Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

circleci: Support the "ping" event type.

Alex Vandiverd30ab34e3d6e
diff --git a/zerver/webhooks/circleci/fixtures/ping.json b/zerver/webhooks/circleci/fixtures/ping.json
new file mode 100644
index 00000000000..fe69e031bd4
--- /dev/null
+++ b/zerver/webhooks/circleci/fixtures/ping.json
@@ -0,0 +1,9 @@
+{
+ "happened_at": "2023-06-17T19:50:27.457981Z",
+ "id": "d1264809-3541-48db-9d72-68f04f074877",
+ "type": "ping",
+ "webhook": {
+ "id": "87f2e824-39f9-4fa8-985e-ce1a0571ad93",
+ "name": "Testing"
+ }
+}
diff --git a/zerver/webhooks/circleci/tests.py b/zerver/webhooks/circleci/tests.py
index f424367cee4..601bae62b4b 100644
--- a/zerver/webhooks/circleci/tests.py
+++ b/zerver/webhooks/circleci/tests.py
@@ -6,6 +6,11 @@ class CircleCiHookTests(WebhookTestCase):
URL_TEMPLATE = "/api/v1/external/circleci?stream={stream}&api_key={api_key}"
WEBHOOK_DIR_NAME = "circleci"
+ def test_ping(self) -> None:
+ expected_topic = "Test event"
+ expected_message = "Webhook 'Testing' test event successful."
+ self.check_webhook("ping", expected_topic, expected_message)
+
def test_bitbucket_job_completed(self) -> None:
expected_topic = "circleci-webhook-testing"
expected_message = """
diff --git a/zerver/webhooks/circleci/view.py b/zerver/webhooks/circleci/view.py
index 093a4f4f131..4de993fd2a7 100644
--- a/zerver/webhooks/circleci/view.py
+++ b/zerver/webhooks/circleci/view.py
@@ -54,7 +54,7 @@ Job `{job_name}` within Pipeline #{pipeline_number} {formatted_status}.
{commit_details}
"""
-ALL_EVENT_TYPES = ["job-completed", "workflow-completed"]
+ALL_EVENT_TYPES = ["ping", "job-completed", "workflow-completed"]
@webhook_view("CircleCI", all_event_types=ALL_EVENT_TYPES)
@@ -64,17 +64,24 @@ def api_circleci_webhook(
user_profile: UserProfile,
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
- subject = get_subject(payload)
- body = get_body(payload)
-
- pipeline = payload["pipeline"]
-
- # We currently don't support projects using VCS providers other than GitHub,
- # BitBucket and GitLab.
- if "trigger_parameters" in pipeline and pipeline["trigger"]["type"] != "gitlab":
- raise JsonableError(
- _("Projects using this version control system provider aren't supported")
- ) # nocoverage
+ type = payload["type"].tame(check_string)
+ if type == "ping":
+ # Ping events don't have full payloads, so our normal codepath won't work
+ subject = "Test event"
+ body = "Webhook '{name}' test event successful.".format(
+ name=payload["webhook"]["name"].tame(check_string)
+ )
+ else:
+ subject = get_subject(payload)
+ body = get_body(payload)
+
+ # We currently don't support projects using VCS providers other than GitHub,
+ # BitBucket and GitLab.
+ pipeline = payload["pipeline"]
+ if "trigger_parameters" in pipeline and pipeline["trigger"]["type"] != "gitlab":
+ raise JsonableError(
+ _("Projects using this version control system provider aren't supported")
+ ) # nocoverage
check_send_webhook_message(
request,