mirror of https://github.com/zulip/zulip.git
webhooks/gitlab: Support issues with multiple assignees.
The fixtures added in this commit were generated by Adam Birds.
This commit is contained in:
parent
488f558d49
commit
4a2a3e3640
|
@ -124,6 +124,7 @@ def get_remove_branch_event_message(user_name: str, branch_name: str) -> str:
|
|||
def get_pull_request_event_message(user_name: str, action: str, url: str, number: Optional[int]=None,
|
||||
target_branch: Optional[str]=None, base_branch: Optional[str]=None,
|
||||
message: Optional[str]=None, assignee: Optional[str]=None,
|
||||
assignees: Optional[List[Dict[str, Any]]]=None,
|
||||
type: Optional[str]='PR', title: Optional[str]=None) -> str:
|
||||
kwargs = {
|
||||
'user_name': user_name,
|
||||
|
@ -139,7 +140,20 @@ def get_pull_request_event_message(user_name: str, action: str, url: str, number
|
|||
else:
|
||||
main_message = PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE.format(**kwargs)
|
||||
|
||||
if assignee:
|
||||
if assignees:
|
||||
assignees_string = ""
|
||||
if len(assignees) == 1:
|
||||
assignees_string = "{username}".format(**assignees[0])
|
||||
else:
|
||||
usernames = []
|
||||
for a in assignees:
|
||||
usernames.append(a['username'])
|
||||
|
||||
assignees_string = ", ".join(usernames[:-1]) + " and " + usernames[-1]
|
||||
|
||||
main_message += PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignees_string)
|
||||
|
||||
elif assignee:
|
||||
main_message += PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignee)
|
||||
|
||||
if target_branch and base_branch:
|
||||
|
@ -163,6 +177,7 @@ def get_issue_event_message(user_name: str,
|
|||
number: Optional[int]=None,
|
||||
message: Optional[str]=None,
|
||||
assignee: Optional[str]=None,
|
||||
assignees: Optional[List[Dict[str, Any]]]=None,
|
||||
title: Optional[str]=None) -> str:
|
||||
return get_pull_request_event_message(
|
||||
user_name,
|
||||
|
@ -171,6 +186,7 @@ def get_issue_event_message(user_name: str,
|
|||
number,
|
||||
message=message,
|
||||
assignee=assignee,
|
||||
assignees=assignees,
|
||||
type='Issue',
|
||||
title=title,
|
||||
)
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
{
|
||||
"object_kind": "issue",
|
||||
"event_type": "issue",
|
||||
"user": {
|
||||
"name": "Adam Birds",
|
||||
"username": "adambirds",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/1e00d93acdfdddc06304143a1dfcd0b4?s=80&d=identicon"
|
||||
},
|
||||
"project": {
|
||||
"id": 8427506,
|
||||
"name": "Zulip GitLab Test",
|
||||
"description": "",
|
||||
"web_url": "https://gitlab.com/adambirds/zulip-gitlab-test",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"git_http_url": "https://gitlab.com/adambirds/zulip-gitlab-test.git",
|
||||
"namespace": "adambirds",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "adambirds/zulip-gitlab-test",
|
||||
"default_branch": null,
|
||||
"ci_config_path": null,
|
||||
"homepage": "https://gitlab.com/adambirds/zulip-gitlab-test",
|
||||
"url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"ssh_url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"http_url": "https://gitlab.com/adambirds/zulip-gitlab-test.git"
|
||||
},
|
||||
"object_attributes": {
|
||||
"author_id": 1102929,
|
||||
"closed_at": null,
|
||||
"confidential": false,
|
||||
"created_at": "2018-09-17 21:01:30 UTC",
|
||||
"description": "Zulip Test Issue 2",
|
||||
"due_date": null,
|
||||
"id": 14226169,
|
||||
"iid": 2,
|
||||
"last_edited_at": null,
|
||||
"last_edited_by_id": null,
|
||||
"milestone_id": null,
|
||||
"moved_to_id": null,
|
||||
"project_id": 8427506,
|
||||
"relative_position": 1073742823,
|
||||
"state": "opened",
|
||||
"time_estimate": 0,
|
||||
"title": "Zulip Test Issue 2",
|
||||
"updated_at": "2018-09-17 21:01:30 UTC",
|
||||
"updated_by_id": null,
|
||||
"weight": null,
|
||||
"url": "https://gitlab.com/adambirds/zulip-gitlab-test/issues/2",
|
||||
"total_time_spent": 0,
|
||||
"human_total_time_spent": null,
|
||||
"human_time_estimate": null,
|
||||
"assignee_ids": [
|
||||
1102929,
|
||||
1129123
|
||||
],
|
||||
"assignee_id": 1102929,
|
||||
"action": "open"
|
||||
},
|
||||
"labels": [],
|
||||
"changes": {
|
||||
"author_id": {
|
||||
"previous": null,
|
||||
"current": 1102929
|
||||
},
|
||||
"created_at": {
|
||||
"previous": null,
|
||||
"current": "2018-09-17 21:01:30 UTC"
|
||||
},
|
||||
"description": {
|
||||
"previous": null,
|
||||
"current": "Zulip Test Issue 2"
|
||||
},
|
||||
"id": {
|
||||
"previous": null,
|
||||
"current": 14226169
|
||||
},
|
||||
"iid": {
|
||||
"previous": null,
|
||||
"current": 2
|
||||
},
|
||||
"project_id": {
|
||||
"previous": null,
|
||||
"current": 8427506
|
||||
},
|
||||
"relative_position": {
|
||||
"previous": null,
|
||||
"current": 1073742823
|
||||
},
|
||||
"state": {
|
||||
"previous": null,
|
||||
"current": "opened"
|
||||
},
|
||||
"title": {
|
||||
"previous": null,
|
||||
"current": "Zulip Test Issue 2"
|
||||
},
|
||||
"updated_at": {
|
||||
"previous": null,
|
||||
"current": "2018-09-17 21:01:30 UTC"
|
||||
},
|
||||
"assignees": {
|
||||
"previous": [],
|
||||
"current": [
|
||||
{
|
||||
"name": "Adam Birds",
|
||||
"username": "adambirds",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/1e00d93acdfdddc06304143a1dfcd0b4?s=80&d=identicon"
|
||||
},
|
||||
{
|
||||
"name": "Eeshan Garg",
|
||||
"username": "eeshangarg",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/cd181af88d928dab53c55600c9f7551d?s=80&d=identicon"
|
||||
},
|
||||
{
|
||||
"name": "Tim Abbott",
|
||||
"username": "timabbott",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/cd181af88d928dab53c55600c9f7551d?s=80&d=identicon"
|
||||
}
|
||||
]
|
||||
},
|
||||
"total_time_spent": {
|
||||
"previous": null,
|
||||
"current": 0
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"name": "Zulip GitLab Test",
|
||||
"url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"description": "",
|
||||
"homepage": "https://gitlab.com/adambirds/zulip-gitlab-test"
|
||||
},
|
||||
"assignees": [
|
||||
{
|
||||
"name": "Adam Birds",
|
||||
"username": "adambirds",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/1e00d93acdfdddc06304143a1dfcd0b4?s=80&d=identicon"
|
||||
},
|
||||
{
|
||||
"name": "Eeshan Garg",
|
||||
"username": "eeshangarg",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/cd181af88d928dab53c55600c9f7551d?s=80&d=identicon"
|
||||
},
|
||||
{
|
||||
"name": "Tim Abbott",
|
||||
"username": "timabbott",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/cd181af88d928dab53c55600c9f7551d?s=80&d=identicon"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
{
|
||||
"object_kind": "issue",
|
||||
"event_type": "issue",
|
||||
"user": {
|
||||
"name": "Adam Birds",
|
||||
"username": "adambirds",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/1e00d93acdfdddc06304143a1dfcd0b4?s=80&d=identicon"
|
||||
},
|
||||
"project": {
|
||||
"id": 8427506,
|
||||
"name": "Zulip GitLab Test",
|
||||
"description": "",
|
||||
"web_url": "https://gitlab.com/adambirds/zulip-gitlab-test",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"git_http_url": "https://gitlab.com/adambirds/zulip-gitlab-test.git",
|
||||
"namespace": "adambirds",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "adambirds/zulip-gitlab-test",
|
||||
"default_branch": null,
|
||||
"ci_config_path": null,
|
||||
"homepage": "https://gitlab.com/adambirds/zulip-gitlab-test",
|
||||
"url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"ssh_url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"http_url": "https://gitlab.com/adambirds/zulip-gitlab-test.git"
|
||||
},
|
||||
"object_attributes": {
|
||||
"author_id": 1102929,
|
||||
"closed_at": null,
|
||||
"confidential": false,
|
||||
"created_at": "2018-09-17 21:01:30 UTC",
|
||||
"description": "Zulip Test Issue 2",
|
||||
"due_date": null,
|
||||
"id": 14226169,
|
||||
"iid": 2,
|
||||
"last_edited_at": null,
|
||||
"last_edited_by_id": null,
|
||||
"milestone_id": null,
|
||||
"moved_to_id": null,
|
||||
"project_id": 8427506,
|
||||
"relative_position": 1073742823,
|
||||
"state": "opened",
|
||||
"time_estimate": 0,
|
||||
"title": "Zulip Test Issue 2",
|
||||
"updated_at": "2018-09-17 21:01:30 UTC",
|
||||
"updated_by_id": null,
|
||||
"weight": null,
|
||||
"url": "https://gitlab.com/adambirds/zulip-gitlab-test/issues/2",
|
||||
"total_time_spent": 0,
|
||||
"human_total_time_spent": null,
|
||||
"human_time_estimate": null,
|
||||
"assignee_ids": [
|
||||
1102929,
|
||||
1129123
|
||||
],
|
||||
"assignee_id": 1102929,
|
||||
"action": "open"
|
||||
},
|
||||
"labels": [],
|
||||
"changes": {
|
||||
"author_id": {
|
||||
"previous": null,
|
||||
"current": 1102929
|
||||
},
|
||||
"created_at": {
|
||||
"previous": null,
|
||||
"current": "2018-09-17 21:01:30 UTC"
|
||||
},
|
||||
"description": {
|
||||
"previous": null,
|
||||
"current": "Zulip Test Issue 2"
|
||||
},
|
||||
"id": {
|
||||
"previous": null,
|
||||
"current": 14226169
|
||||
},
|
||||
"iid": {
|
||||
"previous": null,
|
||||
"current": 2
|
||||
},
|
||||
"project_id": {
|
||||
"previous": null,
|
||||
"current": 8427506
|
||||
},
|
||||
"relative_position": {
|
||||
"previous": null,
|
||||
"current": 1073742823
|
||||
},
|
||||
"state": {
|
||||
"previous": null,
|
||||
"current": "opened"
|
||||
},
|
||||
"title": {
|
||||
"previous": null,
|
||||
"current": "Zulip Test Issue 2"
|
||||
},
|
||||
"updated_at": {
|
||||
"previous": null,
|
||||
"current": "2018-09-17 21:01:30 UTC"
|
||||
},
|
||||
"assignees": {
|
||||
"previous": [],
|
||||
"current": [
|
||||
{
|
||||
"name": "Adam Birds",
|
||||
"username": "adambirds",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/1e00d93acdfdddc06304143a1dfcd0b4?s=80&d=identicon"
|
||||
},
|
||||
{
|
||||
"name": "Eeshan Garg",
|
||||
"username": "eeshangarg",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/cd181af88d928dab53c55600c9f7551d?s=80&d=identicon"
|
||||
}
|
||||
]
|
||||
},
|
||||
"total_time_spent": {
|
||||
"previous": null,
|
||||
"current": 0
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"name": "Zulip GitLab Test",
|
||||
"url": "git@gitlab.com:adambirds/zulip-gitlab-test.git",
|
||||
"description": "",
|
||||
"homepage": "https://gitlab.com/adambirds/zulip-gitlab-test"
|
||||
},
|
||||
"assignees": [
|
||||
{
|
||||
"name": "Adam Birds",
|
||||
"username": "adambirds",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/1e00d93acdfdddc06304143a1dfcd0b4?s=80&d=identicon"
|
||||
},
|
||||
{
|
||||
"name": "Eeshan Garg",
|
||||
"username": "eeshangarg",
|
||||
"avatar_url": "https://secure.gravatar.com/avatar/cd181af88d928dab53c55600c9f7551d?s=80&d=identicon"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -136,9 +136,31 @@ class GitlabHookTests(WebhookTestCase):
|
|||
HTTP_X_GITLAB_EVENT="Issue Hook"
|
||||
)
|
||||
|
||||
def test_create_issue_with_two_assignees_event_message(self) -> None:
|
||||
expected_subject = u"Zulip GitLab Test / Issue #2 Zulip Test Issue 2"
|
||||
expected_message = u"Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2)(assigned to adambirds and eeshangarg)\n\n~~~ quote\nZulip Test Issue 2\n~~~"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'issue_created_with_two_assignees',
|
||||
expected_subject,
|
||||
expected_message,
|
||||
HTTP_X_GITLAB_EVENT="Issue Hook"
|
||||
)
|
||||
|
||||
def test_create_issue_with_three_assignees_event_message(self) -> None:
|
||||
expected_subject = u"Zulip GitLab Test / Issue #2 Zulip Test Issue 2"
|
||||
expected_message = u"Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2)(assigned to adambirds, eeshangarg and timabbott)\n\n~~~ quote\nZulip Test Issue 2\n~~~"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'issue_created_with_three_assignees',
|
||||
expected_subject,
|
||||
expected_message,
|
||||
HTTP_X_GITLAB_EVENT="Issue Hook"
|
||||
)
|
||||
|
||||
def test_create_confidential_issue_with_assignee_event_message(self) -> None:
|
||||
expected_subject = u"testing / Issue #2 Testing"
|
||||
expected_message = u"Joe Bloggs created [Issue #2](https://gitlab.example.co.uk/joe.bloggs/testing/issues/2)(assigned to Joe Bloggs)\n\n~~~ quote\nTesting\n~~~"
|
||||
expected_message = u"Joe Bloggs created [Issue #2](https://gitlab.example.co.uk/joe.bloggs/testing/issues/2)(assigned to joe.bloggs)\n\n~~~ quote\nTesting\n~~~"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'confidential_issue_created_with_assignee',
|
||||
|
|
|
@ -75,6 +75,7 @@ def get_issue_created_event_body(payload: Dict[str, Any],
|
|||
payload['object_attributes'].get('iid'),
|
||||
description,
|
||||
get_objects_assignee(payload),
|
||||
payload.get('assignees'),
|
||||
title=payload['object_attributes'].get('title') if include_title else None
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue