webhooks/github: Improve punctuation.

This commit is contained in:
Eeshan Garg
2019-05-08 22:21:28 -02:30
committed by Tim Abbott
parent 9516699c73
commit ef070ef019
3 changed files with 32 additions and 31 deletions

View File

@@ -193,6 +193,7 @@ def get_setup_webhook_message(integration: str, user_name: Optional[str]=None) -
content = SETUP_MESSAGE_TEMPLATE.format(integration=integration) content = SETUP_MESSAGE_TEMPLATE.format(integration=integration)
if user_name: if user_name:
content += SETUP_MESSAGE_USER_PART.format(user_name=user_name) content += SETUP_MESSAGE_USER_PART.format(user_name=user_name)
content = "{}.".format(content)
return content return content
def get_issue_event_message(user_name: str, def get_issue_event_message(user_name: str,

View File

@@ -16,11 +16,11 @@ class GithubWebhookTest(WebhookTestCase):
EXPECTED_TOPIC_WIKI_EVENTS = u"public-repo / Wiki Pages" EXPECTED_TOPIC_WIKI_EVENTS = u"public-repo / Wiki Pages"
def test_ping_event(self) -> None: def test_ping_event(self) -> None:
expected_message = u"GitHub webhook has been successfully configured by TomaszKolek" expected_message = u"GitHub webhook has been successfully configured by TomaszKolek."
self.send_and_test_stream_message('ping', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='ping') self.send_and_test_stream_message('ping', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='ping')
def test_ping_organization_event(self) -> None: def test_ping_organization_event(self) -> None:
expected_message = u"GitHub webhook has been successfully configured by eeshangarg" expected_message = u"GitHub webhook has been successfully configured by eeshangarg."
self.send_and_test_stream_message('ping_organization', 'zulip-test-org', expected_message, HTTP_X_GITHUB_EVENT='ping') self.send_and_test_stream_message('ping_organization', 'zulip-test-org', expected_message, HTTP_X_GITHUB_EVENT='ping')
def test_push_delete_branch(self) -> None: def test_push_delete_branch(self) -> None:
@@ -90,23 +90,23 @@ class GithubWebhookTest(WebhookTestCase):
self.send_and_test_stream_message('commit_comment', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='commit_comment') self.send_and_test_stream_message('commit_comment', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='commit_comment')
def test_create_msg(self) -> None: def test_create_msg(self) -> None:
expected_message = u"baxterthehacker created tag 0.0.1" expected_message = u"baxterthehacker created tag 0.0.1."
self.send_and_test_stream_message('create', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='create') self.send_and_test_stream_message('create', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='create')
def test_delete_msg(self) -> None: def test_delete_msg(self) -> None:
expected_message = u"baxterthehacker deleted tag simple-tag" expected_message = u"baxterthehacker deleted tag simple-tag."
self.send_and_test_stream_message('delete', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='delete') self.send_and_test_stream_message('delete', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='delete')
def test_deployment_msg(self) -> None: def test_deployment_msg(self) -> None:
expected_message = u"baxterthehacker created new deployment" expected_message = u"baxterthehacker created new deployment."
self.send_and_test_stream_message('deployment', self.EXPECTED_TOPIC_DEPLOYMENT_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='deployment') self.send_and_test_stream_message('deployment', self.EXPECTED_TOPIC_DEPLOYMENT_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='deployment')
def test_deployment_status_msg(self) -> None: def test_deployment_status_msg(self) -> None:
expected_message = u"Deployment changed status to success" expected_message = u"Deployment changed status to success."
self.send_and_test_stream_message('deployment_status', self.EXPECTED_TOPIC_DEPLOYMENT_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='deployment_status') self.send_and_test_stream_message('deployment_status', self.EXPECTED_TOPIC_DEPLOYMENT_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='deployment_status')
def test_fork_msg(self) -> None: def test_fork_msg(self) -> None:
expected_message = u"baxterandthehackers forked [public-repo](https://github.com/baxterandthehackers/public-repo)" expected_message = u"baxterandthehackers forked [public-repo](https://github.com/baxterandthehackers/public-repo)."
self.send_and_test_stream_message('fork', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='fork') self.send_and_test_stream_message('fork', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='fork')
def test_issue_comment_msg(self) -> None: def test_issue_comment_msg(self) -> None:
@@ -140,21 +140,21 @@ class GithubWebhookTest(WebhookTestCase):
self.send_and_test_stream_message('issue', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='issues') self.send_and_test_stream_message('issue', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='issues')
def test_membership_msg(self) -> None: def test_membership_msg(self) -> None:
expected_message = u"baxterthehacker added [kdaigle](https://github.com/kdaigle) to the Contractors team" expected_message = u"baxterthehacker added [kdaigle](https://github.com/kdaigle) to the Contractors team."
self.send_and_test_stream_message('membership', self.send_and_test_stream_message('membership',
self.EXPECTED_TOPIC_ORGANIZATION_EVENTS, self.EXPECTED_TOPIC_ORGANIZATION_EVENTS,
expected_message, expected_message,
HTTP_X_GITHUB_EVENT='membership') HTTP_X_GITHUB_EVENT='membership')
def test_membership_removal_msg(self) -> None: def test_membership_removal_msg(self) -> None:
expected_message = u"baxterthehacker removed [kdaigle](https://github.com/kdaigle) from the Contractors team" expected_message = u"baxterthehacker removed [kdaigle](https://github.com/kdaigle) from the Contractors team."
self.send_and_test_stream_message('membership_removal', self.send_and_test_stream_message('membership_removal',
self.EXPECTED_TOPIC_ORGANIZATION_EVENTS, self.EXPECTED_TOPIC_ORGANIZATION_EVENTS,
expected_message, expected_message,
HTTP_X_GITHUB_EVENT='membership') HTTP_X_GITHUB_EVENT='membership')
def test_member_msg(self) -> None: def test_member_msg(self) -> None:
expected_message = u"baxterthehacker added [octocat](https://github.com/octocat) to [public-repo](https://github.com/baxterthehacker/public-repo)" expected_message = u"baxterthehacker added [octocat](https://github.com/octocat) to [public-repo](https://github.com/baxterthehacker/public-repo)."
self.send_and_test_stream_message('member', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='member') self.send_and_test_stream_message('member', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='member')
def test_pull_request_opened_msg(self) -> None: def test_pull_request_opened_msg(self) -> None:
@@ -193,7 +193,7 @@ class GithubWebhookTest(WebhookTestCase):
self.send_and_test_stream_message('merged_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request') self.send_and_test_stream_message('merged_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request')
def test_public_msg(self) -> None: def test_public_msg(self) -> None:
expected_message = u"baxterthehacker made [the repository](https://github.com/baxterthehacker/public-repo) public" expected_message = u"baxterthehacker made [the repository](https://github.com/baxterthehacker/public-repo) public."
self.send_and_test_stream_message('public', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='public') self.send_and_test_stream_message('public', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='public')
def test_wiki_pages_msg(self) -> None: def test_wiki_pages_msg(self) -> None:
@@ -201,31 +201,31 @@ class GithubWebhookTest(WebhookTestCase):
self.send_and_test_stream_message('wiki_pages', self.EXPECTED_TOPIC_WIKI_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='gollum') self.send_and_test_stream_message('wiki_pages', self.EXPECTED_TOPIC_WIKI_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='gollum')
def test_watch_msg(self) -> None: def test_watch_msg(self) -> None:
expected_message = u"baxterthehacker starred [the repository](https://github.com/baxterthehacker/public-repo)" expected_message = u"baxterthehacker starred [the repository](https://github.com/baxterthehacker/public-repo)."
self.send_and_test_stream_message('watch_repository', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='watch') self.send_and_test_stream_message('watch_repository', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='watch')
def test_repository_msg(self) -> None: def test_repository_msg(self) -> None:
expected_message = u"baxterthehacker created [the repository](https://github.com/baxterandthehackers/public-repo)" expected_message = u"baxterthehacker created [the repository](https://github.com/baxterandthehackers/public-repo)."
self.send_and_test_stream_message('repository', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='repository') self.send_and_test_stream_message('repository', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='repository')
def test_team_add_msg(self) -> None: def test_team_add_msg(self) -> None:
expected_message = u"[The repository](https://github.com/baxterandthehackers/public-repo) was added to team github" expected_message = u"[The repository](https://github.com/baxterandthehackers/public-repo) was added to team github."
self.send_and_test_stream_message('team_add', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='team_add') self.send_and_test_stream_message('team_add', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='team_add')
def test_release_msg(self) -> None: def test_release_msg(self) -> None:
expected_message = u"baxterthehacker published [the release](https://github.com/baxterthehacker/public-repo/releases/tag/0.0.1)" expected_message = u"baxterthehacker published [the release](https://github.com/baxterthehacker/public-repo/releases/tag/0.0.1)."
self.send_and_test_stream_message('release', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='release') self.send_and_test_stream_message('release', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='release')
def test_page_build_msg(self) -> None: def test_page_build_msg(self) -> None:
expected_message = u"Github Pages build, trigerred by baxterthehacker, has finished building" expected_message = u"Github Pages build, trigerred by baxterthehacker, has finished building."
self.send_and_test_stream_message('page_build', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='page_build') self.send_and_test_stream_message('page_build', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='page_build')
def test_status_msg(self) -> None: def test_status_msg(self) -> None:
expected_message = u"[9049f12](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to success" expected_message = u"[9049f12](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to success."
self.send_and_test_stream_message('status', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='status') self.send_and_test_stream_message('status', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='status')
def test_status_with_target_url_msg(self) -> None: def test_status_with_target_url_msg(self) -> None:
expected_message = u"[9049f12](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to [success](https://example.com/build/status)" expected_message = u"[9049f12](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to [success](https://example.com/build/status)."
self.send_and_test_stream_message( self.send_and_test_stream_message(
'status_with_target_url', 'status_with_target_url',
self.EXPECTED_TOPIC_REPO_EVENTS, self.EXPECTED_TOPIC_REPO_EVENTS,

View File

@@ -77,7 +77,7 @@ def get_membership_body(payload: Dict[str, Any]) -> str:
member = payload['member'] member = payload['member']
team_name = payload['team']['name'] team_name = payload['team']['name']
return u"{sender} {action} [{username}]({html_url}) {preposition} the {team_name} team".format( return u"{sender} {action} [{username}]({html_url}) {preposition} the {team_name} team.".format(
sender=get_sender_name(payload), sender=get_sender_name(payload),
action=action, action=action,
username=member['login'], username=member['login'],
@@ -87,7 +87,7 @@ def get_membership_body(payload: Dict[str, Any]) -> str:
) )
def get_member_body(payload: Dict[str, Any]) -> str: def get_member_body(payload: Dict[str, Any]) -> str:
return u"{} {} [{}]({}) to [{}]({})".format( return u"{} {} [{}]({}) to [{}]({}).".format(
get_sender_name(payload), get_sender_name(payload),
payload['action'], payload['action'],
payload['member']['login'], payload['member']['login'],
@@ -134,25 +134,25 @@ def get_issue_comment_body(payload: Dict[str, Any],
def get_fork_body(payload: Dict[str, Any]) -> str: def get_fork_body(payload: Dict[str, Any]) -> str:
forkee = payload['forkee'] forkee = payload['forkee']
return u"{} forked [{}]({})".format( return u"{} forked [{}]({}).".format(
get_sender_name(payload), get_sender_name(payload),
forkee['name'], forkee['name'],
forkee['html_url'] forkee['html_url']
) )
def get_deployment_body(payload: Dict[str, Any]) -> str: def get_deployment_body(payload: Dict[str, Any]) -> str:
return u'{} created new deployment'.format( return u'{} created new deployment.'.format(
get_sender_name(payload), get_sender_name(payload),
) )
def get_change_deployment_status_body(payload: Dict[str, Any]) -> str: def get_change_deployment_status_body(payload: Dict[str, Any]) -> str:
return u'Deployment changed status to {}'.format( return u'Deployment changed status to {}.'.format(
payload['deployment_status']['state'], payload['deployment_status']['state'],
) )
def get_create_or_delete_body(payload: Dict[str, Any], action: str) -> str: def get_create_or_delete_body(payload: Dict[str, Any], action: str) -> str:
ref_type = payload['ref_type'] ref_type = payload['ref_type']
return u'{} {} {} {}'.format( return u'{} {} {} {}.'.format(
get_sender_name(payload), get_sender_name(payload),
action, action,
ref_type, ref_type,
@@ -196,7 +196,7 @@ def get_push_commits_body(payload: Dict[str, Any]) -> str:
) )
def get_public_body(payload: Dict[str, Any]) -> str: def get_public_body(payload: Dict[str, Any]) -> str:
return u"{} made [the repository]({}) public".format( return u"{} made [the repository]({}) public.".format(
get_sender_name(payload), get_sender_name(payload),
payload['repository']['html_url'], payload['repository']['html_url'],
) )
@@ -213,26 +213,26 @@ def get_wiki_pages_body(payload: Dict[str, Any]) -> str:
return u"{}:\n{}".format(get_sender_name(payload), wiki_info.rstrip()) return u"{}:\n{}".format(get_sender_name(payload), wiki_info.rstrip())
def get_watch_body(payload: Dict[str, Any]) -> str: def get_watch_body(payload: Dict[str, Any]) -> str:
return u"{} starred [the repository]({})".format( return u"{} starred [the repository]({}).".format(
get_sender_name(payload), get_sender_name(payload),
payload['repository']['html_url'] payload['repository']['html_url']
) )
def get_repository_body(payload: Dict[str, Any]) -> str: def get_repository_body(payload: Dict[str, Any]) -> str:
return u"{} {} [the repository]({})".format( return u"{} {} [the repository]({}).".format(
get_sender_name(payload), get_sender_name(payload),
payload.get('action'), payload.get('action'),
payload['repository']['html_url'] payload['repository']['html_url']
) )
def get_add_team_body(payload: Dict[str, Any]) -> str: def get_add_team_body(payload: Dict[str, Any]) -> str:
return u"[The repository]({}) was added to team {}".format( return u"[The repository]({}) was added to team {}.".format(
payload['repository']['html_url'], payload['repository']['html_url'],
payload['team']['name'] payload['team']['name']
) )
def get_release_body(payload: Dict[str, Any]) -> str: def get_release_body(payload: Dict[str, Any]) -> str:
return u"{} published [the release]({})".format( return u"{} published [the release]({}).".format(
get_sender_name(payload), get_sender_name(payload),
payload['release']['html_url'], payload['release']['html_url'],
) )
@@ -252,7 +252,7 @@ def get_page_build_body(payload: Dict[str, Any]) -> str:
CONTENT_MESSAGE_TEMPLATE.format(message=build['error']['message']) CONTENT_MESSAGE_TEMPLATE.format(message=build['error']['message'])
) )
return u"Github Pages build, trigerred by {}, {}".format( return u"Github Pages build, trigerred by {}, {}.".format(
payload['build']['pusher']['login'], payload['build']['pusher']['login'],
action action
) )
@@ -265,7 +265,7 @@ def get_status_body(payload: Dict[str, Any]) -> str:
) )
else: else:
status = payload['state'] status = payload['state']
return u"[{}]({}) changed its status to {}".format( return u"[{}]({}) changed its status to {}.".format(
payload['sha'][:7], # TODO payload['sha'][:7], # TODO
payload['commit']['html_url'], payload['commit']['html_url'],
status status