Skip to content

Commit bb3deae

Browse files
ericholscheragjohnson
authored andcommitted
Check to make sure changes exist in BitBucket pushes (#3480)
* Check to make sure changes exist in BitBucket pushes * Add test * Define return values outside variable execution
1 parent 735d630 commit bb3deae

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

readthedocs/core/views/hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def build_branches(project, branch_list):
7474
to_build - a list of branches that were built
7575
not_building - a list of branches that we won't build
7676
"""
77+
to_build = set()
78+
not_building = set()
7779
for branch in branch_list:
7880
versions = project.versions_from_branch_name(branch)
79-
to_build = set()
80-
not_building = set()
8181
for version in versions:
8282
log.info("(Branch Build) Processing %s:%s",
8383
project.slug, version.slug)

readthedocs/restapi/views/integrations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ def handle_webhook(self):
233233
try:
234234
changes = self.request.data['push']['changes']
235235
branches = [change['new']['name']
236-
for change in changes]
236+
for change in changes
237+
if change.get('new')]
237238
return self.get_response_push(self.project, branches)
238239
except KeyError:
239240
raise ParseError('Invalid request')

readthedocs/rtd_tests/tests/test_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,22 @@ def test_bitbucket_webhook(self, trigger_build):
429429
trigger_build.assert_has_calls(
430430
[mock.call(force=True, version=mock.ANY, project=self.project)])
431431

432+
client.post(
433+
'/api/v2/webhook/bitbucket/{0}/'.format(self.project.slug),
434+
{
435+
'push': {
436+
'changes': [
437+
{
438+
'new': None,
439+
},
440+
],
441+
},
442+
},
443+
format='json',
444+
)
445+
trigger_build.assert_not_called(
446+
[mock.call(force=True, version=mock.ANY, project=self.project)])
447+
432448
def test_bitbucket_invalid_webhook(self, trigger_build):
433449
"""Bitbucket webhook unhandled event."""
434450
client = APIClient()

0 commit comments

Comments
 (0)