Skip to content

Commit b4b4acf

Browse files
authored
chore: check permission for pkg-pr-new comment (#17461)
1 parent c608e6a commit b4b4acf

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

.github/workflows/publish-commit.yml

+39-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,46 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21+
- if: github.event.issue.pull_request
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
const user = context.payload.sender.login
26+
console.log(`Validate user: ${user}`)
27+
28+
let hasTriagePermission = false
29+
try {
30+
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
username: user,
34+
});
35+
hasTriagePermission = data.user.permissions.triage
36+
} catch (e) {
37+
console.warn(e)
38+
}
39+
40+
if (hasTriagePermission) {
41+
console.log('Allowed')
42+
await github.rest.reactions.createForIssueComment({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
comment_id: context.payload.comment.id,
46+
content: '+1',
47+
})
48+
} else {
49+
console.log('Not allowed')
50+
await github.rest.reactions.createForIssueComment({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
comment_id: context.payload.comment.id,
54+
content: '-1',
55+
})
56+
throw new Error('not allowed')
57+
}
58+
2159
- name: Checkout code
22-
uses: actions/checkout@v3
60+
uses: actions/checkout@v4
2361

2462
- name: Install pnpm
2563
uses: pnpm/[email protected]

0 commit comments

Comments
 (0)