Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1153)

Unified Diff: dashboard/dashboard/pinpoint/models/change/patch.py

Issue 3019553002: [pinpoint] Gerrit patch support. (Closed)
Patch Set: Example URL Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: dashboard/dashboard/pinpoint/models/change/patch.py
diff --git a/dashboard/dashboard/pinpoint/models/change/patch.py b/dashboard/dashboard/pinpoint/models/change/patch.py
index 5907e19eb355fabeb36509e3a75b91ca6a3e58b3..a6bd218fef37f62e7f1f3c85c1d6cba026964d15 100644
--- a/dashboard/dashboard/pinpoint/models/change/patch.py
+++ b/dashboard/dashboard/pinpoint/models/change/patch.py
@@ -3,24 +3,95 @@
# found in the LICENSE file.
import collections
+import urlparse
+from dashboard.services import gerrit_service
-class Patch(collections.namedtuple('Patch', ('server', 'issue', 'patchset'))):
- """A patch in Rietveld."""
- # TODO: Support Gerrit.
- # https://github.com/catapult-project/catapult/issues/3599
+
+def FromDict(data):
+ # If we have more Patch types in the future, we can loop
+ # through them all and try each one's FromDict() in turn.
+ return GerritPatch.FromDict(data)
+
+
+class GerritPatch(collections.namedtuple(
+ 'GerritPatch', ('server', 'change', 'revision'))):
+ """A patch in Gerrit.
+
+ change is a change ID of the format '<project>~<branch>~<Change-Id>' and
+ revision is a commit ID. Both are described in the Gerrit API documentation.
+ https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#ids
+
+ They must be in a canonical format so we can look up builds precisely.
+ """
def __str__(self):
return self.id_string
@property
def id_string(self):
- return '%s/%d/%d' % (self.server, self.issue, self.patchset)
+ return '%s/%s/%s' % (self.server, self.change, self.revision)
+
+ def BuildParameters(self):
+ patch_info = gerrit_service.GetChange(
+ self.server, self.change, fields=('ALL_REVISIONS',))
+ revision_info = patch_info['revisions'][self.revision]
+ return {
+ 'patch_gerrit_url': self.server,
+ 'patch_issue': patch_info['_number'],
+ 'patch_project': patch_info['project'],
+ 'patch_ref': revision_info['fetch']['http']['ref'],
+ 'patch_repository_url': revision_info['fetch']['http']['url'],
+ 'patch_set': revision_info['_number'],
+ 'patch_storage': 'gerrit',
+ }
def AsDict(self):
return self._asdict()
@classmethod
def FromDict(cls, data):
- # TODO: Validate to ensure the patch exists on the server.
- return cls(data['server'], data['issue'], data['patchset'])
+ """Creates a new GerritPatch from the given data.
+
+ Args:
+ data: A patch URL string, for example:
+ https://chromium-review.googlesource.com/c/chromium/tools/build/+/679595
+ Or a dict containing {server, change, revision [optional]}.
+ change is a {change-id} as described in the Gerrit API documentation.
+ revision is a commit ID hash or numeric patch number.
+ If revision is omitted, it is the change's current revision.
+
+ Returns:
+ A GerritPatch.
+
+ Raises:
+ KeyError: The patch doesn't have the given revision.
+ """
+ if isinstance(data, basestring):
+ url_parts = urlparse.urlparse(data)
+ server = urlparse.urlunsplit(
+ (url_parts.scheme, url_parts.netloc, '', '', ''))
+ change = url_parts.path.rsplit('/', 1)[-1]
+ revision = None
perezju 2017/09/26 09:15:47 how do we know to which repository should the patc
dtu 2017/09/26 20:00:23 As far as I can tell from the Gerrit doc, the nume
perezju 2017/09/27 08:21:47 Wow, had no idea. Ok, thanks for the explanation!
+ else:
+ server = data['server']
+ change = data['change']
+ revision = data.get('revision')
+
+ # Look up the patch and convert everything to a canonical format.
+ patch_info = gerrit_service.GetChange(
+ server, change, fields=('ALL_REVISIONS',))
+ change = patch_info['id']
+
+ # Revision can be a revision ID or numeric patch number.
+ if not revision:
+ revision = patch_info['current_revision']
+ for revision_id, revision_info in patch_info['revisions'].iteritems():
+ if revision == revision_id or revision == revision_info['_number']:
+ revision = revision_id
+ break
+ else:
+ raise KeyError('Patch revision not found: %s/%s revision %s' %
+ (server, change, revision))
+
+ return cls(server, change, revision)
« no previous file with comments | « dashboard/dashboard/pinpoint/models/change/change_test.py ('k') | dashboard/dashboard/pinpoint/models/change/patch_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698