Skip to content

Commit d0f6449

Browse files
authored
additional checks
1 parent 23c15a9 commit d0f6449

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

.github/workflows/scripts/pr_workflow.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def __init__(self) -> None:
8888
super().__init__()
8989
self.user_login = os.getenv("GITHUB_USER_LOGIN")
9090
self.review_state = os.getenv("GITHUB_EVENT_REVIEW_STATE")
91+
# We don't care if the body of the comment is in the discussion page or a review
9192
self.comment_body = os.getenv("COMMENT_BODY", "")
9293
if self.comment_body == "":
94+
# if it wasn't a discussion page comment, try to get a review comment, otherwise keep empty
9395
self.comment_body = os.getenv("REVIEW_COMMENT_BODY", "")
9496
self.last_commit = list(self.pr.get_commits())[-1]
9597
self.last_commit_sha = self.last_commit.sha
@@ -285,10 +287,10 @@ def issue_comment_label_actions(
285287
LOGGER.info(f"Processing label: {label}, action: {action}")
286288

287289
if action[CANCEL_ACTION] or self.event_action == "deleted":
290+
self.dismiss_pr_approval()
288291
if label_in_pr:
289292
LOGGER.info(f"Removing label {label}")
290293
self.pr.remove_from_labels(label=label)
291-
self.dismiss_pr_approval()
292294

293295
elif not label_in_pr:
294296
self.add_pr_label(label=label)
@@ -307,9 +309,12 @@ def approve_pr(self) -> None:
307309

308310
def dismiss_pr_approval(self) -> None:
309311
all_reviews = self.pr.get_reviews()
312+
current_user = self.gh_client.get_user().login
313+
LOGGER.info(f"Looking for approving review by user {current_user}")
310314
# The reviews are paginated in chronological order. We need to get the newest by our account
311315
for review in all_reviews.reversed:
312-
if review.user.login == self.gh_client.get_user().login:
316+
if review.user.login == current_user and review.state == "APPROVED":
317+
LOGGER.info(f"found review by user {current_user} with id {review.id}")
313318
review.dismiss()
314319

315320

0 commit comments

Comments
 (0)