mirror of https://github.com/zulip/zulip.git
Normalize bitbucket issue event's subject and content.
This commit is contained in:
parent
171a4861cc
commit
a8da46db92
|
@ -67,7 +67,7 @@
|
|||
},
|
||||
"priority":"major",
|
||||
"created_on":"2016-07-04T17:36:51.890354+00:00",
|
||||
"id":2,
|
||||
"id":1,
|
||||
"type":"issue",
|
||||
"title":"Bug",
|
||||
"votes":0,
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
"component":null,
|
||||
"created_on":"2016-07-04T17:36:51.890354+00:00",
|
||||
"type":"issue",
|
||||
"id":2,
|
||||
"id":1,
|
||||
"milestone":null,
|
||||
"reporter":{
|
||||
"links":{
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
},
|
||||
"kind":"bug",
|
||||
"type":"issue",
|
||||
"id":2,
|
||||
"id":1,
|
||||
"reporter":{
|
||||
"display_name":"Tomasz",
|
||||
"uuid":"{678ab31f-9f88-4d7a-b343-1bdf9f024917}",
|
||||
|
|
|
@ -10,6 +10,7 @@ class Bitbucket2HookTests(WebhookTestCase):
|
|||
FIXTURE_DIR_NAME = 'bitbucket'
|
||||
EXPECTED_SUBJECT = u"Repository name"
|
||||
EXPECTED_SUBJECT_PR_EVENTS = u"Repository name / PR #1 new commit"
|
||||
EXPECTED_SUBJECT_ISSUE_EVENTS = u"Repository name / Issue #1 Bug"
|
||||
EXPECTED_SUBJECT_BRANCH_EVENTS = u"Repository name / master"
|
||||
|
||||
def test_bitbucket2_on_push_event(self):
|
||||
|
@ -55,18 +56,18 @@ class Bitbucket2HookTests(WebhookTestCase):
|
|||
|
||||
def test_bitbucket2_on_issue_created_event(self):
|
||||
# type: () -> None
|
||||
expected_message = u"User Tomasz(login: kolaszek) created [an issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)"
|
||||
self.send_and_test_stream_message('v2_issue_created', self.EXPECTED_SUBJECT, expected_message)
|
||||
expected_message = u"kolaszek created [Issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)(assigned to kolaszek)\n\n~~~ quote\nSuch a bug\n~~~"
|
||||
self.send_and_test_stream_message('v2_issue_created', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
|
||||
|
||||
def test_bitbucket2_on_issue_updated_event(self):
|
||||
# type: () -> None
|
||||
expected_message = u"User Tomasz(login: kolaszek) updated [an issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)"
|
||||
self.send_and_test_stream_message('v2_issue_updated', self.EXPECTED_SUBJECT, expected_message)
|
||||
expected_message = u"kolaszek updated [Issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)"
|
||||
self.send_and_test_stream_message('v2_issue_updated', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
|
||||
|
||||
def test_bitbucket2_on_issue_commented_event(self):
|
||||
# type: () -> None
|
||||
expected_message = u"User Tomasz(login: kolaszek) commented [an issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)"
|
||||
self.send_and_test_stream_message('v2_issue_commented', self.EXPECTED_SUBJECT, expected_message)
|
||||
expected_message = u"kolaszek commented [Issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)"
|
||||
self.send_and_test_stream_message('v2_issue_commented', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
|
||||
|
||||
def test_bitbucket2_on_pull_request_created_event(self):
|
||||
# type: () -> None
|
||||
|
|
|
@ -12,7 +12,7 @@ from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_vi
|
|||
from zerver.models import Client, UserProfile
|
||||
from zerver.lib.webhooks.git import get_push_commits_event_message, SUBJECT_WITH_BRANCH_TEMPLATE,\
|
||||
get_force_push_commits_event_message, get_remove_branch_event_message, get_pull_request_event_message,\
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_issue_event_message
|
||||
|
||||
|
||||
BITBUCKET_SUBJECT_TEMPLATE = '{repository_name}'
|
||||
|
@ -21,8 +21,6 @@ USER_PART = 'User {display_name}(login: {username})'
|
|||
BITBUCKET_FORK_BODY = USER_PART + ' forked the repository into [{fork_name}]({fork_url}).'
|
||||
BITBUCKET_COMMIT_COMMENT_BODY = USER_PART + ' added [comment]({url_to_comment}) to commit.'
|
||||
BITBUCKET_COMMIT_STATUS_CHANGED_BODY = '[System {key}]({system_url}) changed status of {commit_info} to {status}.'
|
||||
BITBUCKET_ISSUE_ACTION_BODY = USER_PART + ' {action} [an issue]({issue_url})'
|
||||
BITBUCKET_PULL_REQUEST_ACTION_BODY = USER_PART + ' {action} ["{title}" pull request]({pull_request_url})'
|
||||
BITBUCKET_PULL_REQUEST_COMMENT_ACTION_BODY = USER_PART + ' {action} [comment]({comment_url} ' + \
|
||||
'in ["{title}" pull request]({pull_request_url})'
|
||||
|
||||
|
@ -79,6 +77,13 @@ def get_subject_based_on_type(payload, type):
|
|||
id=payload['pullrequest']['id'],
|
||||
title=payload['pullrequest']['title']
|
||||
)
|
||||
if type.startswith('issue'):
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repository_name(payload.get('repository')),
|
||||
type='Issue',
|
||||
id=payload['issue']['id'],
|
||||
title=payload['issue']['title']
|
||||
)
|
||||
return get_subject(payload)
|
||||
|
||||
def get_type(request, payload):
|
||||
|
@ -185,12 +190,21 @@ def get_commit_status_changed_body(payload):
|
|||
)
|
||||
|
||||
def get_issue_action_body(payload, action):
|
||||
# type: (Dict[str, Any], str) -> str
|
||||
return BITBUCKET_ISSUE_ACTION_BODY.format(
|
||||
display_name=get_user_display_name(payload),
|
||||
username=get_user_username(payload),
|
||||
action=action,
|
||||
issue_url=payload['issue']['links']['html']['href']
|
||||
# type: (Dict[str, Any], str) -> text_type
|
||||
issue = payload['issue']
|
||||
assignee = None
|
||||
message = None
|
||||
if action == 'created':
|
||||
if issue['assignee']:
|
||||
assignee = issue['assignee'].get('username')
|
||||
message = issue['content']['raw']
|
||||
|
||||
return get_issue_event_message(
|
||||
get_user_username(payload),
|
||||
action,
|
||||
issue['links']['html']['href'],
|
||||
message,
|
||||
assignee
|
||||
)
|
||||
|
||||
def get_pull_request_action_body(payload, action):
|
||||
|
|
Loading…
Reference in New Issue