mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
integrations: Add support for GitLab feature flag events.
Fixes part of #34405.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"object_kind": "feature_flag",
|
||||
"project": {
|
||||
"id": 68452408,
|
||||
"name": "sample",
|
||||
"description": null,
|
||||
"web_url": "https://gitlab.com/kolanuvarun/sample",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@gitlab.com:kolanuvarun/sample.git",
|
||||
"git_http_url": "https://gitlab.com/kolanuvarun/sample.git",
|
||||
"namespace": "kolanuvarun",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "kolanuvarun/sample",
|
||||
"default_branch": "master",
|
||||
"ci_config_path": "",
|
||||
"homepage": "https://gitlab.com/kolanuvarun/sample",
|
||||
"url": "git@gitlab.com:kolanuvarun/sample.git",
|
||||
"ssh_url": "git@gitlab.com:kolanuvarun/sample.git",
|
||||
"http_url": "https://gitlab.com/kolanuvarun/sample.git"
|
||||
},
|
||||
"user": {
|
||||
"id": 26076637,
|
||||
"name": "Varun Kolanu",
|
||||
"username": "kolanuvarun739",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/dde05c11435528ac083e918ce384c5b943c7ec54be520b7f4a4bcd3863b36060?s=80&d=identicon",
|
||||
"email": "[REDACTED]"
|
||||
},
|
||||
"user_url": "https://gitlab.com/kolanuvarun739",
|
||||
"object_attributes": {
|
||||
"id": 2073324,
|
||||
"name": "sample-feature-flag",
|
||||
"description": "",
|
||||
"active": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"object_kind": "feature_flag",
|
||||
"project": {
|
||||
"id": 68452408,
|
||||
"name": "sample",
|
||||
"description": null,
|
||||
"web_url": "https://gitlab.com/kolanuvarun/sample",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@gitlab.com:kolanuvarun/sample.git",
|
||||
"git_http_url": "https://gitlab.com/kolanuvarun/sample.git",
|
||||
"namespace": "kolanuvarun",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "kolanuvarun/sample",
|
||||
"default_branch": "master",
|
||||
"ci_config_path": "",
|
||||
"homepage": "https://gitlab.com/kolanuvarun/sample",
|
||||
"url": "git@gitlab.com:kolanuvarun/sample.git",
|
||||
"ssh_url": "git@gitlab.com:kolanuvarun/sample.git",
|
||||
"http_url": "https://gitlab.com/kolanuvarun/sample.git"
|
||||
},
|
||||
"user": {
|
||||
"id": 26076637,
|
||||
"name": "Varun Kolanu",
|
||||
"username": "kolanuvarun739",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/dde05c11435528ac083e918ce384c5b943c7ec54be520b7f4a4bcd3863b36060?s=80&d=identicon",
|
||||
"email": "[REDACTED]"
|
||||
},
|
||||
"user_url": "https://gitlab.com/kolanuvarun739",
|
||||
"object_attributes": {
|
||||
"id": 2073324,
|
||||
"name": "sample-feature-flag",
|
||||
"description": "",
|
||||
"active": false
|
||||
}
|
||||
}
|
||||
@@ -685,3 +685,15 @@ A trivial change that should probably be ignored.
|
||||
expected_message = "Release v1.1 for tag v1.1 was deleted."
|
||||
|
||||
self.check_webhook("release_hook__delete", expected_topic_name, expected_message)
|
||||
|
||||
def test_feature_flag_activate_event_message(self) -> None:
|
||||
expected_topic_name = "sample"
|
||||
expected_message = "kolanuvarun739 activated the feature flag [sample-feature-flag](https://gitlab.com/kolanuvarun/sample/-/feature_flags)."
|
||||
|
||||
self.check_webhook("feature_flag_hook__activated", expected_topic_name, expected_message)
|
||||
|
||||
def test_feature_flag_deactivate_event_message(self) -> None:
|
||||
expected_topic_name = "sample"
|
||||
expected_message = "kolanuvarun739 deactivated the feature flag [sample-feature-flag](https://gitlab.com/kolanuvarun/sample/-/feature_flags)."
|
||||
|
||||
self.check_webhook("feature_flag_hook__deactivated", expected_topic_name, expected_message)
|
||||
|
||||
@@ -36,6 +36,8 @@ DESIGN_COMMENT_MESSAGE_TEMPLATE = (
|
||||
"{user_name} {action} on design [{design_name}]({design_url}):\n{content_message}"
|
||||
)
|
||||
|
||||
FEATURE_FLAG_MESSAGE_TEMPLATE = "{user} {action} the feature flag [{name}]({url})."
|
||||
|
||||
|
||||
def fixture_to_headers(fixture_name: str) -> dict[str, str]:
|
||||
if fixture_name.startswith("build"):
|
||||
@@ -408,6 +410,19 @@ def get_release_event_body(payload: WildValue, include_title: bool) -> str:
|
||||
return body
|
||||
|
||||
|
||||
def get_feature_flag_event_body(payload: WildValue, include_title: bool) -> str:
|
||||
repo_url = payload["project"]["web_url"].tame(check_string)
|
||||
feature_flag = payload["object_attributes"]
|
||||
action = "activated" if feature_flag["active"] else "deactivated"
|
||||
|
||||
return FEATURE_FLAG_MESSAGE_TEMPLATE.format(
|
||||
user=payload["user"]["username"].tame(check_string),
|
||||
action=action,
|
||||
name=feature_flag["name"].tame(check_string),
|
||||
url=f"{repo_url}/-/feature_flags",
|
||||
)
|
||||
|
||||
|
||||
def get_repo_name(payload: WildValue) -> str:
|
||||
if "project" in payload:
|
||||
return payload["project"]["name"].tame(check_string)
|
||||
@@ -495,6 +510,7 @@ EVENT_FUNCTION_MAPPER: dict[str, EventFunction] = {
|
||||
"Build Hook": get_build_hook_event_body,
|
||||
"Pipeline Hook": get_pipeline_event_body,
|
||||
"Release Hook": get_release_event_body,
|
||||
"Feature Flag Hook": get_feature_flag_event_body,
|
||||
}
|
||||
|
||||
ALL_EVENT_TYPES = list(EVENT_FUNCTION_MAPPER.keys())
|
||||
|
||||
Reference in New Issue
Block a user