Unassign Issues with No PR After 7 Days #2
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: Unassign Issues with No PR After 7 Days | |
| on: | |
| schedule: | |
| - cron: '0 2 * * *' # Runs daily at 2 AM UTC | |
| workflow_dispatch: # Manual trigger support | |
| jobs: | |
| unassign-stale-issues: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check for stale assigned issues | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.PAT }} | |
| script: | | |
| const daysBeforeUnassign = 7; | |
| const cutoffDate = new Date(); | |
| cutoffDate.setDate(cutoffDate.getDate() - daysBeforeUnassign); | |
| const issues = await github.paginate(github.rest.issues.listForRepo, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| assignee: '*' | |
| }); | |
| for (const issue of issues) { | |
| if (issue.pull_request) continue; // Skip PRs | |
| const createdAt = new Date(issue.created_at); | |
| const assigned = issue.assignees.length > 0; | |
| if (assigned && createdAt < cutoffDate) { | |
| // Check if there's a linked PR via timeline | |
| const timeline = await github.paginate(github.rest.issues.listEventsForTimeline, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| mediaType: { | |
| previews: ["mockingbird"] | |
| } | |
| }); | |
| const hasLinkedPR = timeline.some(event => event.event === 'connected'); | |
| if (!hasLinkedPR) { | |
| console.log(`Unassigning issue #${issue.number} (no PR in 7 days)`); | |
| await github.rest.issues.removeAssignees({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| assignees: issue.assignees.map(user => user.login) | |
| }); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| body: `⏰ This issue was automatically unassigned because no pull request was raised within 5 days. Feel free to ask for re-assignment if you're still working on it.` | |
| }); | |
| } | |
| } | |
| } |