Add commit id and owner to Change for mqtt reporter

Change-Id: I3d197996597c70165edbf2e26f621391c87873e6
This commit is contained in:
vass 2020-04-23 21:22:33 +02:00 committed by lliu82
parent cb27f37153
commit 2be96e7a85
9 changed files with 42 additions and 7 deletions

View File

@ -50,6 +50,14 @@ An MQTT report uses this schema:
The patchset number.
.. attr:: commit_id
The commit id number.
.. attr:: owner
The owner username of the change.
.. attr:: ref
The change reference.
@ -129,10 +137,12 @@ Here is an example of a start message:
'enqueue_time': '1524801093.5689457',
'change': '3',
'patchset': '1',
'commit_id': '2db20c7fb26adf9ac9936a9e750ced9b4854a964',
'owner': 'username',
'ref': 'refs/changes/03/3/1',
'zuul_ref': 'Zf8b3d7cd34f54cb396b488226589db8f',
'buildset': {
'uuid': 'f8b3d7cd34f54cb396b488226589db8f'
'uuid': 'f8b3d7cd34f54cb396b488226589db8f',
'builds': [{
'job_name': 'linters',
'voting': True
@ -157,10 +167,12 @@ Here is an example of a success message:
'enqueue_time': '1524801093.5689457',
'change': '3',
'patchset': '1',
'commit_id': '2db20c7fb26adf9ac9936a9e750ced9b4854a964',
'owner': 'username',
'ref': 'refs/changes/03/3/1',
'zuul_ref': 'Zf8b3d7cd34f54cb396b488226589db8f',
'buildset': {
'uuid': 'f8b3d7cd34f54cb396b488226589db8f'
'uuid': 'f8b3d7cd34f54cb396b488226589db8f',
'builds': [{
'job_name': 'linters',
'voting': True

View File

@ -1668,10 +1668,19 @@ class FakeGitlabAPIClient(gitlabconnection.GitlabAPIClient):
'title': mr.title,
'state': mr.state,
'description': mr.description,
'author': {
'name': 'Administrator',
'username': 'admin'
},
'updated_at': mr.updated_at.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
'sha': mr.sha,
'labels': mr.labels,
'merged_at': mr.merged_at,
'diff_refs': {
'base_sha': 'c380d3acebd181f13629a25d2e2acca46ffe1e00',
'head_sha': '2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f',
'start_sha': 'c380d3acebd181f13629a25d2e2acca46ffe1e00'
},
'merge_status': mr.merge_status,
}, 200, "", "GET"

View File

@ -543,6 +543,9 @@ class FakePull(object):
},
'ref': pr.branch,
},
'user': {
'login': 'octocat'
},
'draft': pr.draft,
'mergeable': True,
'state': pr.state,

View File

@ -555,6 +555,8 @@ class TestMQTTConnection(ZuulTestCase):
'tenant-one/zuul_start/check/org/project/master')
mqtt_payload = start_event['msg']
self.assertEquals(mqtt_payload['project'], 'org/project')
self.assertEqual(len(mqtt_payload['commit_id']), 40)
self.assertEquals(mqtt_payload['owner'], 'username')
self.assertEquals(mqtt_payload['branch'], 'master')
self.assertEquals(mqtt_payload['buildset']['result'], None)
self.assertEquals(mqtt_payload['buildset']['builds'][0]['job_name'],

View File

@ -45,7 +45,7 @@ class GerritChange(Change):
if 'project' not in data:
raise exceptions.ChangeNotFound(self.number, self.patchset)
self.project = connection.source.getProject(data['project'])
self.id = data['id']
self.commit_id = str(data['currentPatchSet']['revision'])
self.branch = data['branch']
self.url = data['url']
urlparse = urllib.parse.urlparse(connection.baseurl)
@ -73,12 +73,12 @@ class GerritChange(Change):
else:
self.is_current_patchset = False
self.files = files
self.id = data['id']
self.is_merged = data.get('status', '') == 'MERGED'
self.approvals = data['currentPatchSet'].get('approvals', [])
self.open = data['open']
self.status = data['status']
self.owner = data['owner']
self.owner = data['owner'].get('username')
self.message = data['commitMessage']
self.missing_labels = set()
@ -99,6 +99,7 @@ class GerritChange(Change):
if self.patchset is None:
self.patchset = str(current_revision['_number'])
self.project = connection.source.getProject(data['project'])
self.commit_id = str(data['current_revision'])
self.id = data['change_id']
self.branch = data['branch']
self.url = '%s/%s' % (baseurl, self.number)
@ -147,7 +148,7 @@ class GerritChange(Change):
self.missing_labels.add(label_name)
self.open = data['status'] == 'NEW'
self.status = data['status']
self.owner = data['owner']
self.owner = data['owner'].get('username')
self.message = current_revision['commit']['message']

View File

@ -1429,7 +1429,8 @@ class GithubConnection(BaseConnection):
change.project.name, change.number, event=event)
change.ref = "refs/pull/%s/head" % change.number
change.branch = change.pr.get('base').get('ref')
change.commit_id = change.pr.get('head').get('sha')
change.owner = change.pr.get('user').get('login')
# Don't overwrite the files list. The change object is bound to a
# specific revision and thus the changed files won't change. This is
# important if we got the files later because of the 300 files limit.

View File

@ -519,6 +519,8 @@ class GitlabConnection(BaseConnection):
change.ref = "refs/merge-requests/%s/head" % change.number
change.branch = change.mr['target_branch']
change.patchset = change.mr['sha']
change.commit_id = change.mr['diff_refs'].get('head_sha')
change.owner = change.mr['author'].get('username')
# Files changes are not part of the Merge Request data
# See api/merge_requests.html#get-single-mr-changes
# this endpoint includes file changes information

View File

@ -40,6 +40,8 @@ class MQTTReporter(BaseReporter):
'change_url': item.change.url,
'change': getattr(item.change, 'number', ''),
'patchset': getattr(item.change, 'patchset', ''),
'commit_id': getattr(item.change, 'commit_id', ''),
'owner': getattr(item.change, 'owner', ''),
'ref': getattr(item.change, 'ref', ''),
'message': self._formatItemReport(
item, with_jobs=False),

View File

@ -3211,6 +3211,9 @@ class Change(Branch):
# in the case of a PR. Either way, it's the place where we
# look for depends-on headers.
self.message = None
# This can be the commit id of the patchset enqueued or
# in the case of a PR the id of HEAD of the branch.
self.commit_id = None
def _id(self):
return '%s,%s' % (self.number, self.patchset)