mirror of https://github.com/zulip/zulip.git
webhooks/github: Add a support for team/edited events.
Signed-off-by: Hemanth V. Alluri <hdrive1999@gmail.com>
This commit is contained in:
parent
46ef6816b6
commit
c8f4177872
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"changes": {
|
||||||
|
"description": {
|
||||||
|
"from": "A temporary team so that I can get some webhook fixtures."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"action": "edited",
|
||||||
|
"team": {
|
||||||
|
"name": "Testing",
|
||||||
|
"id": 3835900,
|
||||||
|
"node_id": "MDQ6VGVhbTM4MzU5MDA=",
|
||||||
|
"slug": "testing",
|
||||||
|
"description": "A temporary team so that I can get some webhook fixtures!",
|
||||||
|
"privacy": "closed",
|
||||||
|
"url": "https://api.github.com/organizations/14038814/team/3835900",
|
||||||
|
"html_url": "https://github.com/orgs/dvm-bitspilani/teams/testing",
|
||||||
|
"members_url": "https://api.github.com/organizations/14038814/team/3835900/members{/member}",
|
||||||
|
"repositories_url": "https://api.github.com/organizations/14038814/team/3835900/repos",
|
||||||
|
"permission": "pull",
|
||||||
|
"parent": null
|
||||||
|
},
|
||||||
|
"organization": {
|
||||||
|
"login": "dvm-bitspilani",
|
||||||
|
"id": 14038814,
|
||||||
|
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE0MDM4ODE0",
|
||||||
|
"url": "https://api.github.com/orgs/dvm-bitspilani",
|
||||||
|
"repos_url": "https://api.github.com/orgs/dvm-bitspilani/repos",
|
||||||
|
"events_url": "https://api.github.com/orgs/dvm-bitspilani/events",
|
||||||
|
"hooks_url": "https://api.github.com/orgs/dvm-bitspilani/hooks",
|
||||||
|
"issues_url": "https://api.github.com/orgs/dvm-bitspilani/issues",
|
||||||
|
"members_url": "https://api.github.com/orgs/dvm-bitspilani/members{/member}",
|
||||||
|
"public_members_url": "https://api.github.com/orgs/dvm-bitspilani/public_members{/member}",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/14038814?v=4",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"sender": {
|
||||||
|
"login": "Hypro999",
|
||||||
|
"id": 29123352,
|
||||||
|
"node_id": "MDQ6VXNlcjI5MTIzMzUy",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/29123352?v=4",
|
||||||
|
"gravatar_id": "",
|
||||||
|
"url": "https://api.github.com/users/Hypro999",
|
||||||
|
"html_url": "https://github.com/Hypro999",
|
||||||
|
"followers_url": "https://api.github.com/users/Hypro999/followers",
|
||||||
|
"following_url": "https://api.github.com/users/Hypro999/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/Hypro999/gists{/gist_id}",
|
||||||
|
"starred_url": "https://api.github.com/users/Hypro999/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/Hypro999/subscriptions",
|
||||||
|
"organizations_url": "https://api.github.com/users/Hypro999/orgs",
|
||||||
|
"repos_url": "https://api.github.com/users/Hypro999/repos",
|
||||||
|
"events_url": "https://api.github.com/users/Hypro999/events{/privacy}",
|
||||||
|
"received_events_url": "https://api.github.com/users/Hypro999/received_events",
|
||||||
|
"type": "User",
|
||||||
|
"site_admin": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
{
|
||||||
|
"changes": {
|
||||||
|
"name": {
|
||||||
|
"from": "Testing"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"action": "edited",
|
||||||
|
"team": {
|
||||||
|
"name": "Testing Team",
|
||||||
|
"id": 3835900,
|
||||||
|
"node_id": "MDQ6VGVhbTM4MzU5MDA=",
|
||||||
|
"slug": "testing-team",
|
||||||
|
"description": "A temporary team so that I can get some webhook fixtures!",
|
||||||
|
"privacy": "closed",
|
||||||
|
"url": "https://api.github.com/organizations/14038814/team/3835900",
|
||||||
|
"html_url": "https://github.com/orgs/dvm-bitspilani/teams/testing-team",
|
||||||
|
"members_url": "https://api.github.com/organizations/14038814/team/3835900/members{/member}",
|
||||||
|
"repositories_url": "https://api.github.com/organizations/14038814/team/3835900/repos",
|
||||||
|
"permission": "pull",
|
||||||
|
"parent": null
|
||||||
|
},
|
||||||
|
"organization": {
|
||||||
|
"login": "dvm-bitspilani",
|
||||||
|
"id": 14038814,
|
||||||
|
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE0MDM4ODE0",
|
||||||
|
"url": "https://api.github.com/orgs/dvm-bitspilani",
|
||||||
|
"repos_url": "https://api.github.com/orgs/dvm-bitspilani/repos",
|
||||||
|
"events_url": "https://api.github.com/orgs/dvm-bitspilani/events",
|
||||||
|
"hooks_url": "https://api.github.com/orgs/dvm-bitspilani/hooks",
|
||||||
|
"issues_url": "https://api.github.com/orgs/dvm-bitspilani/issues",
|
||||||
|
"members_url": "https://api.github.com/orgs/dvm-bitspilani/members{/member}",
|
||||||
|
"public_members_url": "https://api.github.com/orgs/dvm-bitspilani/public_members{/member}",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/14038814?v=4",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"sender": {
|
||||||
|
"login": "Hypro999",
|
||||||
|
"id": 29123352,
|
||||||
|
"node_id": "MDQ6VXNlcjI5MTIzMzUy",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/29123352?v=4",
|
||||||
|
"gravatar_id": "",
|
||||||
|
"url": "https://api.github.com/users/Hypro999",
|
||||||
|
"html_url": "https://github.com/Hypro999",
|
||||||
|
"followers_url": "https://api.github.com/users/Hypro999/followers",
|
||||||
|
"following_url": "https://api.github.com/users/Hypro999/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/Hypro999/gists{/gist_id}",
|
||||||
|
"starred_url": "https://api.github.com/users/Hypro999/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/Hypro999/subscriptions",
|
||||||
|
"organizations_url": "https://api.github.com/users/Hypro999/orgs",
|
||||||
|
"repos_url": "https://api.github.com/users/Hypro999/repos",
|
||||||
|
"events_url": "https://api.github.com/users/Hypro999/events{/privacy}",
|
||||||
|
"received_events_url": "https://api.github.com/users/Hypro999/received_events",
|
||||||
|
"type": "User",
|
||||||
|
"site_admin": false
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
{
|
||||||
|
"changes": {
|
||||||
|
"privacy": {
|
||||||
|
"from": "secret"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"action": "edited",
|
||||||
|
"team": {
|
||||||
|
"name": "Testing",
|
||||||
|
"id": 3835900,
|
||||||
|
"node_id": "MDQ6VGVhbTM4MzU5MDA=",
|
||||||
|
"slug": "testing",
|
||||||
|
"description": "A temporary team so that I can get some webhook fixtures!",
|
||||||
|
"privacy": "closed",
|
||||||
|
"url": "https://api.github.com/organizations/14038814/team/3835900",
|
||||||
|
"html_url": "https://github.com/orgs/dvm-bitspilani/teams/testing",
|
||||||
|
"members_url": "https://api.github.com/organizations/14038814/team/3835900/members{/member}",
|
||||||
|
"repositories_url": "https://api.github.com/organizations/14038814/team/3835900/repos",
|
||||||
|
"permission": "pull",
|
||||||
|
"parent": null
|
||||||
|
},
|
||||||
|
"organization": {
|
||||||
|
"login": "dvm-bitspilani",
|
||||||
|
"id": 14038814,
|
||||||
|
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE0MDM4ODE0",
|
||||||
|
"url": "https://api.github.com/orgs/dvm-bitspilani",
|
||||||
|
"repos_url": "https://api.github.com/orgs/dvm-bitspilani/repos",
|
||||||
|
"events_url": "https://api.github.com/orgs/dvm-bitspilani/events",
|
||||||
|
"hooks_url": "https://api.github.com/orgs/dvm-bitspilani/hooks",
|
||||||
|
"issues_url": "https://api.github.com/orgs/dvm-bitspilani/issues",
|
||||||
|
"members_url": "https://api.github.com/orgs/dvm-bitspilani/members{/member}",
|
||||||
|
"public_members_url": "https://api.github.com/orgs/dvm-bitspilani/public_members{/member}",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/14038814?v=4",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"sender": {
|
||||||
|
"login": "Hypro999",
|
||||||
|
"id": 29123352,
|
||||||
|
"node_id": "MDQ6VXNlcjI5MTIzMzUy",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/29123352?v=4",
|
||||||
|
"gravatar_id": "",
|
||||||
|
"url": "https://api.github.com/users/Hypro999",
|
||||||
|
"html_url": "https://github.com/Hypro999",
|
||||||
|
"followers_url": "https://api.github.com/users/Hypro999/followers",
|
||||||
|
"following_url": "https://api.github.com/users/Hypro999/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/Hypro999/gists{/gist_id}",
|
||||||
|
"starred_url": "https://api.github.com/users/Hypro999/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/Hypro999/subscriptions",
|
||||||
|
"organizations_url": "https://api.github.com/users/Hypro999/orgs",
|
||||||
|
"repos_url": "https://api.github.com/users/Hypro999/repos",
|
||||||
|
"events_url": "https://api.github.com/users/Hypro999/events{/privacy}",
|
||||||
|
"received_events_url": "https://api.github.com/users/Hypro999/received_events",
|
||||||
|
"type": "User",
|
||||||
|
"site_admin": false
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
{
|
||||||
|
"changes": {
|
||||||
|
"privacy": {
|
||||||
|
"from": "closed"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"action": "edited",
|
||||||
|
"team": {
|
||||||
|
"name": "Testing Team",
|
||||||
|
"id": 3835900,
|
||||||
|
"node_id": "MDQ6VGVhbTM4MzU5MDA=",
|
||||||
|
"slug": "testing-team",
|
||||||
|
"description": "A temporary team so that I can get some webhook fixtures!",
|
||||||
|
"privacy": "secret",
|
||||||
|
"url": "https://api.github.com/organizations/14038814/team/3835900",
|
||||||
|
"html_url": "https://github.com/orgs/dvm-bitspilani/teams/testing-team",
|
||||||
|
"members_url": "https://api.github.com/organizations/14038814/team/3835900/members{/member}",
|
||||||
|
"repositories_url": "https://api.github.com/organizations/14038814/team/3835900/repos",
|
||||||
|
"permission": "pull",
|
||||||
|
"parent": null
|
||||||
|
},
|
||||||
|
"organization": {
|
||||||
|
"login": "dvm-bitspilani",
|
||||||
|
"id": 14038814,
|
||||||
|
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE0MDM4ODE0",
|
||||||
|
"url": "https://api.github.com/orgs/dvm-bitspilani",
|
||||||
|
"repos_url": "https://api.github.com/orgs/dvm-bitspilani/repos",
|
||||||
|
"events_url": "https://api.github.com/orgs/dvm-bitspilani/events",
|
||||||
|
"hooks_url": "https://api.github.com/orgs/dvm-bitspilani/hooks",
|
||||||
|
"issues_url": "https://api.github.com/orgs/dvm-bitspilani/issues",
|
||||||
|
"members_url": "https://api.github.com/orgs/dvm-bitspilani/members{/member}",
|
||||||
|
"public_members_url": "https://api.github.com/orgs/dvm-bitspilani/public_members{/member}",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/14038814?v=4",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"sender": {
|
||||||
|
"login": "Hypro999",
|
||||||
|
"id": 29123352,
|
||||||
|
"node_id": "MDQ6VXNlcjI5MTIzMzUy",
|
||||||
|
"avatar_url": "https://avatars3.githubusercontent.com/u/29123352?v=4",
|
||||||
|
"gravatar_id": "",
|
||||||
|
"url": "https://api.github.com/users/Hypro999",
|
||||||
|
"html_url": "https://github.com/Hypro999",
|
||||||
|
"followers_url": "https://api.github.com/users/Hypro999/followers",
|
||||||
|
"following_url": "https://api.github.com/users/Hypro999/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/Hypro999/gists{/gist_id}",
|
||||||
|
"starred_url": "https://api.github.com/users/Hypro999/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/Hypro999/subscriptions",
|
||||||
|
"organizations_url": "https://api.github.com/users/Hypro999/orgs",
|
||||||
|
"repos_url": "https://api.github.com/users/Hypro999/repos",
|
||||||
|
"events_url": "https://api.github.com/users/Hypro999/events{/privacy}",
|
||||||
|
"received_events_url": "https://api.github.com/users/Hypro999/received_events",
|
||||||
|
"type": "User",
|
||||||
|
"site_admin": false
|
||||||
|
}
|
||||||
|
}
|
|
@ -302,6 +302,25 @@ Check [randscape](http://github.com/github/hello-world/runs/4) completed (succes
|
||||||
""".strip()
|
""".strip()
|
||||||
self.send_and_test_stream_message('check_run__completed', expected_topic, expected_message)
|
self.send_and_test_stream_message('check_run__completed', expected_topic, expected_message)
|
||||||
|
|
||||||
|
def test_team_edited_description(self) -> None:
|
||||||
|
expected_topic = "team Testing"
|
||||||
|
expected_message = """\
|
||||||
|
**Hypro999** changed the team description to:
|
||||||
|
```quote
|
||||||
|
A temporary team so that I can get some webhook fixtures!
|
||||||
|
```"""
|
||||||
|
self.send_and_test_stream_message('team__edited_description', expected_topic, expected_message)
|
||||||
|
|
||||||
|
def test_team_edited_name(self) -> None:
|
||||||
|
expected_topic = "team Testing Team"
|
||||||
|
expected_message = """Team `Testing` was renamed to `Testing Team`."""
|
||||||
|
self.send_and_test_stream_message('team__edited_name', expected_topic, expected_message)
|
||||||
|
|
||||||
|
def test_team_edited_privacy(self) -> None:
|
||||||
|
expected_topic = "team Testing Team"
|
||||||
|
expected_message = """Team visibility changed to `secret`"""
|
||||||
|
self.send_and_test_stream_message('team__edited_privacy_secret', expected_topic, expected_message)
|
||||||
|
|
||||||
@patch('zerver.webhooks.github.view.check_send_webhook_message')
|
@patch('zerver.webhooks.github.view.check_send_webhook_message')
|
||||||
def test_check_run_in_progress_ignore(
|
def test_check_run_in_progress_ignore(
|
||||||
self, check_send_webhook_message_mock: MagicMock) -> None:
|
self, check_send_webhook_message_mock: MagicMock) -> None:
|
||||||
|
|
|
@ -235,6 +235,22 @@ def get_add_team_body(payload: Dict[str, Any]) -> str:
|
||||||
payload['team']['name']
|
payload['team']['name']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_team_body(payload: Dict[str, Any]) -> str:
|
||||||
|
changes = payload["changes"]
|
||||||
|
if "description" in changes:
|
||||||
|
actor = payload["sender"]["login"]
|
||||||
|
new_description = payload["team"]["description"]
|
||||||
|
return "**{}** changed the team description to:\n```quote\n{}\n```".format(actor, new_description)
|
||||||
|
if "name" in changes:
|
||||||
|
original_name = changes["name"]["from"]
|
||||||
|
new_name = payload["team"]["name"]
|
||||||
|
return "Team `{}` was renamed to `{}`.".format(original_name, new_name)
|
||||||
|
if "privacy" in changes:
|
||||||
|
new_visibility = payload["team"]["privacy"]
|
||||||
|
return "Team visibility changed to `{}`".format(new_visibility)
|
||||||
|
else: # nocoverage
|
||||||
|
raise UnexpectedWebhookEventType("GitHub", "Team Edited: {}".format(changes.keys()))
|
||||||
|
|
||||||
def get_release_body(payload: Dict[str, Any]) -> str:
|
def get_release_body(payload: Dict[str, Any]) -> str:
|
||||||
data = {
|
data = {
|
||||||
'user_name': get_sender_name(payload),
|
'user_name': get_sender_name(payload),
|
||||||
|
@ -433,6 +449,8 @@ def get_subject_based_on_type(payload: Dict[str, Any], event: str) -> str:
|
||||||
)
|
)
|
||||||
elif event == 'membership':
|
elif event == 'membership':
|
||||||
return "{} organization".format(payload['organization']['login'])
|
return "{} organization".format(payload['organization']['login'])
|
||||||
|
elif event == 'team':
|
||||||
|
return "team {}".format(payload['team']['name'])
|
||||||
elif event == 'push_commits':
|
elif event == 'push_commits':
|
||||||
return TOPIC_WITH_BRANCH_TEMPLATE.format(
|
return TOPIC_WITH_BRANCH_TEMPLATE.format(
|
||||||
repo=get_repository_name(payload),
|
repo=get_repository_name(payload),
|
||||||
|
@ -452,7 +470,6 @@ def get_subject_based_on_type(payload: Dict[str, Any], event: str) -> str:
|
||||||
return get_repository_name(payload)
|
return get_repository_name(payload)
|
||||||
|
|
||||||
EVENT_FUNCTION_MAPPER = {
|
EVENT_FUNCTION_MAPPER = {
|
||||||
'team_add': get_add_team_body,
|
|
||||||
'commit_comment': get_commit_comment_body,
|
'commit_comment': get_commit_comment_body,
|
||||||
'closed_pull_request': get_closed_pull_request_body,
|
'closed_pull_request': get_closed_pull_request_body,
|
||||||
'create': partial(get_create_or_delete_body, action='created'),
|
'create': partial(get_create_or_delete_body, action='created'),
|
||||||
|
@ -481,6 +498,8 @@ EVENT_FUNCTION_MAPPER = {
|
||||||
'repository': get_repository_body,
|
'repository': get_repository_body,
|
||||||
'star': get_star_body,
|
'star': get_star_body,
|
||||||
'status': get_status_body,
|
'status': get_status_body,
|
||||||
|
'team': get_team_body,
|
||||||
|
'team_add': get_add_team_body,
|
||||||
'watch': get_watch_body,
|
'watch': get_watch_body,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue