mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
Normalize github issue or PR comment event's subject and content.
This commit is contained in:
@@ -94,8 +94,8 @@ class GithubV1HookTests(WebhookTestCase):
|
|||||||
def test_issue_comment(self):
|
def test_issue_comment(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('issue_comment', 'issues',
|
self.basic_test('issue_comment', 'issues',
|
||||||
"zulip-test: issue 5: The frobnicator doesn't work",
|
"zulip-test / Issue #5 The frobnicator doesn't work",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) on [issue 5](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) [Issue](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~")
|
||||||
|
|
||||||
def test_issues_closed(self):
|
def test_issues_closed(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
@@ -124,14 +124,14 @@ class GithubV1HookTests(WebhookTestCase):
|
|||||||
def test_pull_request_comment(self):
|
def test_pull_request_comment(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_comment', 'commits',
|
self.basic_test('pull_request_comment', 'commits',
|
||||||
"zulip-test: pull request 9: Less cowbell.",
|
"zulip-test / PR #9 Less cowbell.",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [pull request 9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~")
|
||||||
|
|
||||||
def test_pull_request_comment_user_specified_stream(self):
|
def test_pull_request_comment_user_specified_stream(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_comment', 'my_commits',
|
self.basic_test('pull_request_comment', 'my_commits',
|
||||||
"zulip-test: pull request 9: Less cowbell.",
|
"zulip-test / PR #9 Less cowbell.",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [pull request 9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~",
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~",
|
||||||
send_stream=True)
|
send_stream=True)
|
||||||
|
|
||||||
def test_commit_comment(self):
|
def test_commit_comment(self):
|
||||||
@@ -235,8 +235,8 @@ class GithubV2HookTests(WebhookTestCase):
|
|||||||
def test_issue_comment(self):
|
def test_issue_comment(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('issue_comment', 'issues',
|
self.basic_test('issue_comment', 'issues',
|
||||||
"zulip-test: issue 5: The frobnicator doesn't work",
|
"zulip-test / Issue #5 The frobnicator doesn't work",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) on [issue 5](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) [Issue](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~")
|
||||||
|
|
||||||
def test_issues_closed(self):
|
def test_issues_closed(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
@@ -266,14 +266,14 @@ class GithubV2HookTests(WebhookTestCase):
|
|||||||
def test_pull_request_comment(self):
|
def test_pull_request_comment(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_comment', 'commits',
|
self.basic_test('pull_request_comment', 'commits',
|
||||||
"zulip-test: pull request 9: Less cowbell.",
|
"zulip-test / PR #9 Less cowbell.",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [pull request 9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~")
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~")
|
||||||
|
|
||||||
def test_pull_request_comment_user_specified_stream(self):
|
def test_pull_request_comment_user_specified_stream(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_comment', 'my_commits',
|
self.basic_test('pull_request_comment', 'my_commits',
|
||||||
"zulip-test: pull request 9: Less cowbell.",
|
"zulip-test / PR #9 Less cowbell.",
|
||||||
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [pull request 9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~",
|
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~",
|
||||||
send_stream=True)
|
send_stream=True)
|
||||||
|
|
||||||
def test_commit_comment(self):
|
def test_commit_comment(self):
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ from typing import Any, Mapping, Optional, Sequence, Tuple
|
|||||||
from zerver.lib.str_utils import force_str
|
from zerver.lib.str_utils import force_str
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
|
|
||||||
COMMITS_IN_LIST_LIMIT = 10
|
|
||||||
ZULIP_TEST_REPO_NAME = 'zulip-test'
|
ZULIP_TEST_REPO_NAME = 'zulip-test'
|
||||||
ZULIP_TEST_REPO_ID = 6893087
|
ZULIP_TEST_REPO_ID = 6893087
|
||||||
|
|
||||||
@@ -33,6 +32,7 @@ def github_pull_request_content(payload):
|
|||||||
# type: (Mapping[text_type, Any]) -> text_type
|
# type: (Mapping[text_type, Any]) -> text_type
|
||||||
pull_request = payload['pull_request']
|
pull_request = payload['pull_request']
|
||||||
action = get_pull_request_or_issue_action(payload)
|
action = get_pull_request_or_issue_action(payload)
|
||||||
|
|
||||||
if action in ('opened', 'edited'):
|
if action in ('opened', 'edited'):
|
||||||
return get_pull_request_event_message(
|
return get_pull_request_event_message(
|
||||||
payload['sender']['login'],
|
payload['sender']['login'],
|
||||||
@@ -53,6 +53,7 @@ def github_issues_content(payload):
|
|||||||
# type: (Mapping[text_type, Any]) -> text_type
|
# type: (Mapping[text_type, Any]) -> text_type
|
||||||
issue = payload['issue']
|
issue = payload['issue']
|
||||||
action = get_pull_request_or_issue_action(payload)
|
action = get_pull_request_or_issue_action(payload)
|
||||||
|
|
||||||
if action in ('opened', 'edited'):
|
if action in ('opened', 'edited'):
|
||||||
return get_issue_event_message(
|
return get_issue_event_message(
|
||||||
payload['sender']['login'],
|
payload['sender']['login'],
|
||||||
@@ -67,6 +68,20 @@ def github_issues_content(payload):
|
|||||||
issue['html_url'],
|
issue['html_url'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def github_object_commented_content(payload, type):
|
||||||
|
# type: (Mapping[text_type, Any], text_type) -> text_type
|
||||||
|
comment = payload['comment']
|
||||||
|
issue = payload['issue']
|
||||||
|
action = u'[commented]({})'.format(comment['html_url'])
|
||||||
|
|
||||||
|
return get_pull_request_event_message(
|
||||||
|
comment['user']['login'],
|
||||||
|
action,
|
||||||
|
issue['html_url'],
|
||||||
|
message=comment['body'],
|
||||||
|
type=type
|
||||||
|
)
|
||||||
|
|
||||||
def get_pull_request_or_issue_action(payload):
|
def get_pull_request_or_issue_action(payload):
|
||||||
# type: (Mapping[text_type, Any]) -> text_type
|
# type: (Mapping[text_type, Any]) -> text_type
|
||||||
return 'synchronized' if payload['action'] == 'synchronize' else payload['action']
|
return 'synchronized' if payload['action'] == 'synchronize' else payload['action']
|
||||||
@@ -135,20 +150,15 @@ def api_github_v2(user_profile, event, payload, branches, default_stream,
|
|||||||
if 'pull_request' not in issue or issue['pull_request']['diff_url'] is None:
|
if 'pull_request' not in issue or issue['pull_request']['diff_url'] is None:
|
||||||
# It's an issues comment
|
# It's an issues comment
|
||||||
target_stream = issue_stream
|
target_stream = issue_stream
|
||||||
noun = 'issue'
|
type = 'Issue'
|
||||||
|
subject = get_pull_request_or_issue_subject(repository, payload['issue'], type)
|
||||||
else:
|
else:
|
||||||
# It's a pull request comment
|
# It's a pull request comment
|
||||||
noun = 'pull request'
|
type = 'PR'
|
||||||
|
subject = get_pull_request_or_issue_subject(repository, payload['issue'], type)
|
||||||
|
|
||||||
|
content = github_object_commented_content(payload, type)
|
||||||
|
|
||||||
subject = github_generic_subject(noun, topic_focus, issue)
|
|
||||||
comment = payload['comment']
|
|
||||||
content = (u'%s [commented](%s) on [%s %d](%s)\n\n~~~ quote\n%s\n~~~'
|
|
||||||
% (comment['user']['login'],
|
|
||||||
comment['html_url'],
|
|
||||||
noun,
|
|
||||||
issue['number'],
|
|
||||||
issue['html_url'],
|
|
||||||
comment['body']))
|
|
||||||
elif event == 'push':
|
elif event == 'push':
|
||||||
subject, content = build_message_from_gitlog(user_profile, topic_focus,
|
subject, content = build_message_from_gitlog(user_profile, topic_focus,
|
||||||
payload['ref'], payload['commits'],
|
payload['ref'], payload['commits'],
|
||||||
|
|||||||
Reference in New Issue
Block a user