mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Replace "Commit" to commits sha in commits comment events in git integrations.
This commit is contained in:
@@ -23,7 +23,10 @@ REMOVE_BRANCH_MESSAGE_TEMPLATE = u"{user_name} deleted branch {branch_name}"
|
|||||||
PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE = u"{user_name} {action} [{type}{id}]({url})"
|
PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE = u"{user_name} {action} [{type}{id}]({url})"
|
||||||
PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE = u"(assigned to {assignee})"
|
PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE = u"(assigned to {assignee})"
|
||||||
PULL_REQUEST_BRANCH_INFO_TEMPLATE = u"\nfrom `{target}` to `{base}`"
|
PULL_REQUEST_BRANCH_INFO_TEMPLATE = u"\nfrom `{target}` to `{base}`"
|
||||||
PULL_REQUEST_OR_ISSUE_CONTENT_MESSAGE_TEMPLATE = u"\n~~~ quote\n{message}\n~~~"
|
|
||||||
|
CONTENT_MESSAGE_TEMPLATE = u"\n~~~ quote\n{message}\n~~~"
|
||||||
|
|
||||||
|
COMMITS_COMMENT_MESSAGE_TEMPLATE = u"{user_name} {action} on [{sha}]({url})"
|
||||||
|
|
||||||
def get_push_commits_event_message(user_name, compare_url, branch_name, commits_data):
|
def get_push_commits_event_message(user_name, compare_url, branch_name, commits_data):
|
||||||
# type: (text_type, Optional[text_type], text_type, List[Dict[str, Any]]) -> text_type
|
# type: (text_type, Optional[text_type], text_type, List[Dict[str, Any]]) -> text_type
|
||||||
@@ -77,7 +80,7 @@ def get_pull_request_event_message(
|
|||||||
base=base_branch
|
base=base_branch
|
||||||
)
|
)
|
||||||
if message:
|
if message:
|
||||||
main_message += '\n' + PULL_REQUEST_OR_ISSUE_CONTENT_MESSAGE_TEMPLATE.format(message=message)
|
main_message += '\n' + CONTENT_MESSAGE_TEMPLATE.format(message=message)
|
||||||
return main_message.rstrip()
|
return main_message.rstrip()
|
||||||
|
|
||||||
def get_issue_event_message(user_name, action, url, number=None, message=None, assignee=None):
|
def get_issue_event_message(user_name, action, url, number=None, message=None, assignee=None):
|
||||||
@@ -92,12 +95,26 @@ def get_issue_event_message(user_name, action, url, number=None, message=None, a
|
|||||||
type='Issue'
|
type='Issue'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_commits_comment_action_message(user_name, action, commit_url, sha, message=None):
|
||||||
|
# type: (text_type, text_type, text_type, text_type, Optional[text_type]) -> text_type
|
||||||
|
content = COMMITS_COMMENT_MESSAGE_TEMPLATE.format(
|
||||||
|
user_name=user_name,
|
||||||
|
action=action,
|
||||||
|
sha=get_short_sha(sha),
|
||||||
|
url=commit_url
|
||||||
|
)
|
||||||
|
if message is not None:
|
||||||
|
content += CONTENT_MESSAGE_TEMPLATE.format(
|
||||||
|
message=message
|
||||||
|
)
|
||||||
|
return content
|
||||||
|
|
||||||
def get_commits_content(commits_data):
|
def get_commits_content(commits_data):
|
||||||
# type: (List[Dict[str, Any]]) -> text_type
|
# type: (List[Dict[str, Any]]) -> text_type
|
||||||
commits_content = u''
|
commits_content = u''
|
||||||
for commit in commits_data[:COMMITS_LIMIT]:
|
for commit in commits_data[:COMMITS_LIMIT]:
|
||||||
commits_content += COMMIT_ROW_TEMPLATE.format(
|
commits_content += COMMIT_ROW_TEMPLATE.format(
|
||||||
commit_short_sha=commit.get('sha')[:7],
|
commit_short_sha=get_short_sha(commit.get('sha')),
|
||||||
commit_url=commit.get('url'),
|
commit_url=commit.get('url'),
|
||||||
commit_msg=commit.get('message').partition('\n')[0]
|
commit_msg=commit.get('message').partition('\n')[0]
|
||||||
)
|
)
|
||||||
@@ -106,3 +123,7 @@ def get_commits_content(commits_data):
|
|||||||
commits_content += COMMITS_MORE_THAN_LIMIT_TEMPLATE.format(
|
commits_content += COMMITS_MORE_THAN_LIMIT_TEMPLATE.format(
|
||||||
commits_number=len(commits_data) - COMMITS_LIMIT)
|
commits_number=len(commits_data) - COMMITS_LIMIT)
|
||||||
return commits_content.rstrip()
|
return commits_content.rstrip()
|
||||||
|
|
||||||
|
def get_short_sha(sha):
|
||||||
|
# type: (text_type) -> text_type
|
||||||
|
return sha[:7]
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class Bitbucket2HookTests(WebhookTestCase):
|
|||||||
|
|
||||||
def test_bitbucket2_on_commit_comment_created_event(self):
|
def test_bitbucket2_on_commit_comment_created_event(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [Commit](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74)\n\n~~~ quote\nNice fix!\n~~~"
|
expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [32c4ea1](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74)\n~~~ quote\nNice fix!\n~~~"
|
||||||
self.send_and_test_stream_message('v2_commit_comment_created', self.EXPECTED_SUBJECT, expected_message)
|
self.send_and_test_stream_message('v2_commit_comment_created', self.EXPECTED_SUBJECT, expected_message)
|
||||||
|
|
||||||
def test_bitbucket2_on_commit_status_changed_event(self):
|
def test_bitbucket2_on_commit_status_changed_event(self):
|
||||||
|
|||||||
@@ -138,13 +138,13 @@ class GithubV1HookTests(WebhookTestCase):
|
|||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('commit_comment', 'commits',
|
self.basic_test('commit_comment', 'commits',
|
||||||
"zulip-test",
|
"zulip-test",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302) on [7c99467](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n~~~ quote\nAre we sure this is enough cowbell?\n~~~")
|
||||||
|
|
||||||
def test_commit_comment_line(self):
|
def test_commit_comment_line(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('commit_comment_line', 'commits',
|
self.basic_test('commit_comment_line', 'commits',
|
||||||
"zulip-test",
|
"zulip-test",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on [7c99467](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~")
|
||||||
|
|
||||||
class GithubV2HookTests(WebhookTestCase):
|
class GithubV2HookTests(WebhookTestCase):
|
||||||
STREAM_NAME = None # type: Optional[text_type]
|
STREAM_NAME = None # type: Optional[text_type]
|
||||||
@@ -280,10 +280,10 @@ class GithubV2HookTests(WebhookTestCase):
|
|||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('commit_comment', 'commits',
|
self.basic_test('commit_comment', 'commits',
|
||||||
"zulip-test",
|
"zulip-test",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302) on [7c99467](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n~~~ quote\nAre we sure this is enough cowbell?\n~~~")
|
||||||
|
|
||||||
def test_commit_comment_line(self):
|
def test_commit_comment_line(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('commit_comment_line', 'commits',
|
self.basic_test('commit_comment_line', 'commits',
|
||||||
"zulip-test",
|
"zulip-test",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on [7c99467](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~")
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class GitlabHookTests(WebhookTestCase):
|
|||||||
def test_note_commit_event_message(self):
|
def test_note_commit_event_message(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
expected_subject = u"my-awesome-project"
|
expected_subject = u"my-awesome-project"
|
||||||
expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7#note_14169211) on [Commit](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7)\n\n~~~ quote\nnice commit\n~~~"
|
expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7#note_14169211) on [66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7)\n~~~ quote\nnice commit\n~~~"
|
||||||
|
|
||||||
self.send_and_test_stream_message(
|
self.send_and_test_stream_message(
|
||||||
'commit_note',
|
'commit_note',
|
||||||
|
|||||||
@@ -12,14 +12,13 @@ from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_vi
|
|||||||
from zerver.models import Client, UserProfile
|
from zerver.models import Client, UserProfile
|
||||||
from zerver.lib.webhooks.git import get_push_commits_event_message, SUBJECT_WITH_BRANCH_TEMPLATE,\
|
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,\
|
get_force_push_commits_event_message, 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, get_issue_event_message, get_commits_comment_action_message
|
||||||
|
|
||||||
|
|
||||||
BITBUCKET_SUBJECT_TEMPLATE = '{repository_name}'
|
BITBUCKET_SUBJECT_TEMPLATE = '{repository_name}'
|
||||||
USER_PART = 'User {display_name}(login: {username})'
|
USER_PART = 'User {display_name}(login: {username})'
|
||||||
|
|
||||||
BITBUCKET_FORK_BODY = USER_PART + ' forked the repository into [{fork_name}]({fork_url}).'
|
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_COMMIT_STATUS_CHANGED_BODY = '[System {key}]({system_url}) changed status of {commit_info} to {status}.'
|
||||||
|
|
||||||
|
|
||||||
@@ -168,13 +167,13 @@ def get_fork_body(payload):
|
|||||||
def get_commit_comment_body(payload):
|
def get_commit_comment_body(payload):
|
||||||
# type: (Dict[str, Any]) -> text_type
|
# type: (Dict[str, Any]) -> text_type
|
||||||
comment = payload.get('comment')
|
comment = payload.get('comment')
|
||||||
action = u'[commented]({}) on'.format(comment['links']['html']['href'])
|
action = u'[commented]({})'.format(comment['links']['html']['href'])
|
||||||
return get_pull_request_event_message(
|
return get_commits_comment_action_message(
|
||||||
get_user_username(payload),
|
get_user_username(payload),
|
||||||
action,
|
action,
|
||||||
comment['commit']['links']['html']['href'],
|
comment['commit']['links']['html']['href'],
|
||||||
message=comment['content']['raw'],
|
comment['commit']['hash'],
|
||||||
type='Commit'
|
comment['content']['raw'],
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_commit_status_changed_body(payload):
|
def get_commit_status_changed_body(payload):
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ from zerver.views.messages import send_message_backend
|
|||||||
from zerver.lib.webhooks.git import get_push_commits_event_message,\
|
from zerver.lib.webhooks.git import get_push_commits_event_message,\
|
||||||
SUBJECT_WITH_BRANCH_TEMPLATE, get_force_push_commits_event_message, \
|
SUBJECT_WITH_BRANCH_TEMPLATE, get_force_push_commits_event_message, \
|
||||||
get_remove_branch_event_message, get_pull_request_event_message,\
|
get_remove_branch_event_message, get_pull_request_event_message,\
|
||||||
get_issue_event_message, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE
|
get_issue_event_message, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE,\
|
||||||
|
get_commits_comment_action_message
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import ujson
|
import ujson
|
||||||
@@ -176,13 +177,13 @@ def api_github_v2(user_profile, event, payload, branches, default_stream,
|
|||||||
subject = topic_focus
|
subject = topic_focus
|
||||||
|
|
||||||
comment = payload.get('comment')
|
comment = payload.get('comment')
|
||||||
action = u'[commented]({}) on'.format(comment['html_url'])
|
action = u'[commented]({})'.format(comment['html_url'])
|
||||||
content = get_pull_request_event_message(
|
content = get_commits_comment_action_message(
|
||||||
comment['user']['login'],
|
comment['user']['login'],
|
||||||
action,
|
action,
|
||||||
comment['html_url'].split('#', 1)[0],
|
comment['html_url'].split('#', 1)[0],
|
||||||
message=comment['body'],
|
comment['commit_id'],
|
||||||
type='Commit'
|
comment['body'],
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ from zerver.lib.response import json_success
|
|||||||
from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variables
|
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,\
|
from zerver.lib.webhooks.git import get_push_commits_event_message, EMPTY_SHA,\
|
||||||
get_remove_branch_event_message, get_pull_request_event_message,\
|
get_remove_branch_event_message, get_pull_request_event_message,\
|
||||||
get_issue_event_message, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE
|
get_issue_event_message, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE,\
|
||||||
|
get_commits_comment_action_message
|
||||||
from zerver.models import Client, UserProfile
|
from zerver.models import Client, UserProfile
|
||||||
|
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
@@ -123,13 +124,13 @@ def get_objects_assignee(payload):
|
|||||||
def get_commented_commit_event_body(payload):
|
def get_commented_commit_event_body(payload):
|
||||||
# type: (Dict[str, Any]) -> text_type
|
# type: (Dict[str, Any]) -> text_type
|
||||||
comment = payload.get('object_attributes')
|
comment = payload.get('object_attributes')
|
||||||
action = u'[commented]({}) on'.format(comment['url'])
|
action = u'[commented]({})'.format(comment['url'])
|
||||||
return get_pull_request_event_message(
|
return get_commits_comment_action_message(
|
||||||
get_issue_user_name(payload),
|
get_issue_user_name(payload),
|
||||||
action,
|
action,
|
||||||
payload.get('commit').get('url'),
|
payload.get('commit').get('url'),
|
||||||
message=comment['note'],
|
payload.get('commit').get('id'),
|
||||||
type='Commit'
|
comment['note'],
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_commented_merge_request_event_body(payload):
|
def get_commented_merge_request_event_body(payload):
|
||||||
|
|||||||
Reference in New Issue
Block a user