Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/gitlab: Remove support for deprecated Build Hook.
Niloth P158af33a0162
diff --git a/zerver/webhooks/gitlab/fixtures/build_created.json b/zerver/webhooks/gitlab/fixtures/build_created.jsondeleted file mode 100644index 0e63812dfbf..00000000000--- a/zerver/webhooks/gitlab/fixtures/build_created.json+++ /dev/null@@ -1,42 +0,0 @@-{- "object_kind":"build",- "ref":"master",- "tag":false,- "before_sha":"c4e3d3814490d5f4432a19e874d86c5d0a71451e",- "sha":"c4e3d3814490d5f4432a19e874d86c5d0a71451e",- "build_id":4537823,- "build_name":"job_name",- "build_stage":"test",- "build_status":"created",- "build_started_at":null,- "build_finished_at":null,- "build_duration":null,- "build_allow_failure":true,- "project_id":1740047,- "project_name":"Tomasz Kolek / my-awesome-project",- "user":{- "id":745906,- "name":"Tomasz Kolek",- "email":"[email protected]"- },- "commit":{- "id":4413028,- "sha":"c4e3d3814490d5f4432a19e874d86c5d0a71451e",- "message":"x\n",- "author_name":"Tomasz Kolek",- "author_email":"[email protected]",- "status":"created",- "duration":null,- "started_at":null,- "finished_at":null- },- "repository":{- "name":"my-awesome-project",- "url":"[email protected]:TomaszKolek/my-awesome-project.git",- "description":"abc",- "homepage":"https://gitlab.com/TomaszKolek/my-awesome-project",- "git_http_url":"https://gitlab.com/TomaszKolek/my-awesome-project.git",- "git_ssh_url":"[email protected]:TomaszKolek/my-awesome-project.git",- "visibility_level":20- }-}diff --git a/zerver/webhooks/gitlab/fixtures/build_started.json b/zerver/webhooks/gitlab/fixtures/build_started.jsondeleted file mode 100644index 82d5c8d41ae..00000000000--- a/zerver/webhooks/gitlab/fixtures/build_started.json+++ /dev/null@@ -1,42 +0,0 @@-{- "object_kind":"build",- "ref":"master",- "tag":false,- "before_sha":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "sha":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "build_id":4541112,- "build_name":"job_name",- "build_stage":"test",- "build_status":"running",- "build_started_at":"2016-09-28 20:21:04 UTC",- "build_finished_at":null,- "build_duration":0.159148421,- "build_allow_failure":true,- "project_id":1740047,- "project_name":"Tomasz Kolek / my-awesome-project",- "user":{- "id":745906,- "name":"Tomasz Kolek",- "email":"[email protected]"- },- "commit":{- "id":4414206,- "sha":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "message":"a\n",- "author_name":"Tomasz Kolek",- "author_email":"[email protected]",- "status":"running",- "duration":0,- "started_at":"2016-09-28 20:21:04 UTC",- "finished_at":null- },- "repository":{- "name":"my-awesome-project",- "url":"[email protected]:TomaszKolek/my-awesome-project.git",- "description":"abc",- "homepage":"https://gitlab.com/TomaszKolek/my-awesome-project",- "git_http_url":"https://gitlab.com/TomaszKolek/my-awesome-project.git",- "git_ssh_url":"[email protected]:TomaszKolek/my-awesome-project.git",- "visibility_level":20- }-}diff --git a/zerver/webhooks/gitlab/fixtures/build_succeeded.json b/zerver/webhooks/gitlab/fixtures/build_succeeded.jsondeleted file mode 100644index 017401e5641..00000000000--- a/zerver/webhooks/gitlab/fixtures/build_succeeded.json+++ /dev/null@@ -1,42 +0,0 @@-{- "object_kind":"build",- "ref":"master",- "tag":false,- "before_sha":"c4e3d3814490d5f4432a19e874d86c5d0a71451e",- "sha":"c4e3d3814490d5f4432a19e874d86c5d0a71451e",- "build_id":4537823,- "build_name":"job_name",- "build_stage":"test",- "build_status":"success",- "build_started_at":"2016-09-28 18:33:47 UTC",- "build_finished_at":"2016-09-28 18:34:32 UTC",- "build_duration":44.711645256,- "build_allow_failure":true,- "project_id":1740047,- "project_name":"Tomasz Kolek / my-awesome-project",- "user":{- "id":745906,- "name":"Tomasz Kolek",- "email":"[email protected]"- },- "commit":{- "id":4413028,- "sha":"c4e3d3814490d5f4432a19e874d86c5d0a71451e",- "message":"x\n",- "author_name":"Tomasz Kolek",- "author_email":"[email protected]",- "status":"success",- "duration":44,- "started_at":"2016-09-28 18:33:47 UTC",- "finished_at":"2016-09-28 18:34:32 UTC"- },- "repository":{- "name":"my-awesome-project",- "url":"[email protected]:TomaszKolek/gitlab-test.git",- "description":"abc",- "homepage":"https://gitlab.com/TomaszKolek/my-awesome-project",- "git_http_url":"https://gitlab.com/TomaszKolek/my-awesome-project.git",- "git_ssh_url":"[email protected]:TomaszKolek/my-awesome-project.git",- "visibility_level":20- }-}diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.pyindex 92f350b5f15..a8109218184 100644--- a/zerver/webhooks/gitlab/tests.py+++ b/zerver/webhooks/gitlab/tests.py@@ -453,72 +453,6 @@ A trivial change that should probably be ignored."wiki_page_hook__wiki_page_edited", expected_topic_name, expected_message)- def test_build_created_event_message(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "Build job_name from test stage was created."-- self.check_webhook(- "build_created",- expected_topic_name,- expected_message,- HTTP_X_GITLAB_EVENT="Job Hook",- )-- def test_build_started_event_message(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "Build job_name from test stage started."-- self.check_webhook(- "build_started",- expected_topic_name,- expected_message,- HTTP_X_GITLAB_EVENT="Job Hook",- )-- def test_build_succeeded_event_message(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "Build job_name from test stage changed status to success."-- self.check_webhook(- "build_succeeded",- expected_topic_name,- expected_message,- HTTP_X_GITLAB_EVENT="Job Hook",- )-- def test_build_created_event_message_legacy_event_name(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "Build job_name from test stage was created."-- self.check_webhook(- "build_created",- expected_topic_name,- expected_message,- HTTP_X_GITLAB_EVENT="Build Hook",- )-- def test_build_started_event_message_legacy_event_name(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "Build job_name from test stage started."-- self.check_webhook(- "build_started",- expected_topic_name,- expected_message,- HTTP_X_GITLAB_EVENT="Build Hook",- )-- def test_build_succeeded_event_message_legacy_event_name(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "Build job_name from test stage changed status to success."-- self.check_webhook(- "build_succeeded",- expected_topic_name,- expected_message,- HTTP_X_GITLAB_EVENT="Build Hook",- )-def test_pipeline_succeeded_with_artifacts_event_message(self) -> None:expected_topic_name = "onlysomeproject / test/links-in-zulip-pipeline-message"expected_message = "[Pipeline (22668)](https://gitlab.example.com/group1/onlysomeproject/-/pipelines/22668) changed status to success with build(s):\n* [cleanup:cleanup docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58592) - success\n* [pages](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591) - success\n * built artifact: *artifacts.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/download)]\n* [black+pytest:future environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58590) - success\n* [docs:anaconda environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589) - success\n * built artifact: *sphinx-docs.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/download)]\n* [pytest:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58588) - success\n* [black:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58587) - success\n* [setup:docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58586) - success."diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.pyindex 994ab4a7f75..1a618fa76c1 100644--- a/zerver/webhooks/gitlab/view.py+++ b/zerver/webhooks/gitlab/view.py@@ -50,9 +50,6 @@ EMOJI_MESSAGE_TEMPLATE = "{user_name} {action} the emoji :{emoji_text}:{suffix}.def fixture_to_headers(fixture_name: str) -> dict[str, str]:- if fixture_name.startswith("build"):- return {} # Since there are 2 possible event types.-# Map "push_hook__push_commits_more_than_limit.json" into GitLab's# HTTP event title "Push Hook".return {"HTTP_X_GITLAB_EVENT": fixture_name.split("__", 1)[0].replace("_", " ").title()}@@ -363,7 +360,7 @@ def get_wiki_page_event_body()-def get_build_hook_event_body(+def get_job_hook_event_body(payload: WildValue, include_title: bool, realm: Realm | None = None) -> str:build_status = payload["build_status"].tame(check_string)@@ -706,8 +703,7 @@ EVENT_FUNCTION_MAPPER: dict[str, EventFunction] = {"Merge Request Hook reopen": partial(get_merge_request_event_body, "reopened"),"Wiki Page Hook create": partial(get_wiki_page_event_body, "created"),"Wiki Page Hook update": partial(get_wiki_page_event_body, "updated"),- "Job Hook": get_build_hook_event_body,- "Build Hook": get_build_hook_event_body,+ "Job Hook": get_job_hook_event_body,"Pipeline Hook": get_pipeline_event_body,"Release Hook": get_release_event_body,"Feature Flag Hook": get_feature_flag_event_body,@@ -769,7 +765,7 @@ def get_body_based_on_event(event: str) -> EventFunction:def get_topic_based_on_event(event: str, payload: WildValue, use_merge_request_title: bool) -> str:if event == "Push Hook":return f"{get_repo_name(payload)} / {get_branch_name(payload)}"- elif event in ("Job Hook", "Build Hook"):+ elif event == "Job Hook":return "{} / {}".format(payload["repository"]["name"].tame(check_string), get_branch_name(payload))