mirror of https://github.com/zulip/zulip.git
webhooks/github*: Support pushing a local branch without commits.
Changes made to get_push_commits_event_message in zerver/lib/webhooks/git.py are common to all Git integrations that use get_push_commits_event_message. These include github, github_webhook, gitlab, gogs, bitbucket, bitbucket2. In some cases (for instance, gitlab), no further changes to gitlab/view.py will be required to support pushing a local branch without commits; adding a fixture and tests should suffice.
This commit is contained in:
parent
7a545eeb13
commit
5687b2cdc5
|
@ -21,6 +21,7 @@ PUSH_COMMITS_MESSAGE_TEMPLATE_WITHOUT_COMMITTERS = u"""{user_name} {pushed_text}
|
||||||
{commits_data}
|
{commits_data}
|
||||||
"""
|
"""
|
||||||
PUSH_DELETE_BRANCH_MESSAGE_TEMPLATE = u"{user_name} [deleted]({compare_url}) the branch {branch_name}."
|
PUSH_DELETE_BRANCH_MESSAGE_TEMPLATE = u"{user_name} [deleted]({compare_url}) the branch {branch_name}."
|
||||||
|
PUSH_LOCAL_BRANCH_WITHOUT_COMMITS_MESSAGE_TEMPLATE = u"{user_name} [pushed]({compare_url}) the branch {branch_name}."
|
||||||
PUSH_COMMITS_MESSAGE_EXTENSION = u"Commits by {}"
|
PUSH_COMMITS_MESSAGE_EXTENSION = u"Commits by {}"
|
||||||
PUSH_COMMITTERS_LIMIT_INFO = 3
|
PUSH_COMMITTERS_LIMIT_INFO = 3
|
||||||
|
|
||||||
|
@ -53,6 +54,13 @@ def get_push_commits_event_message(user_name, compare_url, branch_name, commits_
|
||||||
branch_name=branch_name
|
branch_name=branch_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not commits_data and not deleted:
|
||||||
|
return PUSH_LOCAL_BRANCH_WITHOUT_COMMITS_MESSAGE_TEMPLATE.format(
|
||||||
|
user_name=user_name,
|
||||||
|
compare_url=compare_url,
|
||||||
|
branch_name=branch_name
|
||||||
|
)
|
||||||
|
|
||||||
pushed_message_template = PUSH_PUSHED_TEXT_WITH_URL if compare_url else PUSH_PUSHED_TEXT_WITHOUT_URL
|
pushed_message_template = PUSH_PUSHED_TEXT_WITH_URL if compare_url else PUSH_PUSHED_TEXT_WITHOUT_URL
|
||||||
|
|
||||||
pushed_text_message = pushed_message_template.format(
|
pushed_text_message = pushed_message_template.format(
|
||||||
|
|
|
@ -0,0 +1,155 @@
|
||||||
|
{
|
||||||
|
"ref":"refs/heads/feature",
|
||||||
|
"before":"0000000000000000000000000000000000000000",
|
||||||
|
"after":"2e8cf535fb38a3dab2476cdf856efda904ad4c94",
|
||||||
|
"created":true,
|
||||||
|
"deleted":false,
|
||||||
|
"forced":false,
|
||||||
|
"base_ref":"refs/heads/changes",
|
||||||
|
"compare":"https://github.com/eeshangarg/public-repo/compare/feature",
|
||||||
|
"commits":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"head_commit":{
|
||||||
|
"id":"2e8cf535fb38a3dab2476cdf856efda904ad4c94",
|
||||||
|
"tree_id":"09303be712bd8e923f9b227c8522257fa32ca7dc",
|
||||||
|
"distinct":true,
|
||||||
|
"message":"Update the README",
|
||||||
|
"timestamp":"2017-04-29T14:31:31-02:30",
|
||||||
|
"url":"https://github.com/eeshangarg/public-repo/commit/2e8cf535fb38a3dab2476cdf856efda904ad4c94",
|
||||||
|
"author":{
|
||||||
|
"name":"John Snow",
|
||||||
|
"email":"johnsnow@got.com"
|
||||||
|
},
|
||||||
|
"committer":{
|
||||||
|
"name":"Eeshan Garg",
|
||||||
|
"email":"jerryguitarist@gmail.com",
|
||||||
|
"username":"eeshangarg"
|
||||||
|
},
|
||||||
|
"added":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"removed":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"modified":[
|
||||||
|
"README.md"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"repository":{
|
||||||
|
"id":89799239,
|
||||||
|
"name":"public-repo",
|
||||||
|
"full_name":"eeshangarg/public-repo",
|
||||||
|
"owner":{
|
||||||
|
"name":"eeshangarg",
|
||||||
|
"email":"jerryguitarist@gmail.com",
|
||||||
|
"login":"eeshangarg",
|
||||||
|
"id":7251823,
|
||||||
|
"avatar_url":"https://avatars3.githubusercontent.com/u/7251823?v=3",
|
||||||
|
"gravatar_id":"",
|
||||||
|
"url":"https://api.github.com/users/eeshangarg",
|
||||||
|
"html_url":"https://github.com/eeshangarg",
|
||||||
|
"followers_url":"https://api.github.com/users/eeshangarg/followers",
|
||||||
|
"following_url":"https://api.github.com/users/eeshangarg/following{/other_user}",
|
||||||
|
"gists_url":"https://api.github.com/users/eeshangarg/gists{/gist_id}",
|
||||||
|
"starred_url":"https://api.github.com/users/eeshangarg/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url":"https://api.github.com/users/eeshangarg/subscriptions",
|
||||||
|
"organizations_url":"https://api.github.com/users/eeshangarg/orgs",
|
||||||
|
"repos_url":"https://api.github.com/users/eeshangarg/repos",
|
||||||
|
"events_url":"https://api.github.com/users/eeshangarg/events{/privacy}",
|
||||||
|
"received_events_url":"https://api.github.com/users/eeshangarg/received_events",
|
||||||
|
"type":"User",
|
||||||
|
"site_admin":false
|
||||||
|
},
|
||||||
|
"private":false,
|
||||||
|
"html_url":"https://github.com/eeshangarg/public-repo",
|
||||||
|
"description":null,
|
||||||
|
"fork":false,
|
||||||
|
"url":"https://github.com/eeshangarg/public-repo",
|
||||||
|
"forks_url":"https://api.github.com/repos/eeshangarg/public-repo/forks",
|
||||||
|
"keys_url":"https://api.github.com/repos/eeshangarg/public-repo/keys{/key_id}",
|
||||||
|
"collaborators_url":"https://api.github.com/repos/eeshangarg/public-repo/collaborators{/collaborator}",
|
||||||
|
"teams_url":"https://api.github.com/repos/eeshangarg/public-repo/teams",
|
||||||
|
"hooks_url":"https://api.github.com/repos/eeshangarg/public-repo/hooks",
|
||||||
|
"issue_events_url":"https://api.github.com/repos/eeshangarg/public-repo/issues/events{/number}",
|
||||||
|
"events_url":"https://api.github.com/repos/eeshangarg/public-repo/events",
|
||||||
|
"assignees_url":"https://api.github.com/repos/eeshangarg/public-repo/assignees{/user}",
|
||||||
|
"branches_url":"https://api.github.com/repos/eeshangarg/public-repo/branches{/branch}",
|
||||||
|
"tags_url":"https://api.github.com/repos/eeshangarg/public-repo/tags",
|
||||||
|
"blobs_url":"https://api.github.com/repos/eeshangarg/public-repo/git/blobs{/sha}",
|
||||||
|
"git_tags_url":"https://api.github.com/repos/eeshangarg/public-repo/git/tags{/sha}",
|
||||||
|
"git_refs_url":"https://api.github.com/repos/eeshangarg/public-repo/git/refs{/sha}",
|
||||||
|
"trees_url":"https://api.github.com/repos/eeshangarg/public-repo/git/trees{/sha}",
|
||||||
|
"statuses_url":"https://api.github.com/repos/eeshangarg/public-repo/statuses/{sha}",
|
||||||
|
"languages_url":"https://api.github.com/repos/eeshangarg/public-repo/languages",
|
||||||
|
"stargazers_url":"https://api.github.com/repos/eeshangarg/public-repo/stargazers",
|
||||||
|
"contributors_url":"https://api.github.com/repos/eeshangarg/public-repo/contributors",
|
||||||
|
"subscribers_url":"https://api.github.com/repos/eeshangarg/public-repo/subscribers",
|
||||||
|
"subscription_url":"https://api.github.com/repos/eeshangarg/public-repo/subscription",
|
||||||
|
"commits_url":"https://api.github.com/repos/eeshangarg/public-repo/commits{/sha}",
|
||||||
|
"git_commits_url":"https://api.github.com/repos/eeshangarg/public-repo/git/commits{/sha}",
|
||||||
|
"comments_url":"https://api.github.com/repos/eeshangarg/public-repo/comments{/number}",
|
||||||
|
"issue_comment_url":"https://api.github.com/repos/eeshangarg/public-repo/issues/comments{/number}",
|
||||||
|
"contents_url":"https://api.github.com/repos/eeshangarg/public-repo/contents/{+path}",
|
||||||
|
"compare_url":"https://api.github.com/repos/eeshangarg/public-repo/compare/{base}...{head}",
|
||||||
|
"merges_url":"https://api.github.com/repos/eeshangarg/public-repo/merges",
|
||||||
|
"archive_url":"https://api.github.com/repos/eeshangarg/public-repo/{archive_format}{/ref}",
|
||||||
|
"downloads_url":"https://api.github.com/repos/eeshangarg/public-repo/downloads",
|
||||||
|
"issues_url":"https://api.github.com/repos/eeshangarg/public-repo/issues{/number}",
|
||||||
|
"pulls_url":"https://api.github.com/repos/eeshangarg/public-repo/pulls{/number}",
|
||||||
|
"milestones_url":"https://api.github.com/repos/eeshangarg/public-repo/milestones{/number}",
|
||||||
|
"notifications_url":"https://api.github.com/repos/eeshangarg/public-repo/notifications{?since,all,participating}",
|
||||||
|
"labels_url":"https://api.github.com/repos/eeshangarg/public-repo/labels{/name}",
|
||||||
|
"releases_url":"https://api.github.com/repos/eeshangarg/public-repo/releases{/id}",
|
||||||
|
"deployments_url":"https://api.github.com/repos/eeshangarg/public-repo/deployments",
|
||||||
|
"created_at":1493484776,
|
||||||
|
"updated_at":"2017-04-29T16:52:56Z",
|
||||||
|
"pushed_at":1494977751,
|
||||||
|
"git_url":"git://github.com/eeshangarg/public-repo.git",
|
||||||
|
"ssh_url":"git@github.com:eeshangarg/public-repo.git",
|
||||||
|
"clone_url":"https://github.com/eeshangarg/public-repo.git",
|
||||||
|
"svn_url":"https://github.com/eeshangarg/public-repo",
|
||||||
|
"homepage":null,
|
||||||
|
"size":0,
|
||||||
|
"stargazers_count":0,
|
||||||
|
"watchers_count":0,
|
||||||
|
"language":null,
|
||||||
|
"has_issues":true,
|
||||||
|
"has_projects":true,
|
||||||
|
"has_downloads":true,
|
||||||
|
"has_wiki":true,
|
||||||
|
"has_pages":false,
|
||||||
|
"forks_count":0,
|
||||||
|
"mirror_url":null,
|
||||||
|
"open_issues_count":0,
|
||||||
|
"forks":0,
|
||||||
|
"open_issues":0,
|
||||||
|
"watchers":0,
|
||||||
|
"default_branch":"changes",
|
||||||
|
"stargazers":0,
|
||||||
|
"master_branch":"changes"
|
||||||
|
},
|
||||||
|
"pusher":{
|
||||||
|
"name":"eeshangarg",
|
||||||
|
"email":"jerryguitarist@gmail.com"
|
||||||
|
},
|
||||||
|
"sender":{
|
||||||
|
"login":"eeshangarg",
|
||||||
|
"id":7251823,
|
||||||
|
"avatar_url":"https://avatars3.githubusercontent.com/u/7251823?v=3",
|
||||||
|
"gravatar_id":"",
|
||||||
|
"url":"https://api.github.com/users/eeshangarg",
|
||||||
|
"html_url":"https://github.com/eeshangarg",
|
||||||
|
"followers_url":"https://api.github.com/users/eeshangarg/followers",
|
||||||
|
"following_url":"https://api.github.com/users/eeshangarg/following{/other_user}",
|
||||||
|
"gists_url":"https://api.github.com/users/eeshangarg/gists{/gist_id}",
|
||||||
|
"starred_url":"https://api.github.com/users/eeshangarg/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url":"https://api.github.com/users/eeshangarg/subscriptions",
|
||||||
|
"organizations_url":"https://api.github.com/users/eeshangarg/orgs",
|
||||||
|
"repos_url":"https://api.github.com/users/eeshangarg/repos",
|
||||||
|
"events_url":"https://api.github.com/users/eeshangarg/events{/privacy}",
|
||||||
|
"received_events_url":"https://api.github.com/users/eeshangarg/received_events",
|
||||||
|
"type":"User",
|
||||||
|
"site_admin":false
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,11 @@ class GithubWebhookTest(WebhookTestCase):
|
||||||
expected_message = u"eeshangarg [deleted](https://github.com/eeshangarg/public-repo/compare/2e8cf535fb38...000000000000) the branch feature."
|
expected_message = u"eeshangarg [deleted](https://github.com/eeshangarg/public-repo/compare/2e8cf535fb38...000000000000) the branch feature."
|
||||||
self.send_and_test_stream_message('push_delete_branch', u"public-repo / feature", expected_message, HTTP_X_GITHUB_EVENT='push')
|
self.send_and_test_stream_message('push_delete_branch', u"public-repo / feature", expected_message, HTTP_X_GITHUB_EVENT='push')
|
||||||
|
|
||||||
|
def test_push_local_branch_without_commits(self):
|
||||||
|
# type: () -> None
|
||||||
|
expected_message = u"eeshangarg [pushed](https://github.com/eeshangarg/public-repo/compare/feature) the branch feature."
|
||||||
|
self.send_and_test_stream_message('push_local_branch_without_commits', u"public-repo / feature", expected_message, HTTP_X_GITHUB_EVENT='push')
|
||||||
|
|
||||||
def test_push_1_commit(self):
|
def test_push_1_commit(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
expected_message = u"baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 1 commit to branch changes.\n\n* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))"
|
expected_message = u"baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 1 commit to branch changes.\n\n* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))"
|
||||||
|
|
Loading…
Reference in New Issue