|
| 1 | +name: Community Feedback Closer |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '30 12 * * *' # 5:30am Redmond, daily |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + issues: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + close-stale-feedback: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Close community feedback issues lacking upvotes |
| 16 | + uses: actions/github-script@v7 |
| 17 | + with: |
| 18 | + script: | |
| 19 | + const label = 'needs community feedback'; |
| 20 | + const requiredUpvotes = 7; |
| 21 | + const maxAgeDays = 60; |
| 22 | + const cutoffDate = new Date(Date.now() - maxAgeDays * 24 * 60 * 60 * 1000); |
| 23 | +
|
| 24 | + const issues = await github.paginate(github.rest.issues.listForRepo, { |
| 25 | + owner: context.repo.owner, |
| 26 | + repo: context.repo.repo, |
| 27 | + labels: label, |
| 28 | + state: 'open', |
| 29 | + per_page: 100, |
| 30 | + }); |
| 31 | +
|
| 32 | + for (const issue of issues) { |
| 33 | + const createdAt = new Date(issue.created_at); |
| 34 | + if (createdAt > cutoffDate) { |
| 35 | + core.info(`#${issue.number} is only ${Math.floor((Date.now() - createdAt) / 86400000)} days old, skipping.`); |
| 36 | + continue; |
| 37 | + } |
| 38 | +
|
| 39 | + const upvotes = issue.reactions?.['+1'] ?? 0; |
| 40 | + if (upvotes >= requiredUpvotes) { |
| 41 | + core.info(`#${issue.number} has ${upvotes} upvotes (>= ${requiredUpvotes}), keeping open.`); |
| 42 | + continue; |
| 43 | + } |
| 44 | +
|
| 45 | + core.info(`Closing #${issue.number} (${upvotes} upvotes, created ${issue.created_at}).`); |
| 46 | +
|
| 47 | + await github.rest.issues.createComment({ |
| 48 | + owner: context.repo.owner, |
| 49 | + repo: context.repo.repo, |
| 50 | + issue_number: issue.number, |
| 51 | + body: `This feature request has not received the 7 community upvotes needed to be considered for future planning within 60 days of its creation. We are closing this issue, but if the community rallies behind it in the future, we are happy to reconsider. Thank you for your feedback!\n\nHappy Coding!`, |
| 52 | + }); |
| 53 | +
|
| 54 | + await github.rest.issues.update({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + issue_number: issue.number, |
| 58 | + state: 'closed', |
| 59 | + state_reason: 'not_planned', |
| 60 | + }); |
| 61 | + } |
0 commit comments