diff --git a/readthedocs/core/views/hooks.py b/readthedocs/core/views/hooks.py index a99f66c1169..9140c45a59c 100644 --- a/readthedocs/core/views/hooks.py +++ b/readthedocs/core/views/hooks.py @@ -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) diff --git a/readthedocs/restapi/views/integrations.py b/readthedocs/restapi/views/integrations.py index 80699a1c196..ddc226cf472 100644 --- a/readthedocs/restapi/views/integrations.py +++ b/readthedocs/restapi/views/integrations.py @@ -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') diff --git a/readthedocs/rtd_tests/tests/test_api.py b/readthedocs/rtd_tests/tests/test_api.py index 75e2a7e1f34..219417c9a20 100644 --- a/readthedocs/rtd_tests/tests/test_api.py +++ b/readthedocs/rtd_tests/tests/test_api.py @@ -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()