|
30 | 30 | operations-per-run: 60
|
31 | 31 | # Start with the oldest issues, always.
|
32 | 32 | ascending: true
|
| 33 | + - name: "Close old issues labeled likely-no" |
| 34 | + uses: actions/github-script@v5 |
| 35 | + with: |
| 36 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + script: | |
| 38 | + const thirtyDaysAgo = new Date(new Date().setDate(new Date().getDate() - 30)); |
| 39 | + console.log(`Looking for issues labeled with 'likely-no' more than 30 days ago, which is after ${thirtyDaysAgo.toISOString()}`); |
| 40 | +
|
| 41 | + const issues = await github.rest.issues.listForRepo({ |
| 42 | + owner: context.repo.owner, |
| 43 | + repo: context.repo.repo, |
| 44 | + labels: 'likely-no', |
| 45 | + state: 'open', |
| 46 | + }); |
| 47 | +
|
| 48 | + console.log(`Found ${issues.data.length} open issues labeled with 'likely-no'`); |
| 49 | +
|
| 50 | + for (const issue of issues.data) { |
| 51 | + console.log(`Checking issue #${issue.number} created at ${issue.created_at}`); |
| 52 | +
|
| 53 | + const timeline = await github.rest.issues.listEventsForTimeline({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + issue_number: issue.number, |
| 57 | + }); |
| 58 | +
|
| 59 | + const labelEvent = timeline.data.find(event => event.event === 'labeled' && event.label.name === 'likely-no'); |
| 60 | + |
| 61 | + if (labelEvent) { |
| 62 | + console.log(`Issue #${issue.number} was labeled with 'likely-no' at ${labelEvent.created_at}`); |
| 63 | +
|
| 64 | + if (new Date(labelEvent.created_at) < thirtyDaysAgo) { |
| 65 | + console.log(`Issue #${issue.number} is older than 30 days with 'likely-no' label, closing issue.`); |
| 66 | + await github.rest.issues.update({ |
| 67 | + owner: context.repo.owner, |
| 68 | + repo: context.repo.repo, |
| 69 | + issue_number: issue.number, |
| 70 | + state: 'closed', |
| 71 | + state_reason: 'not planned' |
| 72 | + }); |
| 73 | + } |
| 74 | + } else { |
| 75 | + console.log(`Issue #${issue.number} does not have a 'likely-no' label event in its timeline.`); |
| 76 | + } |
| 77 | + } |
| 78 | +
|
33 | 79 | branches:
|
34 | 80 | runs-on: ubuntu-latest
|
35 | 81 | steps:
|
|
0 commit comments