Skip to content

Commit

Permalink
After pushing, wait for MRs to stabilize
Browse files Browse the repository at this point in the history
By stabililze we mean that the "changes_count" field of the MR has a
value of "1".  This ensures that by the time the "git lab" command
terminates, MRs should be fully up-to-date.

Note that this approach will have to be reevaluated if #16 is
implemented (which would allow multiple commits to end up in a single
MR).

Change-Id: Id20d9feb27076afe0603bee334badc815e5528a9
  • Loading branch information
Ahmon Dancy committed Aug 29, 2023
1 parent 221d1a2 commit 7ee3c16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gerritlab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ def cancel_prev_pipelines(commit):
with timing("push"):
remote.push(refspec=refs_to_push, force=True)

with timing("stabilize"):
for mr in new_mrs+updated_mrs:
mr.wait_until_stable()

if len(updated_mrs) == 0 and len(new_mrs) == 0:
print()
warn("No updated/new MRs.\n")
Expand Down
22 changes: 22 additions & 0 deletions gerritlab/merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def __init__(
self._web_url = None
self._mergeable = False

self._set_data(json_data)

def _set_data(self, json_data):
if json_data is not None:
for attr in json_data:
setattr(self, "_{}".format(attr), json_data[attr])
Expand Down Expand Up @@ -157,6 +160,25 @@ def needs_update(self, commit) -> bool:
self._title != title or
self._description != desc.strip())

def refresh(self):
"""
Update's this object's data using the latest info available from the server.
"""
r = global_vars.session.get("{}/{}".format(global_vars.mr_url, self._iid))
r.raise_for_status()
self._set_data(r.json())

def wait_until_stable(self):
"""
Poll GitLab until the changes_count field has a value of "1".
Other values indicate that GitLab hasn't reacted to a push yet.
"""
while True:
self.refresh()
if self._changes_count == "1":
return
time.sleep(0.500)


def _get_open_merge_requests():
"""Gets all open merge requests in the GitLab repo."""
Expand Down

0 comments on commit 7ee3c16

Please sign in to comment.