snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
0
zerver/webhooks/netlify/__init__.py
Normal file
0
zerver/webhooks/netlify/__init__.py
Normal file
28
zerver/webhooks/netlify/doc.md
Normal file
28
zerver/webhooks/netlify/doc.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Zulip Netlify integration
|
||||
|
||||
Get Zulip notifications for your Netlify deployments!
|
||||
|
||||
{start_tabs}
|
||||
|
||||
1. {!create-an-incoming-webhook.md!}
|
||||
|
||||
1. {!generate-webhook-url-basic.md!}
|
||||
|
||||
1. Go to your Netlify project, and click **Settings**. Click **Build & deploy**,
|
||||
and select **Deploy notifications**.
|
||||
Click **Add Notification**, and select **HTTP POST request**.
|
||||
|
||||
1. Select an **Event**, and set **URL to notify** to the URL generated above.
|
||||
Click **Save**.
|
||||
|
||||
{end_tabs}
|
||||
|
||||
{!congrats.md!}
|
||||
|
||||

|
||||
|
||||
### Related documentation
|
||||
|
||||
- [Netlify HTTP Post Request documentation](https://docs.netlify.com/site-deploys/notifications/#http-post-request)
|
||||
|
||||
{!webhooks-url-specification.md!}
|
||||
45
zerver/webhooks/netlify/fixtures/deploy_building.json
Normal file
45
zerver/webhooks/netlify/fixtures/deploy_building.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"id":"5b78192ac9659217dbf7c9aa",
|
||||
"site_id":"573f11b2-f5f3-481f-a1f8-85feb457ff49",
|
||||
"build_id":"5b78192ac9659217dbf7c9ab",
|
||||
"state":"building",
|
||||
"name":"objective-jepsen-35fbb2",
|
||||
"url":"http://objective-jepsen-35fbb2.netlify.com",
|
||||
"ssl_url":"https://objective-jepsen-35fbb2.netlify.com",
|
||||
"admin_url":"https://app.netlify.com/sites/objective-jepsen-35fbb2",
|
||||
"deploy_url":"http://5b78192ac9659217dbf7c9aa.objective-jepsen-35fbb2.netlify.com",
|
||||
"deploy_ssl_url":"https://5b78192ac9659217dbf7c9aa--objective-jepsen-35fbb2.netlify.com",
|
||||
"created_at":"2018-08-18T13:03:38.315Z",
|
||||
"updated_at":"2018-08-18T13:03:39.800Z",
|
||||
"user_id":"5b68ca02b13fb17905788d44",
|
||||
"error_message":null,
|
||||
"required":[
|
||||
|
||||
],
|
||||
"required_functions":null,
|
||||
"commit_ref":null,
|
||||
"review_id":null,
|
||||
"branch":"master",
|
||||
"commit_url":null,
|
||||
"skipped":null,
|
||||
"locked":null,
|
||||
"log_access_attributes":{
|
||||
"type":"firebase",
|
||||
"url":"https://netlify.firebaseio.com/builds/5b78192ac9659217dbf7c9ab/log"
|
||||
},
|
||||
"title":null,
|
||||
"review_url":null,
|
||||
"published_at":null,
|
||||
"context":"production",
|
||||
"deploy_time":null,
|
||||
"available_functions":[
|
||||
|
||||
],
|
||||
"summary":{
|
||||
"status":"building",
|
||||
"messages":[
|
||||
|
||||
]
|
||||
},
|
||||
"screenshot_url":null
|
||||
}
|
||||
52
zerver/webhooks/netlify/fixtures/deploy_created.json
Normal file
52
zerver/webhooks/netlify/fixtures/deploy_created.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"id":"5b78192ac9659217dbf7c9aa",
|
||||
"site_id":"573f11b2-f5f3-481f-a1f8-85feb457ff49",
|
||||
"build_id":"5b78192ac9659217dbf7c9ab",
|
||||
"state":"ready",
|
||||
"name":"objective-jepsen-35fbb2",
|
||||
"url":"http://objective-jepsen-35fbb2.netlify.com",
|
||||
"ssl_url":"https://objective-jepsen-35fbb2.netlify.com",
|
||||
"admin_url":"https://app.netlify.com/sites/objective-jepsen-35fbb2",
|
||||
"deploy_url":"http://5b78192ac9659217dbf7c9aa.objective-jepsen-35fbb2.netlify.com",
|
||||
"deploy_ssl_url":"https://5b78192ac9659217dbf7c9aa--objective-jepsen-35fbb2.netlify.com",
|
||||
"created_at":"2018-08-18T13:03:38.315Z",
|
||||
"updated_at":"2018-08-18T13:03:44.609Z",
|
||||
"user_id":"5b68ca02b13fb17905788d44",
|
||||
"error_message":null,
|
||||
"required":[
|
||||
|
||||
],
|
||||
"required_functions":[
|
||||
|
||||
],
|
||||
"commit_ref":null,
|
||||
"review_id":null,
|
||||
"branch":"master",
|
||||
"commit_url":null,
|
||||
"skipped":null,
|
||||
"locked":null,
|
||||
"log_access_attributes":{
|
||||
"type":"firebase",
|
||||
"url":"https://netlify.firebaseio.com/builds/5b78192ac9659217dbf7c9ab/log"
|
||||
},
|
||||
"title":null,
|
||||
"review_url":null,
|
||||
"published_at":"2018-08-18T13:03:42.462Z",
|
||||
"context":"production",
|
||||
"deploy_time":3,
|
||||
"available_functions":[
|
||||
|
||||
],
|
||||
"summary":{
|
||||
"status":"ready",
|
||||
"messages":[
|
||||
{
|
||||
"type":"info",
|
||||
"title":"No new files created for this deploy",
|
||||
"description":null,
|
||||
"image":null
|
||||
}
|
||||
]
|
||||
},
|
||||
"screenshot_url":"https://353a23c500dde3b2ad58-c49fe7e7355d384845270f4a7a0a7aa1.ssl.cf2.rackcdn.com/5b78192ac9659217dbf7c9aa/screenshot.png"
|
||||
}
|
||||
41
zerver/webhooks/netlify/fixtures/deploy_failed.json
Normal file
41
zerver/webhooks/netlify/fixtures/deploy_failed.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"id":"5b64d77c02ed83730664c2f6",
|
||||
"site_id":"6f2ad239-fce7-4b54-81fe-873d4fcf5c78",
|
||||
"build_id":"5b64d77c02ed83730664c2f7",
|
||||
"state":"error",
|
||||
"name":"objective-jepsen-35fbb2",
|
||||
"url":"http://objective-jepsen-35fbb2.netlify.com",
|
||||
"ssl_url":"https://objective-jepsen-35fbb2.netlify.com",
|
||||
"admin_url":"https://app.netlify.com/sites/objective-jepsen-35fbb2",
|
||||
"deploy_url":"http://5b78192ac9659217dbf7c9aa.objective-jepsen-35fbb2.netlify.com",
|
||||
"deploy_ssl_url":"https://5b78192ac9659217dbf7c9aa--objective-jepsen-35fbb2.netlify.com",
|
||||
"created_at":"2018-08-03T22:30:20.261Z",
|
||||
"updated_at":"2018-08-03T22:30:27.734Z",
|
||||
"user_id":"5b64d15c82d3f16bcbbdcdbe",
|
||||
"error_message":"failed during stage 'building site': Build script returned non-zero exit code: 127",
|
||||
"required":[
|
||||
|
||||
],
|
||||
"required_functions":null,
|
||||
"commit_ref":null,
|
||||
"review_id":null,
|
||||
"branch":"master",
|
||||
"commit_url":null,
|
||||
"skipped":null,
|
||||
"locked":null,
|
||||
"log_access_attributes":{
|
||||
"type":"firebase",
|
||||
"url":"https://netlify.firebaseio.com/builds/5b64d77c02ed83730664c2f7/log"
|
||||
},
|
||||
"title":null,
|
||||
"review_url":null,
|
||||
"published_at":null,
|
||||
"context":"production",
|
||||
"deploy_time":null,
|
||||
"available_functions":[
|
||||
|
||||
],
|
||||
"summary":{
|
||||
|
||||
}
|
||||
}
|
||||
43
zerver/webhooks/netlify/fixtures/deploy_locked.json
Normal file
43
zerver/webhooks/netlify/fixtures/deploy_locked.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"id":"5b64d2c3792f8946ae9ddc8b",
|
||||
"site_id":"6f2ad239-fce7-4b54-81fe-873d4fcf5c78",
|
||||
"build_id":"5b64d2c3792f8946ae9ddc8c",
|
||||
"state":"ready",
|
||||
"name":"objective-jepsen-35fbb2",
|
||||
"url":"http://objective-jepsen-35fbb2.netlify.com",
|
||||
"ssl_url":"https://objective-jepsen-35fbb2.netlify.com",
|
||||
"admin_url":"https://app.netlify.com/sites/objective-jepsen-35fbb2",
|
||||
"deploy_url":"http://5b78192ac9659217dbf7c9aa.objective-jepsen-35fbb2.netlify.com",
|
||||
"deploy_ssl_url":"https://5b78192ac9659217dbf7c9aa--objective-jepsen-35fbb2.netlify.com",
|
||||
"created_at":"2018-08-03T22:10:11.180Z",
|
||||
"updated_at":"2018-08-03T22:21:59.875Z",
|
||||
"user_id":"5b64d15c82d3f16bcbbdcdbe",
|
||||
"error_message":null,
|
||||
"required":[
|
||||
|
||||
],
|
||||
"required_functions":[
|
||||
|
||||
],
|
||||
"commit_ref":null,
|
||||
"review_id":null,
|
||||
"branch":"master",
|
||||
"commit_url":null,
|
||||
"skipped":null,
|
||||
"locked":true,
|
||||
"log_access_attributes":{
|
||||
"type":"firebase",
|
||||
"url":"https://netlify.firebaseio.com/builds/5b64d2c3792f8946ae9ddc8c/log"
|
||||
},
|
||||
"title":null,
|
||||
"review_url":null,
|
||||
"published_at":"2018-08-03T22:21:59.747Z",
|
||||
"context":"production",
|
||||
"deploy_time":2,
|
||||
"available_functions":[
|
||||
|
||||
],
|
||||
"summary":{
|
||||
|
||||
}
|
||||
}
|
||||
43
zerver/webhooks/netlify/fixtures/deploy_unlocked.json
Normal file
43
zerver/webhooks/netlify/fixtures/deploy_unlocked.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"id":"5b64d2c3792f8946ae9ddc8b",
|
||||
"site_id":"6f2ad239-fce7-4b54-81fe-873d4fcf5c78",
|
||||
"build_id":"5b64d2c3792f8946ae9ddc8c",
|
||||
"state":"ready",
|
||||
"name":"objective-jepsen-35fbb2",
|
||||
"url":"http://objective-jepsen-35fbb2.netlify.com",
|
||||
"ssl_url":"https://objective-jepsen-35fbb2.netlify.com",
|
||||
"admin_url":"https://app.netlify.com/sites/objective-jepsen-35fbb2",
|
||||
"deploy_url":"http://5b78192ac9659217dbf7c9aa.objective-jepsen-35fbb2.netlify.com",
|
||||
"deploy_ssl_url":"https://5b78192ac9659217dbf7c9aa--objective-jepsen-35fbb2.netlify.com",
|
||||
"created_at":"2018-08-03T22:10:11.180Z",
|
||||
"updated_at":"2018-08-03T22:24:04.622Z",
|
||||
"user_id":"5b64d15c82d3f16bcbbdcdbe",
|
||||
"error_message":null,
|
||||
"required":[
|
||||
|
||||
],
|
||||
"required_functions":[
|
||||
|
||||
],
|
||||
"commit_ref":null,
|
||||
"review_id":null,
|
||||
"branch":"master",
|
||||
"commit_url":null,
|
||||
"skipped":null,
|
||||
"locked":false,
|
||||
"log_access_attributes":{
|
||||
"type":"firebase",
|
||||
"url":"https://netlify.firebaseio.com/builds/5b64d2c3792f8946ae9ddc8c/log"
|
||||
},
|
||||
"title":null,
|
||||
"review_url":null,
|
||||
"published_at":"2018-08-03T22:21:59.747Z",
|
||||
"context":"production",
|
||||
"deploy_time":2,
|
||||
"available_functions":[
|
||||
|
||||
],
|
||||
"summary":{
|
||||
|
||||
}
|
||||
}
|
||||
58
zerver/webhooks/netlify/tests.py
Normal file
58
zerver/webhooks/netlify/tests.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
|
||||
class NetlifyHookTests(WebhookTestCase):
|
||||
def test_building_message(self) -> None:
|
||||
expected_topic_name = "master"
|
||||
expected_message = "The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) on branch master is now building."
|
||||
|
||||
self.check_webhook(
|
||||
"deploy_building",
|
||||
expected_topic_name,
|
||||
expected_message,
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
def test_created_message(self) -> None:
|
||||
expected_topic_name = "master"
|
||||
expected_message = "The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) on branch master is now ready."
|
||||
|
||||
self.check_webhook(
|
||||
"deploy_created", expected_topic_name, expected_message, content_type="application/json"
|
||||
)
|
||||
|
||||
def test_failed_message(self) -> None:
|
||||
expected_topic_name = "master"
|
||||
expected_message = (
|
||||
"The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) "
|
||||
"on branch master failed during stage 'building site': Build script returned non-zero exit code: 127"
|
||||
)
|
||||
|
||||
self.check_webhook(
|
||||
"deploy_failed", expected_topic_name, expected_message, content_type="application/json"
|
||||
)
|
||||
|
||||
def test_locked_message(self) -> None:
|
||||
expected_topic_name = "master"
|
||||
expected_message = (
|
||||
"The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) "
|
||||
"on branch master is now locked."
|
||||
)
|
||||
|
||||
self.check_webhook(
|
||||
"deploy_locked", expected_topic_name, expected_message, content_type="application/json"
|
||||
)
|
||||
|
||||
def test_unlocked_message(self) -> None:
|
||||
expected_topic_name = "master"
|
||||
expected_message = (
|
||||
"The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) "
|
||||
"on branch master is now unlocked."
|
||||
)
|
||||
|
||||
self.check_webhook(
|
||||
"deploy_unlocked",
|
||||
expected_topic_name,
|
||||
expected_message,
|
||||
content_type="application/json",
|
||||
)
|
||||
65
zerver/webhooks/netlify/view.py
Normal file
65
zerver/webhooks/netlify/view.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import webhook_view
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
||||
from zerver.lib.validator import WildValue, check_string
|
||||
from zerver.lib.webhooks.common import (
|
||||
check_send_webhook_message,
|
||||
default_fixture_to_headers,
|
||||
get_event_header,
|
||||
)
|
||||
from zerver.models import UserProfile
|
||||
|
||||
ALL_EVENT_TYPES = [
|
||||
"deploy_failed",
|
||||
"deploy_locked",
|
||||
"deploy_unlocked",
|
||||
"deploy_building",
|
||||
"deploy_created",
|
||||
]
|
||||
|
||||
fixture_to_headers = default_fixture_to_headers("HTTP_X_NETLIFY_EVENT")
|
||||
|
||||
|
||||
@webhook_view("Netlify", all_event_types=ALL_EVENT_TYPES)
|
||||
@typed_endpoint
|
||||
def api_netlify_webhook(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
*,
|
||||
payload: JsonBodyPayload[WildValue],
|
||||
) -> HttpResponse:
|
||||
message_template, event = get_template(request, payload)
|
||||
|
||||
body = message_template.format(
|
||||
build_name=payload["name"].tame(check_string),
|
||||
build_url=payload["url"].tame(check_string),
|
||||
branch_name=payload["branch"].tame(check_string),
|
||||
state=payload["state"].tame(check_string),
|
||||
)
|
||||
|
||||
topic_name = "{topic}".format(topic=payload["branch"].tame(check_string))
|
||||
|
||||
check_send_webhook_message(request, user_profile, topic_name, body, event)
|
||||
|
||||
return json_success(request)
|
||||
|
||||
|
||||
def get_template(request: HttpRequest, payload: WildValue) -> tuple[str, str]:
|
||||
message_template = "The build [{build_name}]({build_url}) on branch {branch_name} "
|
||||
event = get_event_header(request, "X-Netlify-Event", "Netlify")
|
||||
|
||||
if event == "deploy_failed":
|
||||
message_template += payload["error_message"].tame(check_string)
|
||||
elif event == "deploy_locked":
|
||||
message_template += "is now locked."
|
||||
elif event == "deploy_unlocked":
|
||||
message_template += "is now unlocked."
|
||||
elif event in ALL_EVENT_TYPES:
|
||||
message_template += "is now {state}.".format(state=payload["state"].tame(check_string))
|
||||
else:
|
||||
raise UnsupportedWebhookEventTypeError(event)
|
||||
|
||||
return message_template, event
|
||||
Reference in New Issue
Block a user