|
| 1 | +name: Triage "info-needed" label |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +env: |
| 8 | + TRIAGERS: '["karrtikr","karthiknadig","paulacamargo25","eleanorjboyd", "brettcannon"]' |
| 9 | + |
| 10 | +jobs: |
| 11 | + add_label: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + if: contains(github.event.issue.labels.*.name, 'triage-needed') && !contains(github.event.issue.labels.*.name, 'info-needed') |
| 14 | + env: |
| 15 | + KEYWORDS: '["\\?", "please", "kindly", "let me know", "try", "can you", "could you", "would you", "may I", "provide", "let us know", "tell me", "give me", "send me", "what", "when", "where", "why", "how"]' |
| 16 | + steps: |
| 17 | + - name: Check for author |
| 18 | + uses: actions/github-script@v6 |
| 19 | + with: |
| 20 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + script: | |
| 22 | + const issue = await github.rest.issues.get({ |
| 23 | + owner: context.repo.owner, |
| 24 | + repo: context.repo.repo, |
| 25 | + issue_number: context.issue.number |
| 26 | + }); |
| 27 | + const commentAuthor = context.payload.comment.user.login; |
| 28 | + const commentBody = context.payload.comment.body; |
| 29 | + const isTeamMember = ${{ env.TRIAGERS }}.includes(commentAuthor); |
| 30 | +
|
| 31 | + const keywords = ${{ env.KEYWORDS }}; |
| 32 | + const isRequestForInfo = new RegExp(keywords.join('|'), 'i').test(commentBody); |
| 33 | +
|
| 34 | + const shouldAddLabel = isTeamMember && commentAuthor !== issue.data.user.login && isRequestForInfo; |
| 35 | +
|
| 36 | + if (shouldAddLabel) { |
| 37 | + await github.rest.issues.addLabels({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + issue_number: context.issue.number, |
| 41 | + labels: ['info-needed'] |
| 42 | + }); |
| 43 | + } |
| 44 | +
|
| 45 | + remove_label: |
| 46 | + if: contains(github.event.issue.labels.*.name, 'info-needed') && contains(github.event.issue.labels.*.name, 'triage-needed') |
| 47 | + runs-on: ubuntu-latest |
| 48 | + steps: |
| 49 | + - name: Check for author |
| 50 | + uses: actions/github-script@v6 |
| 51 | + with: |
| 52 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + script: | |
| 54 | + const issue = await github.rest.issues.get({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + issue_number: context.issue.number |
| 58 | + }); |
| 59 | + const commentAuthor = context.payload.comment.user.login; |
| 60 | + const issueAuthor = issue.data.user.login; |
| 61 | + if (commentAuthor === issueAuthor) { |
| 62 | + await github.rest.issues.removeLabel({ |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + issue_number: context.issue.number, |
| 66 | + name: 'info-needed' |
| 67 | + }); |
| 68 | + return; |
| 69 | + } |
| 70 | + if (${{ env.TRIAGERS }}.includes(commentAuthor)) { |
| 71 | + // If one of triagers made a comment, ignore it |
| 72 | + return; |
| 73 | + } |
| 74 | + // Loop through all the comments on the issue in reverse order and find the last username that a TRIAGER mentioned |
| 75 | + // If the comment author is the last mentioned username, remove the "info-needed" label |
| 76 | + const comments = await github.rest.issues.listComments({ |
| 77 | + owner: context.repo.owner, |
| 78 | + repo: context.repo.repo, |
| 79 | + issue_number: context.issue.number |
| 80 | + }); |
| 81 | + for (const comment of comments.data.slice().reverse()) { |
| 82 | + if (!${{ env.TRIAGERS }}.includes(comment.user.login)) { |
| 83 | + continue; |
| 84 | + } |
| 85 | + const matches = comment.body.match(/@\w+/g) || []; |
| 86 | + const mentionedUsernames = matches.map(match => match.replace('@', '')); |
| 87 | + if (mentionedUsernames.includes(commentAuthor)) { |
| 88 | + await github.rest.issues.removeLabel({ |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + issue_number: context.issue.number, |
| 92 | + name: 'info-needed' |
| 93 | + }); |
| 94 | + break; |
| 95 | + } |
| 96 | + } |
0 commit comments