Skip to content
Snippets Groups Projects
Verified Commit 79be226d authored by Clayton Craft's avatar Clayton Craft :speech_balloon:
Browse files

mrhlpr: mr: use a simpler mechanism to detect if user approved a MR

This doesn't depend on an auth error to detect if a user has approved a
MR, and fixes #24.

For some reason mr.approval_state().get was 404'ing, causing #24.
parent dbb8411e
No related branches found
No related tags found
No related merge requests found
Pipeline #210295 passed
......@@ -549,16 +549,14 @@ def finish(
if skip_approve or (gl.user and mr.author and gl.user.id == mr.author.get("id")):
print("Skipping approval...")
else:
print("Approving MR...")
try:
mr.approve(git.sha())
# For some reason, approve fails with auth error if already approved...
except gitlab_api.GitlabAuthenticationError as e:
approved_by_ids = [ap["id"] for ap in mr.approval_state.get().rules[0]["approved_by"]]
if gl.user is None:
raise e
if gl.user.id not in approved_by_ids:
raise RuntimeError("Approving failed, and MR not yet approved") from e
if mr.approvals.get().attributes["user_has_approved"]:
print("MR has already been approved by you!")
else:
print("Approving MR...")
try:
mr.approve(git.sha())
except Exception as e:
raise RuntimeError("Approval failed, your approval was not added!") from e
if comment:
print("Adding the comment...")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment