|
| 1 | +name: Auto Close Issue |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * *' |
| 6 | + |
| 7 | +jobs: |
| 8 | + close-not-reproducible-issues: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 12 | + env: |
| 13 | + BODY: > |
| 14 | + Thanks for raising this issue 🙏<br /> |
| 15 | + <br /> |
| 16 | + Unfortunately, we are closing the issue as no reproducible samples were provided within 7 days.<br /> |
| 17 | + If there are any updates, please reopen this issue or create new one.<br /> |
| 18 | + <br /> |
| 19 | + If you have any questions please reach out to us on our [Discord](https://discord.webdriver.io/)<br /> |
| 20 | + channel. We are happy to help you out there. |
| 21 | + with: |
| 22 | + github-token: ${{ secrets.WDIO_BOT_GITHUB_TOKEN }} |
| 23 | + script: | |
| 24 | + const labelName = 'Reproducible Example Missing' |
| 25 | + const daysBeforeClose = 7 |
| 26 | + const perPage = 100 |
| 27 | +
|
| 28 | + const now = new Date() |
| 29 | + const msInDay = 24 * 60 * 60 * 1000 |
| 30 | + const iterator = github.paginate.iterator(github.rest.issues.listForRepo, { |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + state: 'open', |
| 34 | + labels: [labelName], |
| 35 | + per_page: perPage, |
| 36 | + }) |
| 37 | +
|
| 38 | + for await (const { data: issues } of iterator) { |
| 39 | + for (const issue of issues) { |
| 40 | + if (issue.pull_request) { |
| 41 | + continue |
| 42 | + } |
| 43 | +
|
| 44 | + const events = await github.paginate( |
| 45 | + github.rest.issues.listEventsForTimeline, |
| 46 | + { |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + issue_number: issue.number, |
| 50 | + per_page: perPage |
| 51 | + } |
| 52 | + ) |
| 53 | +
|
| 54 | + const labelEvent = events.find( |
| 55 | + e => e.event === 'labeled' && e.label?.name === labelName |
| 56 | + ) |
| 57 | +
|
| 58 | + if (!labelEvent) { |
| 59 | + continue |
| 60 | + } |
| 61 | +
|
| 62 | + const labeledAt = new Date(labelEvent.created_at) |
| 63 | + const updatedAt = new Date(issue.updated_at) |
| 64 | + const targetDate = updatedAt > labeledAt ? updatedAt : labeledAt |
| 65 | +
|
| 66 | + const diffDays = Math.floor((now - targetDate) / msInDay) |
| 67 | + if (diffDays >= daysBeforeClose) { |
| 68 | + console.log(`Closing issue #${issue.number} (inactive ${diffDays} days after label)`) |
| 69 | +
|
| 70 | + await github.rest.issues.createComment({ |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + issue_number: issue.number, |
| 74 | + body: process.env.BODY, |
| 75 | + }) |
| 76 | +
|
| 77 | + await github.rest.issues.update({ |
| 78 | + owner: context.repo.owner, |
| 79 | + repo: context.repo.repo, |
| 80 | + issue_number: issue.number, |
| 81 | + state: 'closed' |
| 82 | + }) |
| 83 | + } |
| 84 | + } |
| 85 | + } |
0 commit comments