Skip to content

Commit

Permalink
Check to make sure changes exist in BitBucket pushes (#3480)
Browse files Browse the repository at this point in the history
* Check to make sure changes exist in BitBucket pushes

* Add test

* Define return values outside variable execution
  • Loading branch information
ericholscher authored and agjohnson committed Jan 15, 2018
1 parent 735d630 commit bb3deae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions readthedocs/core/views/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def build_branches(project, branch_list):
to_build - a list of branches that were built
not_building - a list of branches that we won't build
"""
to_build = set()
not_building = set()
for branch in branch_list:
versions = project.versions_from_branch_name(branch)
to_build = set()
not_building = set()
for version in versions:
log.info("(Branch Build) Processing %s:%s",
project.slug, version.slug)
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/restapi/views/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ def handle_webhook(self):
try:
changes = self.request.data['push']['changes']
branches = [change['new']['name']
for change in changes]
for change in changes
if change.get('new')]
return self.get_response_push(self.project, branches)
except KeyError:
raise ParseError('Invalid request')
Expand Down
16 changes: 16 additions & 0 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,22 @@ def test_bitbucket_webhook(self, trigger_build):
trigger_build.assert_has_calls(
[mock.call(force=True, version=mock.ANY, project=self.project)])

client.post(
'/api/v2/webhook/bitbucket/{0}/'.format(self.project.slug),
{
'push': {
'changes': [
{
'new': None,
},
],
},
},
format='json',
)
trigger_build.assert_not_called(
[mock.call(force=True, version=mock.ANY, project=self.project)])

def test_bitbucket_invalid_webhook(self, trigger_build):
"""Bitbucket webhook unhandled event."""
client = APIClient()
Expand Down

0 comments on commit bb3deae

Please sign in to comment.