Skip to content

Commit 1a84aab

Browse files
committed
chore: fix issue/labeler bot
Replace unmaintained actions-ecosystem actions with github-script, use step outputs instead of env context, and restrict token permissions to issues: write only.
1 parent 7cf7c1a commit 1a84aab

1 file changed

Lines changed: 48 additions & 35 deletions

File tree

.github/workflows/issue-labels.yaml

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,61 @@ on:
44
issue_comment:
55
types: [created]
66

7+
permissions:
8+
issues: write
9+
710
jobs:
811
label-op-response:
912
runs-on: ubuntu-latest
1013
steps:
11-
- name: Check if the comment is from the OP
14+
- name: Check if the comment is from the issue author
1215
id: check-op
13-
run: |
14-
OP=${{ github.event.issue.user.login }}
15-
COMMENTER=${{ github.event.comment.user.login }}
16-
17-
if [ "$OP" = "$COMMENTER" ]; then
18-
echo "op_comment=true" >> $GITHUB_ENV
19-
else
20-
echo "op_comment=false" >> $GITHUB_ENV
21-
fi
22-
23-
- name: Add 'Needs Attention' label if OP responded and it was open
24-
if: env.op_comment == 'true' && github.event.issue.state == 'open'
25-
# https://github.com/actions-ecosystem/action-add-labels/releases
26-
uses: actions-ecosystem/action-add-labels@bd52874380e3909a1ac983768df6976535ece7d8 # v1.1.0
16+
uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0
2717
with:
28-
labels: 'Needs Attention'
29-
env:
30-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
18+
script: |
19+
const isOpComment =
20+
context.payload.comment.user.login ===
21+
context.payload.issue.user.login;
22+
core.setOutput('op_comment', isOpComment ? 'true' : 'false');
3123
32-
- name: Remove 'blocked customer-response' label if OP responded and it was open
33-
if: env.op_comment == 'true' && github.event.issue.state == 'open'
34-
# https://github.com/actions-ecosystem/action-remove-labels/releases
35-
uses: actions-ecosystem/action-remove-labels@f5dccab59b9ed79c1a5ddd2ab6d8771449b0250f # v1.3.0
24+
- name: Update labels when the issue author responded on an open item
25+
if: steps.check-op.outputs.op_comment == 'true' && github.event.issue.state == 'open'
26+
uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0
3627
with:
37-
labels: 'blocked: customer-response'
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
28+
script: |
29+
const issueNumber = context.payload.issue.number;
30+
await github.rest.issues.addLabels({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
issue_number: issueNumber,
34+
labels: ['Needs Attention'],
35+
});
36+
try {
37+
await github.rest.issues.removeLabel({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
issue_number: issueNumber,
41+
name: 'blocked: customer-response',
42+
});
43+
} catch (error) {
44+
if (error.status !== 404) {
45+
throw error;
46+
}
47+
}
4048
41-
- name: Add comment if OP responded but issue was closed
42-
if: env.op_comment == 'true' && github.event.issue.state == 'closed'
43-
# https://github.com/actions-ecosystem/action-create-comment/releases
44-
uses: actions-ecosystem/action-create-comment@5b43c092bf96ebc715dbbe5682ecf3b771223855 # v1.0.0
49+
- name: Comment when the issue author responded on a closed item
50+
if: steps.check-op.outputs.op_comment == 'true' && github.event.issue.state == 'closed'
51+
uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0
4552
with:
46-
github_token: ${{ secrets.GH_TOKEN }}
47-
body: |
48-
In order to prioritize work in this repository, closed issues and pull requests do not regularly receive attention.
49-
50-
If the underlying issue or pull request still requires attention, opening a new issue with a reproduction
51-
after testing with current versions, or reposting the pull request as a new PR may be the most effective way forward.
53+
script: |
54+
await github.rest.issues.createComment({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
issue_number: context.payload.issue.number,
58+
body: [
59+
'In order to prioritize work in this repository, closed issues and pull requests do not regularly receive attention.',
60+
'',
61+
'If the underlying issue or pull request still requires attention, opening a new issue with a reproduction',
62+
'after testing with current versions, or reposting the pull request as a new PR may be the most effective way forward.',
63+
].join('\n'),
64+
});

0 commit comments

Comments
 (0)