mirror of https://github.com/zulip/zulip.git
Normalize gitlab issue event's subject and content.
This commit is contained in:
parent
a8da46db92
commit
56dd1a9b90
|
@ -56,8 +56,8 @@ class GitlabHookTests(WebhookTestCase):
|
|||
|
||||
def test_create_issue_without_assignee_event_message(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"my-awesome-project"
|
||||
expected_message = u"Tomasz Kolek created [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
|
||||
expected_subject = u"my-awesome-project / Issue #1 Issue title"
|
||||
expected_message = u"Tomasz Kolek created [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)\n\n~~~ quote\nIssue description\n~~~"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'issue_created_without_assignee',
|
||||
|
@ -68,8 +68,8 @@ class GitlabHookTests(WebhookTestCase):
|
|||
|
||||
def test_create_issue_with_assignee_event_message(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"my-awesome-project"
|
||||
expected_message = u"Tomasz Kolek created [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1) (assigned to Tomasz Kolek)."
|
||||
expected_subject = u"my-awesome-project / Issue #1 Issue title"
|
||||
expected_message = u"Tomasz Kolek created [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)(assigned to Tomasz Kolek)\n\n~~~ quote\nIssue description\n~~~"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'issue_created_with_assignee',
|
||||
|
@ -80,8 +80,8 @@ class GitlabHookTests(WebhookTestCase):
|
|||
|
||||
def test_update_issue_event_message(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"my-awesome-project"
|
||||
expected_message = u"Tomasz Kolek updated [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
|
||||
expected_subject = u"my-awesome-project / Issue #1 Issue title_new"
|
||||
expected_message = u"Tomasz Kolek updated [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'issue_updated',
|
||||
|
@ -92,8 +92,8 @@ class GitlabHookTests(WebhookTestCase):
|
|||
|
||||
def test_close_issue_event_message(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"my-awesome-project"
|
||||
expected_message = u"Tomasz Kolek closed [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
|
||||
expected_subject = u"my-awesome-project / Issue #1 Issue title_new"
|
||||
expected_message = u"Tomasz Kolek closed [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'issue_closed',
|
||||
|
@ -104,8 +104,8 @@ class GitlabHookTests(WebhookTestCase):
|
|||
|
||||
def test_reopen_issue_event_message(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"my-awesome-project"
|
||||
expected_message = u"Tomasz Kolek reopened [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
|
||||
expected_subject = u"my-awesome-project / Issue #1 Issue title_new"
|
||||
expected_message = u"Tomasz Kolek reopened [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)"
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'issue_reopened',
|
||||
|
@ -176,7 +176,7 @@ class GitlabHookTests(WebhookTestCase):
|
|||
def test_merge_request_created_with_assignee_event_message(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"my-awesome-project / MR #3 New Merge Request"
|
||||
expected_message = u"Tomasz Kolek created [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to tomaszkolek0)\nfrom `tomek` to `master`\n\n~~~ quote\ndescription of merge request\n~~~"
|
||||
expected_message = u"Tomasz Kolek created [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to Tomasz Kolek)\nfrom `tomek` to `master`\n\n~~~ quote\ndescription of merge request\n~~~"
|
||||
self.send_and_test_stream_message(
|
||||
'merge_request_created_with_assignee',
|
||||
expected_subject,
|
||||
|
@ -199,7 +199,7 @@ class GitlabHookTests(WebhookTestCase):
|
|||
def test_merge_request_updated_event_message(self):
|
||||
# type: () -> None
|
||||
expected_subject = u"my-awesome-project / MR #3 New Merge Request"
|
||||
expected_message = u"Tomasz Kolek updated [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to tomaszkolek0)\nfrom `tomek` to `master`\n\n~~~ quote\nupdated desc\n~~~"
|
||||
expected_message = u"Tomasz Kolek updated [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to Tomasz Kolek)\nfrom `tomek` to `master`\n\n~~~ quote\nupdated desc\n~~~"
|
||||
self.send_and_test_stream_message(
|
||||
'merge_request_updated',
|
||||
expected_subject,
|
||||
|
|
|
@ -5,7 +5,7 @@ from zerver.lib.response import json_success
|
|||
from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variables
|
||||
from zerver.lib.webhooks.git import get_push_commits_event_message, EMPTY_SHA,\
|
||||
get_remove_branch_event_message, get_pull_request_event_message,\
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE
|
||||
get_issue_event_message, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE
|
||||
from zerver.models import Client, UserProfile
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
@ -64,19 +64,20 @@ def get_tag_push_event_body(payload):
|
|||
|
||||
def get_issue_created_event_body(payload):
|
||||
# type: (Dict[str, Any]) -> text_type
|
||||
body = get_issue_event_body(payload, "created")
|
||||
assignee_name = payload.get('assignee', {}).get('name')
|
||||
if assignee_name:
|
||||
body = u"{} (assigned to {}).".format(body[:-1], assignee_name)
|
||||
return body
|
||||
return get_issue_event_message(
|
||||
get_issue_user_name(payload),
|
||||
'created',
|
||||
get_object_url(payload),
|
||||
payload.get('object_attributes').get('description'),
|
||||
get_objects_assignee(payload)
|
||||
)
|
||||
|
||||
def get_issue_event_body(payload, action):
|
||||
# type: (Dict[str, Any], text_type) -> text_type
|
||||
return "{} {} [Issue #{}]({}).".format(
|
||||
return get_issue_event_message(
|
||||
get_issue_user_name(payload),
|
||||
action,
|
||||
get_object_iid(payload),
|
||||
get_object_url(payload)
|
||||
get_object_url(payload),
|
||||
)
|
||||
|
||||
def get_merge_request_updated_event_body(payload):
|
||||
|
@ -105,10 +106,16 @@ def get_merge_request_open_or_updated_body(payload, action):
|
|||
pull_request.get('source_branch'),
|
||||
pull_request.get('target_branch'),
|
||||
pull_request.get('description'),
|
||||
payload.get('assignee', {}).get('username'),
|
||||
get_objects_assignee(payload),
|
||||
type='MR',
|
||||
)
|
||||
|
||||
def get_objects_assignee(payload):
|
||||
# type: (Dict[str, Any]) -> text_type
|
||||
assignee_object = payload.get('assignee')
|
||||
if assignee_object:
|
||||
return assignee_object.get('name')
|
||||
|
||||
def get_commented_commit_event_body(payload):
|
||||
# type: (Dict[str, Any]) -> text_type
|
||||
return u"{} added [comment]({}) to [Commit]({}).".format(
|
||||
|
@ -272,6 +279,13 @@ def get_subject_based_on_event(event, payload):
|
|||
id=payload.get('object_attributes').get('iid'),
|
||||
title=payload.get('object_attributes').get('title')
|
||||
)
|
||||
elif event.startswith('Issue Hook'):
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repo_name(payload),
|
||||
type='Issue',
|
||||
id=payload.get('object_attributes').get('iid'),
|
||||
title=payload.get('object_attributes').get('title')
|
||||
)
|
||||
return get_repo_name(payload)
|
||||
|
||||
def get_event(request, payload):
|
||||
|
|
Loading…
Reference in New Issue