summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-09-22 14:36:49 +0000
committerGerrit Code Review <review@openstack.org>2020-09-22 14:36:49 +0000
commitefb7ca509a58d1ffb616425bf26178b4fbb8b9c2 (patch)
tree7baa8f82550dbdc608e79ef30ecd91f54ba15fb0
parentca157fd969a97e57134a1b0cd35efc9774064da4 (diff)
parent2be96e7a8558910633bd653e2e167e7767c5903e (diff)
downloadzuul-efb7ca509a58d1ffb616425bf26178b4fbb8b9c2.tar.gz
Merge "Add commit id and owner to Change for mqtt reporter"
-rw-r--r--doc/source/reference/drivers/mqtt.rst16
-rw-r--r--tests/base.py9
-rw-r--r--tests/fakegithub.py3
-rw-r--r--tests/unit/test_connection.py2
-rw-r--r--zuul/driver/gerrit/gerritmodel.py9
-rw-r--r--zuul/driver/github/githubconnection.py3
-rw-r--r--zuul/driver/gitlab/gitlabconnection.py2
-rw-r--r--zuul/driver/mqtt/mqttreporter.py2
-rw-r--r--zuul/model.py3
9 files changed, 42 insertions, 7 deletions
diff --git a/doc/source/reference/drivers/mqtt.rst b/doc/source/reference/drivers/mqtt.rst
index 8aa0911dc..421c7112c 100644
--- a/doc/source/reference/drivers/mqtt.rst
+++ b/doc/source/reference/drivers/mqtt.rst
@@ -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
diff --git a/tests/base.py b/tests/base.py
index b1343a9fb..57349f5ab 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -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"
diff --git a/tests/fakegithub.py b/tests/fakegithub.py
index 89b3ec73a..4a5bc42c1 100644
--- a/tests/fakegithub.py
+++ b/tests/fakegithub.py
@@ -543,6 +543,9 @@ class FakePull(object):
},
'ref': pr.branch,
},
+ 'user': {
+ 'login': 'octocat'
+ },
'draft': pr.draft,
'mergeable': True,
'state': pr.state,
diff --git a/tests/unit/test_connection.py b/tests/unit/test_connection.py
index f64de8c7c..ebabb6a0b 100644
--- a/tests/unit/test_connection.py
+++ b/tests/unit/test_connection.py
@@ -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'],
diff --git a/zuul/driver/gerrit/gerritmodel.py b/zuul/driver/gerrit/gerritmodel.py
index e9043119f..98ca19895 100644
--- a/zuul/driver/gerrit/gerritmodel.py
+++ b/zuul/driver/gerrit/gerritmodel.py
@@ -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']
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 0c72b0564..cb977ee98 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -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.
diff --git a/zuul/driver/gitlab/gitlabconnection.py b/zuul/driver/gitlab/gitlabconnection.py
index 90308ba62..0a946c6d2 100644
--- a/zuul/driver/gitlab/gitlabconnection.py
+++ b/zuul/driver/gitlab/gitlabconnection.py
@@ -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
diff --git a/zuul/driver/mqtt/mqttreporter.py b/zuul/driver/mqtt/mqttreporter.py
index 88dd70738..e489f5908 100644
--- a/zuul/driver/mqtt/mqttreporter.py
+++ b/zuul/driver/mqtt/mqttreporter.py
@@ -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),
diff --git a/zuul/model.py b/zuul/model.py
index ecf5c62fa..1b887df0d 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -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)