Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bot/code_review_bot/report/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"])
Expand Down
6 changes: 5 additions & 1 deletion bot/code_review_bot/revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
41 changes: 41 additions & 0 deletions bot/tests/test_reporter_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
}
2 changes: 1 addition & 1 deletion bot/tests/test_reporter_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down