Normalize bitbucket push event.

Normalize bitbukcet push event by creating it by
get_push_commits_event_message common function.
This commit is contained in:
Tomasz Kolek 2016-10-01 11:03:07 +02:00 committed by Tim Abbott
parent 1c1a003ba1
commit 809bc5f29b
1 changed files with 14 additions and 8 deletions

View File

@ -10,8 +10,7 @@ from zerver.lib.actions import check_send_message
from zerver.lib.response import json_success
from zerver.lib.validator import check_dict
from zerver.decorator import REQ, has_request_variables, authenticated_rest_api_view
from .github import build_commit_list_content
from zerver.lib.webhooks.git import get_push_commits_event_message
@authenticated_rest_api_view(is_webhook=True)
@ -20,11 +19,18 @@ def api_bitbucket_webhook(request, user_profile, payload=REQ(validator=check_dic
stream=REQ(default='commits')):
# type: (HttpRequest, UserProfile, Mapping[text_type, Any], text_type) -> HttpResponse
repository = payload['repository']
commits = [{u'id': commit['raw_node'], u'message': commit['message'],
u'url': u'%s%scommits/%s' % (payload['canon_url'],
repository['absolute_url'],
commit['raw_node'])}
for commit in payload['commits']]
commits = [
{
'sha': commit.get('raw_node'),
'message': commit.get('message'),
'url': u'{}{}commits/{}'.format(
payload.get('canon_url'),
repository.get('absolute_url'),
commit.get('raw_node'))
}
for commit in payload.get('commits')
]
subject = repository['name']
if len(commits) == 0:
@ -35,7 +41,7 @@ def api_bitbucket_webhook(request, user_profile, payload=REQ(validator=check_dic
payload['canon_url'] + repository['absolute_url']))
else:
branch = payload['commits'][-1]['branch']
content = build_commit_list_content(commits, branch, None, payload['user'])
content = get_push_commits_event_message(payload.get('user'), None, branch, commits)
subject += u'/%s' % (branch,)
check_send_message(user_profile, get_client("ZulipBitBucketWebhook"), "stream",