Round-robin issue assignment #3
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
| name: Round-robin issue assignment | |
| on: | |
| issues: | |
| types: [opened] | |
| # Important: avoid race conditions if multiple issues are opened close together. | |
| # This serializes runs in the same "group" instead of running in parallel. | |
| concurrency: | |
| group: rr-issue-assignment | |
| cancel-in-progress: false | |
| jobs: | |
| assign: | |
| runs-on: ubuntu-latest | |
| # Needed for assigning the issue if you use GITHUB_TOKEN in any step. | |
| # In this workflow we use the PAT for both reading/updating vars and assigning, | |
| # but keeping issues:write is still fine. | |
| permissions: | |
| issues: write | |
| contents: read | |
| steps: | |
| - name: Round-robin assign and persist last index | |
| env: | |
| GH_TOKEN: ${{ secrets.RR_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| ISSUE_NUMBER: ${{ github.event.issue.number }} | |
| run: | | |
| set -euo pipefail | |
| # Read the assignee list variable | |
| assignees_json=$(gh api -H "Accept: application/vnd.github+json" \ | |
| /repos/$REPO/actions/variables/RR_ASSIGNEES --jq .value) | |
| # Read the last index variable | |
| last_index=$(gh api -H "Accept: application/vnd.github+json" \ | |
| /repos/$REPO/actions/variables/RR_LAST_INDEX --jq .value) | |
| # Compute next index (wrap around) | |
| count=$(echo "$assignees_json" | jq 'length') | |
| next_index=$(( (last_index + 1) % count )) | |
| assignee=$(echo "$assignees_json" | jq -r ".[$next_index]") | |
| echo "Assigning issue #$ISSUE_NUMBER to $assignee (index $next_index of $count)" | |
| # Assign the issue | |
| gh api -X POST -H "Accept: application/vnd.github+json" \ | |
| /repos/$REPO/issues/$ISSUE_NUMBER/assignees \ | |
| -f assignees[]="$assignee" >/dev/null | |
| # Persist updated index back to the repo variable | |
| gh api -X PATCH -H "Accept: application/vnd.github+json" \ | |
| /repos/$REPO/actions/variables/RR_LAST_INDEX \ | |
| -f name="RR_LAST_INDEX" -f value="$next_index" >/dev/null |