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:
Eeshan Garg
2017-11-26 20:33:52 -03:30
committed by Tim Abbott
parent 2210f627a5
commit 5b8f38f4e3
3 changed files with 89 additions and 0 deletions

View File

@@ -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}"
}
}

View File

@@ -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)

View File

@@ -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: