diff --git a/bot/code_review_bot/report/backend.py b/bot/code_review_bot/report/backend.py index 9547d3875..fcb23eadc 100644 --- a/bot/code_review_bot/report/backend.py +++ b/bot/code_review_bot/report/backend.py @@ -38,7 +38,7 @@ def publish(self, issues, revision): "id": revision.id, "phid": revision.phid, "title": revision.title, - "bugzilla_id": int(revision.bugzilla_id), + "bugzilla_id": revision.bugzilla_id, "repository": revision.target_repository, } backend_revision = self.create("/v1/revision/", data) @@ -80,6 +80,8 @@ def create(self, url_path, data): response = requests.post( url_post, json=data, auth=(self.username, self.password) ) + if not response.ok: + logger.warn("Backend rejected the payload: {}".format(response.content)) response.raise_for_status() out = response.json() logger.info("Created item on backend", url=url_post, id=out["id"]) diff --git a/bot/code_review_bot/revisions.py b/bot/code_review_bot/revisions.py index 05fa7a036..a6a3f9098 100644 --- a/bot/code_review_bot/revisions.py +++ b/bot/code_review_bot/revisions.py @@ -348,7 +348,11 @@ def is_decision_task(task): @property def bugzilla_id(self): - return self.revision["fields"].get("bugzilla.bug-id") + try: + return int(self.revision["fields"].get("bugzilla.bug-id")) + except ValueError: + logger.info("No bugzilla id available for this revision") + return None @property def title(self): diff --git a/bot/tests/test_reporter_backend.py b/bot/tests/test_reporter_backend.py index 46585b4a5..f7ee24217 100644 --- a/bot/tests/test_reporter_backend.py +++ b/bot/tests/test_reporter_backend.py @@ -19,6 +19,8 @@ def test_publication(mock_coverity_issues, mock_revision, mock_backend, mock_hgm mock_revision.target_repository = "test" mock_revision.mercurial_revision = "deadbeef1234" + assert mock_revision.bugzilla_id == 1234567 + configuration = { "url": "http://code-review-backend.test", "username": "tester", @@ -89,3 +91,42 @@ def test_publication(mock_coverity_issues, mock_revision, mock_backend, mock_hgm "validates": False, }, ] + + +def test_missing_bugzilla_id( + mock_coverity_issues, mock_revision, mock_backend, mock_hgmo +): + """ + Test revision creation on the backend without a bugzilla id (None instead) + """ + # Nothing in backend at first + revisions, diffs, issues = mock_backend + assert not revisions and not diffs and not issues + + # Hardcode revision & repo + mock_revision.repository = "test-try" + mock_revision.target_repository = "test" + mock_revision.mercurial_revision = "deadbeef1234" + + # Set bugzilla id as empty string + mock_revision.revision["fields"]["bugzilla.bug-id"] = "" + assert mock_revision.bugzilla_id is None + + configuration = { + "url": "http://code-review-backend.test", + "username": "tester", + "password": "test1234", + } + + r = BackendReporter(configuration) + r.publish(mock_coverity_issues, mock_revision) + + assert len(revisions) == 1 + assert 51 in revisions + assert revisions[51] == { + "bugzilla_id": None, + "id": 51, + "phid": "PHID-DREV-zzzzz", + "repository": "test", + "title": "Static Analysis tests", + } diff --git a/bot/tests/test_reporter_debug.py b/bot/tests/test_reporter_debug.py index aa8ba5442..dab921e19 100644 --- a/bot/tests/test_reporter_debug.py +++ b/bot/tests/test_reporter_debug.py @@ -50,7 +50,7 @@ def test_publication(tmpdir, mock_issues, mock_revision): "id": 51, "diff_id": 42, "url": "https://phabricator.test/D51", - "bugzilla_id": "1234567", + "bugzilla_id": 1234567, "diff_phid": "PHID-DIFF-test", "phid": "PHID-DREV-zzzzz", "title": "Static Analysis tests",