mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
Normalize github pull requests event message.
Add detailed info (description, source and target branch, assignee) to message. Change subject to 'repo_name / PR #id title'. Modify some test fixtures for better coverage.
This commit is contained in:
@@ -6,7 +6,24 @@
|
|||||||
"body": "Omitted something I think?",
|
"body": "Omitted something I think?",
|
||||||
"merge_commit_sha": null,
|
"merge_commit_sha": null,
|
||||||
"number": 7,
|
"number": 7,
|
||||||
"assignee": null,
|
"assignee": {
|
||||||
|
"following_url": "https://api.github.com/users/lfaraone/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/lfaraone/gists{/gist_id}",
|
||||||
|
"organizations_url": "https://api.github.com/users/lfaraone/orgs",
|
||||||
|
"url": "https://api.github.com/users/lfaraone",
|
||||||
|
"events_url": "https://api.github.com/users/lfaraone/events{/privacy}",
|
||||||
|
"html_url": "https://github.com/lfaraone",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/lfaraone/subscriptions",
|
||||||
|
"avatar_url": "https://0.gravatar.com/avatar/43918f842a892d0deb9ef1d8dcc9fe49?d=https%3A%2F%2Fidenticons.github.com%2F38b70bc4e5dd6c315c3acbe51c86820c.png",
|
||||||
|
"repos_url": "https://api.github.com/users/lfaraone/repos",
|
||||||
|
"received_events_url": "https://api.github.com/users/lfaraone/received_events",
|
||||||
|
"gravatar_id": "43918f842a892d0deb9ef1d8dcc9fe49",
|
||||||
|
"starred_url": "https://api.github.com/users/lfaraone/starred{/owner}{/repo}",
|
||||||
|
"login": "lfaraone",
|
||||||
|
"type": "User",
|
||||||
|
"id": 73410,
|
||||||
|
"followers_url": "https://api.github.com/users/lfaraone/followers"
|
||||||
|
},
|
||||||
"mergeable": null,
|
"mergeable": null,
|
||||||
"closed_at": null,
|
"closed_at": null,
|
||||||
"additions": 1,
|
"additions": 1,
|
||||||
|
|||||||
@@ -6,7 +6,24 @@
|
|||||||
"body": "Omitted something I think?",
|
"body": "Omitted something I think?",
|
||||||
"merge_commit_sha": null,
|
"merge_commit_sha": null,
|
||||||
"number": 7,
|
"number": 7,
|
||||||
"assignee": null,
|
"assignee": {
|
||||||
|
"following_url": "https://api.github.com/users/lfaraone/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/lfaraone/gists{/gist_id}",
|
||||||
|
"organizations_url": "https://api.github.com/users/lfaraone/orgs",
|
||||||
|
"url": "https://api.github.com/users/lfaraone",
|
||||||
|
"events_url": "https://api.github.com/users/lfaraone/events{/privacy}",
|
||||||
|
"html_url": "https://github.com/lfaraone",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/lfaraone/subscriptions",
|
||||||
|
"avatar_url": "https://0.gravatar.com/avatar/43918f842a892d0deb9ef1d8dcc9fe49?d=https%3A%2F%2Fidenticons.github.com%2F38b70bc4e5dd6c315c3acbe51c86820c.png",
|
||||||
|
"repos_url": "https://api.github.com/users/lfaraone/repos",
|
||||||
|
"received_events_url": "https://api.github.com/users/lfaraone/received_events",
|
||||||
|
"gravatar_id": "43918f842a892d0deb9ef1d8dcc9fe49",
|
||||||
|
"starred_url": "https://api.github.com/users/lfaraone/starred{/owner}{/repo}",
|
||||||
|
"login": "lfaraone",
|
||||||
|
"type": "User",
|
||||||
|
"id": 73410,
|
||||||
|
"followers_url": "https://api.github.com/users/lfaraone/followers"
|
||||||
|
},
|
||||||
"mergeable": null,
|
"mergeable": null,
|
||||||
"closed_at": null,
|
"closed_at": null,
|
||||||
"additions": 1,
|
"additions": 1,
|
||||||
|
|||||||
@@ -106,20 +106,20 @@ class GithubV1HookTests(WebhookTestCase):
|
|||||||
def test_pull_request_opened(self):
|
def test_pull_request_opened(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_opened', 'commits',
|
self.basic_test('pull_request_opened', 'commits',
|
||||||
"zulip-test: pull request 7: Counting is hard.",
|
"zulip-test / PR #7 Counting is hard.",
|
||||||
"lfaraone opened [pull request 7](https://github.com/zbenjamin/zulip-test/pull/7)\n\n~~~ quote\nOmitted something I think?\n~~~")
|
"lfaraone opened [PR](https://github.com/zbenjamin/zulip-test/pull/7)(assigned to lfaraone)\nfrom `patch-2` to `master`\n\n~~~ quote\nOmitted something I think?\n~~~")
|
||||||
|
|
||||||
def test_pull_request_closed(self):
|
def test_pull_request_closed(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_closed', 'commits',
|
self.basic_test('pull_request_closed', 'commits',
|
||||||
"zulip-test: pull request 7: Counting is hard.",
|
"zulip-test / PR #7 Counting is hard.",
|
||||||
"zbenjamin closed [pull request 7](https://github.com/zbenjamin/zulip-test/pull/7)")
|
"zbenjamin closed [PR](https://github.com/zbenjamin/zulip-test/pull/7)")
|
||||||
|
|
||||||
def test_pull_request_synchronize(self):
|
def test_pull_request_synchronize(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_synchronize', 'commits',
|
self.basic_test('pull_request_synchronize', 'commits',
|
||||||
"zulip-test: pull request 13: Even more cowbell.",
|
"zulip-test / PR #13 Even more cowbell.",
|
||||||
"zbenjamin synchronized [pull request 13](https://github.com/zbenjamin/zulip-test/pull/13)")
|
"zbenjamin synchronized [PR](https://github.com/zbenjamin/zulip-test/pull/13)")
|
||||||
|
|
||||||
def test_pull_request_comment(self):
|
def test_pull_request_comment(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
@@ -247,20 +247,21 @@ class GithubV2HookTests(WebhookTestCase):
|
|||||||
def test_pull_request_opened(self):
|
def test_pull_request_opened(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_opened', 'commits',
|
self.basic_test('pull_request_opened', 'commits',
|
||||||
"zulip-test: pull request 7: Counting is hard.",
|
"zulip-test / PR #7 Counting is hard.",
|
||||||
"lfaraone opened [pull request 7](https://github.com/zbenjamin/zulip-test/pull/7)\n\n~~~ quote\nOmitted something I think?\n~~~")
|
"lfaraone opened [PR](https://github.com/zbenjamin/zulip-test/pull/7)(assigned to lfaraone)\nfrom `patch-2` to `master`\n\n~~~ quote\nOmitted something I think?\n~~~")
|
||||||
|
|
||||||
def test_pull_request_closed(self):
|
def test_pull_request_closed(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_closed', 'commits',
|
self.basic_test('pull_request_closed', 'commits',
|
||||||
"zulip-test: pull request 7: Counting is hard.",
|
"zulip-test / PR #7 Counting is hard.",
|
||||||
"zbenjamin closed [pull request 7](https://github.com/zbenjamin/zulip-test/pull/7)")
|
"zbenjamin closed [PR](https://github.com/zbenjamin/zulip-test/pull/7)")
|
||||||
|
|
||||||
def test_pull_request_synchronize(self):
|
def test_pull_request_synchronize(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
self.basic_test('pull_request_synchronize', 'commits',
|
self.basic_test('pull_request_synchronize', 'commits',
|
||||||
"zulip-test: pull request 13: Even more cowbell.",
|
"zulip-test / PR #13 Even more cowbell.",
|
||||||
"zbenjamin synchronized [pull request 13](https://github.com/zbenjamin/zulip-test/pull/13)")
|
|
||||||
|
"zbenjamin synchronized [PR](https://github.com/zbenjamin/zulip-test/pull/13)")
|
||||||
|
|
||||||
def test_pull_request_comment(self):
|
def test_pull_request_comment(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ from zerver.decorator import authenticated_api_view, REQ, has_request_variables,
|
|||||||
from zerver.views.messages import send_message_backend
|
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_remove_branch_event_message, get_pull_request_event_message,\
|
||||||
|
SUBJECT_WITH_PR_INFO_TEMPLATE
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import ujson
|
import ujson
|
||||||
@@ -28,6 +29,25 @@ def is_test_repository(repository):
|
|||||||
class UnknownEventType(Exception):
|
class UnknownEventType(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def github_pull_request_content(payload):
|
||||||
|
# type: (Mapping[text_type, Any]) -> text_type
|
||||||
|
pull_request = payload['pull_request']
|
||||||
|
action = 'synchronized' if payload['action'] == 'synchronize' else payload['action']
|
||||||
|
if action in ('opened', 'edited'):
|
||||||
|
return get_pull_request_event_message(
|
||||||
|
payload['sender']['login'],
|
||||||
|
action,
|
||||||
|
pull_request['html_url'],
|
||||||
|
pull_request['head']['ref'],
|
||||||
|
pull_request['base']['ref'],
|
||||||
|
pull_request['body'],
|
||||||
|
pull_request.get('assignee', {}).get('login')
|
||||||
|
)
|
||||||
|
return get_pull_request_event_message(
|
||||||
|
payload['sender']['login'],
|
||||||
|
action,
|
||||||
|
pull_request['html_url'],
|
||||||
|
)
|
||||||
|
|
||||||
def github_generic_subject(noun, topic_focus, blob):
|
def github_generic_subject(noun, topic_focus, blob):
|
||||||
# type: (text_type, text_type, Mapping[text_type, Any]) -> text_type
|
# type: (text_type, text_type, Mapping[text_type, Any]) -> text_type
|
||||||
@@ -80,8 +100,13 @@ def api_github_v2(user_profile, event, payload, branches, default_stream,
|
|||||||
# Event Handlers
|
# Event Handlers
|
||||||
if event == 'pull_request':
|
if event == 'pull_request':
|
||||||
pull_req = payload['pull_request']
|
pull_req = payload['pull_request']
|
||||||
subject = github_generic_subject('pull request', topic_focus, pull_req)
|
subject = SUBJECT_WITH_PR_INFO_TEMPLATE.format(
|
||||||
content = github_generic_content('pull request', payload, pull_req)
|
repo=repository['name'],
|
||||||
|
type='PR',
|
||||||
|
id=pull_req['number'],
|
||||||
|
title=pull_req['title']
|
||||||
|
)
|
||||||
|
content = github_pull_request_content(payload)
|
||||||
elif event == 'issues':
|
elif event == 'issues':
|
||||||
# in v1, we assume that this stream exists since it is
|
# in v1, we assume that this stream exists since it is
|
||||||
# deprecated and the few realms that use it already have the
|
# deprecated and the few realms that use it already have the
|
||||||
|
|||||||
Reference in New Issue
Block a user