mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
webhooks/bitbucket2: Ignore push events with no changes.
We now ignore payloads where payload['push']['changes'] is empty, because an empty push doesn't really convey any useful information. I couldn't find a way to replicate the action that would generate such a payload, so I took one of our existing payloads and editted out payload['push']['changes'] myself, so this payload is not authentic.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"push":{
|
||||
"changes":[
|
||||
|
||||
]
|
||||
},
|
||||
"actor":{
|
||||
"username":"eeshangarg",
|
||||
"type":"user",
|
||||
"display_name":"eeshangarg",
|
||||
"uuid":"{a161e482-30e8-47ef-b6ab-c4e4cfaa0dce}",
|
||||
"links":{
|
||||
"self":{
|
||||
"href":"https://api.bitbucket.org/2.0/users/eeshangarg"
|
||||
},
|
||||
"html":{
|
||||
"href":"https://bitbucket.org/eeshangarg/"
|
||||
},
|
||||
"avatar":{
|
||||
"href":"https://bitbucket.org/account/eeshangarg/avatar/32/"
|
||||
}
|
||||
}
|
||||
},
|
||||
"repository":{
|
||||
"scm":"git",
|
||||
"website":"",
|
||||
"name":"test-repo",
|
||||
"links":{
|
||||
"self":{
|
||||
"href":"https://api.bitbucket.org/2.0/repositories/webhooktest/test-repo"
|
||||
},
|
||||
"html":{
|
||||
"href":"https://bitbucket.org/webhooktest/test-repo"
|
||||
},
|
||||
"avatar":{
|
||||
"href":"https://bitbucket.org/webhooktest/test-repo/avatar/32/"
|
||||
}
|
||||
},
|
||||
"project":{
|
||||
"links":{
|
||||
"self":{
|
||||
"href":"https://api.bitbucket.org/2.0/teams/webhooktest/projects/TES"
|
||||
},
|
||||
"html":{
|
||||
"href":"https://bitbucket.org/account/user/webhooktest/projects/TES"
|
||||
},
|
||||
"avatar":{
|
||||
"href":"https://bitbucket.org/account/user/webhooktest/projects/TES/avatar/32"
|
||||
}
|
||||
},
|
||||
"type":"project",
|
||||
"uuid":"{c9b1f7ee-1949-4f6e-ba2b-6333fdbe6bf6}",
|
||||
"key":"TES",
|
||||
"name":"test-project"
|
||||
},
|
||||
"full_name":"webhooktest/test-repo",
|
||||
"owner":{
|
||||
"username":"webhooktest",
|
||||
"type":"team",
|
||||
"display_name":"webhooktest",
|
||||
"uuid":"{31358906-183f-4b53-b83c-f70ba0ca5d3c}",
|
||||
"links":{
|
||||
"self":{
|
||||
"href":"https://api.bitbucket.org/2.0/teams/webhooktest"
|
||||
},
|
||||
"html":{
|
||||
"href":"https://bitbucket.org/webhooktest/"
|
||||
},
|
||||
"avatar":{
|
||||
"href":"https://bitbucket.org/account/webhooktest/avatar/32/"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type":"repository",
|
||||
"is_private":true,
|
||||
"uuid":"{79e5af61-a749-45c5-be24-ba1cba7b662e}"
|
||||
}
|
||||
}
|
||||
@@ -273,3 +273,11 @@ class Bitbucket2HookTests(WebhookTestCase):
|
||||
result = self.client_post(self.url, payload, content_type="application/json")
|
||||
self.assertFalse(check_send_stream_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
|
||||
@patch('zerver.webhooks.bitbucket2.view.check_send_stream_message')
|
||||
def test_bitbucket2_on_push_without_changes_ignore(self, check_send_stream_message_mock):
|
||||
# type: (MagicMock) -> None
|
||||
payload = self.get_body('push_without_changes')
|
||||
result = self.client_post(self.url, payload, content_type="application/json")
|
||||
self.assertFalse(check_send_stream_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
|
||||
@@ -54,6 +54,9 @@ def api_bitbucket2_webhook(request, user_profile, payload=REQ(argument_type='bod
|
||||
check_send_stream_message(user_profile, request.client,
|
||||
stream, subject, body)
|
||||
else:
|
||||
# ignore push events with no changes
|
||||
if not payload['push']['changes']:
|
||||
return json_success()
|
||||
branch = get_branch_name_for_push_event(payload)
|
||||
if branch and branches:
|
||||
if branches.find(branch) == -1:
|
||||
|
||||
Reference in New Issue
Block a user