|
| 1 | +name: Update labels on issues and pull requests |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + issues: |
| 7 | + types: [opened] |
| 8 | + |
| 9 | +permissions: {} |
| 10 | + |
| 11 | +jobs: |
| 12 | + label-new-issue: |
| 13 | + if: github.event_name == 'issues' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + issues: write |
| 17 | + steps: |
| 18 | + - name: Add needs attention label on creation |
| 19 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 20 | + with: |
| 21 | + script: | |
| 22 | + await github.rest.issues.addLabels({ |
| 23 | + owner: context.repo.owner, |
| 24 | + repo: context.repo.repo, |
| 25 | + issue_number: context.issue.number, |
| 26 | + labels: ['needs attention'], |
| 27 | + }); |
| 28 | +
|
| 29 | + label-op-response: |
| 30 | + if: github.event_name == 'issue_comment' |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + issues: write |
| 34 | + steps: |
| 35 | + - name: Check if the comment is from the issue author |
| 36 | + id: check-op |
| 37 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const isOpComment = |
| 41 | + context.payload.comment.user.login === |
| 42 | + context.payload.issue.user.login; |
| 43 | + core.setOutput('op_comment', isOpComment ? 'true' : 'false'); |
| 44 | +
|
| 45 | + - name: Update labels when the issue author responded on an open item |
| 46 | + if: steps.check-op.outputs.op_comment == 'true' && github.event.issue.state == 'open' |
| 47 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 48 | + with: |
| 49 | + script: | |
| 50 | + const issueNumber = context.payload.issue.number; |
| 51 | + await github.rest.issues.addLabels({ |
| 52 | + owner: context.repo.owner, |
| 53 | + repo: context.repo.repo, |
| 54 | + issue_number: issueNumber, |
| 55 | + labels: ['needs attention'], |
| 56 | + }); |
| 57 | + try { |
| 58 | + await github.rest.issues.removeLabel({ |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + issue_number: issueNumber, |
| 62 | + name: 'blocked: await customer response', |
| 63 | + }); |
| 64 | + } catch (error) { |
| 65 | + if (error.status !== 404) { |
| 66 | + throw error; |
| 67 | + } |
| 68 | + } |
| 69 | +
|
| 70 | + - name: Comment when the issue author responded on a closed item |
| 71 | + if: steps.check-op.outputs.op_comment == 'true' && github.event.issue.state == 'closed' |
| 72 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 73 | + with: |
| 74 | + script: | |
| 75 | + await github.rest.issues.createComment({ |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + issue_number: context.payload.issue.number, |
| 79 | + body: [ |
| 80 | + 'This item is closed, so it may not receive regular attention.', |
| 81 | + '', |
| 82 | + 'If it is still relevant, please open a new issue with an up-to-date reproduction, or open a new pull request.', |
| 83 | + ].join('\n'), |
| 84 | + }); |
0 commit comments