Skip to content
Snippets Groups Projects
Verified Commit 297ff40a authored by Clayton Craft's avatar Clayton Craft :speech_balloon: Committed by Newbyte
Browse files

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

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.
[ci:skip-build]: already built successfully in CI
parent d49a1ccf
No related branches found
No related tags found
1 merge request!60mrhlpr: mr: use a simpler mechanism to detect if user approved a MR
Pipeline #210714 passed with warnings
......@@ -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