Unassign Stale Issues #55
This file contains 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: Unassign Stale Issues | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Runs daily at midnight | |
jobs: | |
unassign-issues: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Unassign Stale Issues | |
run: | | |
open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues?state=open" \ | |
| jq -r '.[] | select(.assignee != null) | .number') | |
for issue in $open_issues; do | |
# Get the last updated timestamp of the issue | |
last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ | |
| jq -r '.updated_at') | |
days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 )) | |
if [ $days_since_update -gt 40 ]; then | |
current_assignee=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ | |
| jq -r '.assignee.login') | |
# Unassign the current assignee | |
curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d "{\"assignees\":[\"$current_assignee\"]}" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/assignees" | |
# Find the next assignee in the queue (mentioned in the issue body as @username) | |
next_assignee=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ | |
| jq -r '.body' | grep -o '@[a-zA-Z0-9_-]\+' | head -n 1 | tr -d '@') | |
if [ -n "$next_assignee" ]; then | |
# Assign to the next assignee | |
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d "{\"assignees\":[\"$next_assignee\"]}" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/assignees" | |
fi | |
# Add a comment mentioning the reassignment | |
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d "{\"body\":\"@${current_assignee} has been unassigned due to inactivity. @${next_assignee}, you have been assigned to this issue. Please make sure to update the issue within the next 15 days.\"}" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments" | |
fi | |
done |