Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions .github/workflows/dependabot_review_request_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ jobs:
REVIEWER: Pigbibi
run: |
set -euo pipefail
latest_review_request_actor() {
gh api --paginate \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/timeline?per_page=100" |
jq -sr --arg reviewer "${REVIEWER}" \
'[.[][] | select(.event == "review_requested" and .requested_reviewer.login == $reviewer)][-1].actor.login // ""'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor review-request removals before restoring

If a maintainer requests Pigbibi after the DELETE and then removes that request before the second timeline read, this filter still reports the maintainer as the latest actor because it ignores the later review_request_removed event. The subsequent POST then re-adds a review request the maintainer intentionally cancelled. Check that Pigbibi is currently requested (or account for removal events) before performing the restore.

Useful? React with 👍 / 👎.

}

review_requests="$(gh pr view "${PR_NUMBER}" \
--repo "${GITHUB_REPOSITORY}" \
--json reviewRequests \
Expand All @@ -39,9 +46,7 @@ jobs:
exit 0
fi

latest_request_actor="$(gh api \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/timeline?per_page=100" \
--jq '[.[] | select(.event == "review_requested" and .requested_reviewer.login == "Pigbibi")][-1].actor.login // ""')"
latest_request_actor="$(latest_review_request_actor)"
case "${latest_request_actor}" in
'dependabot[bot]'|'app/dependabot') ;;
*)
Expand All @@ -53,4 +58,16 @@ jobs:
gh api --method DELETE \
"repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/requested_reviewers" \
-f "reviewers[]=${REVIEWER}"
echo "Dismissed Dependabot review request for ${REVIEWER}." >> "${GITHUB_STEP_SUMMARY}"

latest_request_actor="$(latest_review_request_actor)"
case "${latest_request_actor}" in
'dependabot[bot]'|'app/dependabot')
echo "Dismissed Dependabot review request for ${REVIEWER}." >> "${GITHUB_STEP_SUMMARY}"
;;
*)
gh api --method POST \
"repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/requested_reviewers" \
-f "reviewers[]=${REVIEWER}"
echo "Restored review request made by ${latest_request_actor:-<unknown>}." >> "${GITHUB_STEP_SUMMARY}"
;;
esac
Loading