-
Notifications
You must be signed in to change notification settings - Fork 130
Add PR assignee rotation workflow #976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ilopezluna
wants to merge
1
commit into
main
Choose a base branch
from
add-pr-assignee-rotation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| name: Assign PR | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened] | ||
|
|
||
| permissions: | ||
| issues: write | ||
| pull-requests: read | ||
|
|
||
| concurrency: | ||
| group: pr-assignee-rotation | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| assign: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Assign PR in rotation | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| PR_CREATED_AT: ${{ github.event.pull_request.created_at }} | ||
| ROTATION_START_AT: "2026-06-18T08:11:55Z" | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| readonly USERS=(ilopezluna ericcurtin doringeman) | ||
| readonly BOT_LOGIN="github-actions[bot]" | ||
|
|
||
| next_assignee="${USERS[0]}" | ||
| page=1 | ||
|
|
||
| while true; do | ||
| prs=$(gh api \ | ||
| --method GET \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "/repos/${REPO}/pulls" \ | ||
| -f state=all \ | ||
| -f sort=created \ | ||
| -f direction=desc \ | ||
| -f per_page=100 \ | ||
| -f page="${page}") | ||
|
|
||
| count=$(jq 'length' <<<"${prs}") | ||
| if [ "${count}" -eq 0 ]; then | ||
| break | ||
| fi | ||
|
|
||
| while IFS=$'\t' read -r number created_at; do | ||
| if [[ "${number}" == "${PR_NUMBER}" ]]; then | ||
| continue | ||
| fi | ||
|
|
||
| if [[ "${created_at}" > "${PR_CREATED_AT}" || "${created_at}" == "${PR_CREATED_AT}" ]]; then | ||
| continue | ||
| fi | ||
|
|
||
| if [[ "${created_at}" < "${ROTATION_START_AT}" ]]; then | ||
| echo "Reached PRs created before rotation start; using ${next_assignee}." | ||
| break 2 | ||
| fi | ||
|
|
||
| events=$(gh api \ | ||
| --method GET \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "/repos/${REPO}/issues/${number}/events" \ | ||
| -f per_page=100) | ||
|
|
||
| previous_assignee=$(jq -r \ | ||
| --arg bot "${BOT_LOGIN}" \ | ||
| --argjson users "$(printf '%s\n' "${USERS[@]}" | jq -R . | jq -s .)" \ | ||
| '[.[] | select(.event == "assigned" and .actor.login == $bot and (.assignee.login as $login | $users | index($login)))][-1].assignee.login // empty' \ | ||
| <<<"${events}") | ||
|
|
||
| if [[ -n "${previous_assignee}" ]]; then | ||
| for i in "${!USERS[@]}"; do | ||
| if [[ "${USERS[$i]}" == "${previous_assignee}" ]]; then | ||
| next_assignee="${USERS[$(((i + 1) % ${#USERS[@]}))]}" | ||
| echo "Previous rotated PR #${number} was assigned to ${previous_assignee}; assigning ${next_assignee}." | ||
| break 3 | ||
| fi | ||
| done | ||
| fi | ||
| done < <(jq -r '.[] | [.number, .created_at] | @tsv' <<<"${prs}") | ||
|
|
||
| page=$((page + 1)) | ||
| done | ||
|
|
||
| gh api \ | ||
| --method POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "/repos/${REPO}/issues/${PR_NUMBER}/assignees" \ | ||
| -f "assignees[]=${next_assignee}" >/dev/null | ||
|
|
||
| echo "Assigned PR #${PR_NUMBER} to ${next_assignee}." | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Issue event pagination might miss older bot assignments on noisy PRs.
Because the
/issues/{number}/eventscall is limited to 100 items and we don’t paginate, older botassignedevents on noisy PRs can be dropped, causing us to incorrectly fall back tonext_assignee. Please either paginate until you’ve found the last bot assignment or use a query that reliably returns the latest relevant assignment (e.g., a targeted GraphQL query or iterating event pages until no more matches).