|
| 1 | +name: Remove Inactive Issue Assignees |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * 0' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + cleanup_assignees: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Identify and notify inactive issues |
| 16 | + uses: actions/github-script@v6 |
| 17 | + with: |
| 18 | + script: | |
| 19 | + const inactiveDays = 60; |
| 20 | + const warningDays = 7; |
| 21 | +
|
| 22 | + const issues = await github.paginate(github.rest.issues.listForRepo, { |
| 23 | + owner: context.repo.owner, |
| 24 | + repo: context.repo.repo, |
| 25 | + state: 'open' |
| 26 | + }); |
| 27 | +
|
| 28 | + const now = new Date(); |
| 29 | +
|
| 30 | + for (const issue of issues) { |
| 31 | + const lastUpdate = new Date(issue.updated_at); |
| 32 | + const daysInactive = Math.floor((now - lastUpdate) / (1000 * 60 * 60 * 24)); |
| 33 | +
|
| 34 | + if (daysInactive >= inactiveDays && issue.assignees.length > 0) { |
| 35 | + const warningComment = issue.comments.some(comment => comment.body.includes('[PT-BR] Os assignees serão removidos. \n\n[EN] The assignees will be removed.')); |
| 36 | +
|
| 37 | + if (!warningComment) { |
| 38 | + await github.rest.issues.createComment({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + issue_number: issue.number, |
| 42 | + body: `:warning: [PT-BR] Esta issue está inativa há ${daysInactive} dias. Os assignees serão removidos em ${warningDays} dias caso não haja atualizações.\n\n:warning: [EN] This issue has been inactive for ${daysInactive} days. The assignees will be removed in ${warningDays} days if there are no updates.` |
| 43 | + }); |
| 44 | + } |
| 45 | + } else if (daysInactive >= inactiveDays + warningDays && issue.assignees.length > 0) { |
| 46 | + await github.rest.issues.removeAssignees({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + issue_number: issue.number, |
| 50 | + assignees: issue.assignees.map(assignee => assignee.login) |
| 51 | + }); |
| 52 | +
|
| 53 | + await github.rest.issues.createComment({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + issue_number: issue.number, |
| 57 | + body: `✅ [PT-BR] Os assignees foram removidos devido à inatividade prolongada da issue.\n\n✅ [EN] The assignees have been removed due to prolonged inactivity of this issue.` |
| 58 | + }); |
| 59 | + } |
| 60 | + } |
| 61 | +
|
0 commit comments