Skip to content

Commit

Permalink
Check MR sha instead of changes_count for stabilization check
Browse files Browse the repository at this point in the history
Followup to #35

Change-Id: I209472650081fc3b32181af41d9ddc30c344adb5
  • Loading branch information
Ahmon Dancy committed Aug 30, 2023
1 parent 3714f22 commit 9bf2897
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 5 additions & 2 deletions gerritlab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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"):
Expand All @@ -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)
Expand All @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions gerritlab/merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 9bf2897

Please sign in to comment.