From 9bf289729c321fb1769b004fd9a31b728073da7f Mon Sep 17 00:00:00 2001 From: Ahmon Dancy Date: Wed, 30 Aug 2023 12:05:14 -0700 Subject: [PATCH] Check MR sha instead of changes_count for stabilization check Followup to #35 Change-Id: I209472650081fc3b32181af41d9ddc30c344adb5 --- gerritlab/main.py | 7 +++++-- gerritlab/merge_request.py | 7 +++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gerritlab/main.py b/gerritlab/main.py index 6d66e11..854f900 100644 --- a/gerritlab/main.py +++ b/gerritlab/main.py @@ -82,6 +82,7 @@ def __init__(self, commit, source_branch, target_branch): self.commit = commit self.source_branch = source_branch self.target_branch = target_branch + self.mr = None # key is timer name, value is seconds counted timers = {} @@ -156,6 +157,7 @@ def create_merge_requests(repo, remote, local_branch): mr = current_mrs_by_source_branch.get(c.source_branch) if mr: + c.mr = mr # Update the MR if needed if mr.needs_update(c): with timing("update_mrs"): @@ -169,6 +171,7 @@ def create_merge_requests(repo, remote, local_branch): mr = merge_request.MergeRequest( remote=remote, source_branch=c.source_branch, target_branch=c.target_branch, title=title, description=desp) + c.mr = c with timing("create_mrs"): mr.create() new_mrs.append(mr) @@ -182,8 +185,8 @@ def create_merge_requests(repo, remote, local_branch): remote.push(refspec=refs_to_push, force=True) with timing("stabilize"): - for mr in new_mrs+updated_mrs: - mr.wait_until_stable() + for c in commits_data: + c.mr.wait_until_stable(c) if len(updated_mrs) == 0 and len(new_mrs) == 0: print() diff --git a/gerritlab/merge_request.py b/gerritlab/merge_request.py index b8c797c..1043d67 100644 --- a/gerritlab/merge_request.py +++ b/gerritlab/merge_request.py @@ -168,14 +168,13 @@ def refresh(self): r.raise_for_status() self._set_data(r.json()) - def wait_until_stable(self): + def wait_until_stable(self, commit): """ - Poll GitLab until the changes_count field has a value of "1". - Other values indicate that GitLab hasn't reacted to a push yet. + Poll the MR until the "sha" field matches that of `commit`. """ while True: self.refresh() - if self._changes_count == "1": + if self._sha == commit.commit.hexsha: return time.sleep(0.500)