Skip to content

Commit 9c1a893

Browse files
authored
[CI] Update Stylebot Permissions (#792)
1 parent e81c36c commit 9c1a893

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

.github/workflows/pr_style_bot.yml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,50 @@ on:
55
issue_comment:
66
types: [created]
77

8-
permissions:
9-
contents: write
10-
pull-requests: write
8+
permissions: {}
9+
10+
env:
11+
PYTHON_VERSION: "3.10"
1112

1213
jobs:
13-
run-style-bot:
14+
check-permissions:
1415
if: >
1516
contains(github.event.comment.body, '@bot /style') &&
1617
github.event.issue.pull_request != null
1718
runs-on: ubuntu-latest
19+
outputs:
20+
is_authorized: ${{ steps.check_user_permission.outputs.has_permission }}
21+
steps:
22+
- name: Check user permission
23+
id: check_user_permission
24+
uses: actions/github-script@v6
25+
with:
26+
script: |
27+
const comment_user = context.payload.comment.user.login;
28+
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
username: comment_user
32+
});
33+
34+
const authorized =
35+
permission.permission === 'admin' ||
36+
permission.permission === 'write';
37+
38+
console.log(
39+
`User ${comment_user} has permission level: ${permission.permission}, ` +
40+
`authorized: ${authorized} (admins & maintainers allowed)`
41+
);
42+
43+
core.setOutput('has_permission', authorized);
1844
45+
run-style-bot:
46+
needs: check-permissions
47+
if: needs.check-permissions.outputs.is_authorized == 'true'
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write
51+
pull-requests: write
1952
steps:
2053
- name: Extract PR details
2154
id: pr_info
@@ -61,6 +94,8 @@ jobs:
6194
6295
- name: Set up Python
6396
uses: actions/setup-python@v4
97+
with:
98+
python-version: ${{ env.PYTHON_VERSION }}
6499

65100
- name: Get Ruff Version from pre-commit-config.yaml
66101
id: get-ruff-version

0 commit comments

Comments
 (0)