From ecd2abe3a491c2d4f2d9a4774d044793f2e1154d Mon Sep 17 00:00:00 2001 From: Zeid Zabaneh Date: Tue, 9 May 2023 12:21:16 -0400 Subject: [PATCH] add compatibility field for landing path --- landoapi/models/landing_job.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/landoapi/models/landing_job.py b/landoapi/models/landing_job.py index 503a992a..b53d2956 100644 --- a/landoapi/models/landing_job.py +++ b/landoapi/models/landing_job.py @@ -137,6 +137,23 @@ class LandingJob(Base): def landing_path(self) -> list[tuple[int, int]]: return [(revision.revision_id, revision.diff_id) for revision in self.revisions] + @property + def landing_path_compat(self): + """Return landing path based on associated revisions or legacy fields.""" + if self.revisions: + return [ + { + "revision_id": "D{}".format(revision_id), + "diff_id": diff_id, + } + for revision_id, diff_id in self.landing_path + ] + else: + return [ + {"revision_id": "D{}".format(r), "diff_id": self.revision_to_diff_id[r]} + for r in self.revision_order + ] + @property def head_revision(self) -> str: """Human-readable representation of the branch head's Phabricator revision ID.""" @@ -313,13 +330,7 @@ def serialize(self) -> dict[str, Any]: return { "id": self.id, "status": self.status.value, - "landing_path": [ - { - "revision_id": "D{}".format(revision.revision_id), - "diff_id": revision.diff_id, - } - for revision in self.revisions - ], + "landing_path": self.landing_path_compat, "error_breakdown": self.error_breakdown, "details": ( self.error or self.landed_commit_id