From 7eb4019ae88be7d091e21aaee412821d57b93149 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Fri, 15 Nov 2013 16:38:25 +0900 Subject: Add support for CurrentPatchSet The "currentPatchset" field of the query results includes information about the review label scores. Change-Id: I41d54225284e15b2b61b79bfaa309cd5c2b4b86a --- pygerrit/models.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pygerrit/models.py b/pygerrit/models.py index 31f7cca..9b764c1 100644 --- a/pygerrit/models.py +++ b/pygerrit/models.py @@ -67,6 +67,7 @@ class Change(object): self.owner = Account.from_json(json_data, "owner") self.sortkey = from_json(json_data, "sortKey") self.status = from_json(json_data, "status") + self.current_patchset = CurrentPatchset.from_json(json_data) def __repr__(self): return u"" % (self.number, self.project, self.branch) @@ -98,6 +99,35 @@ class Patchset(object): return None +class CurrentPatchset(Patchset): + + """ Gerrit current patch set. """ + + def __init__(self, json_data): + super(CurrentPatchset, self).__init__(json_data) + self.author = Account.from_json(json_data, "author") + self.approvals = [] + if "approvals" in json_data: + for approval in json_data["approvals"]: + self.approvals.append(Approval(approval)) + + def __repr__(self): + return u"" % (self.number, self.revision) + + @staticmethod + def from_json(json_data): + r""" Create a CurrentPatchset instance. + + Return an instance of CurrentPatchset initialised with values from + "currentPatchSet" in `json_data`, or None if `json_data` does not + contain "currentPatchSet". + + """ + if "currentPatchSet" in json_data: + return CurrentPatchset(json_data["currentPatchSet"]) + return None + + class Approval(object): """ Gerrit approval (verified, code review, etc). """ -- cgit v1.2.1