File tree Expand file tree Collapse file tree 1 file changed +39
-4
lines changed Expand file tree Collapse file tree 1 file changed +39
-4
lines changed Original file line number Diff line number Diff line change 5
5
issue_comment :
6
6
types : [created]
7
7
8
- permissions :
9
- contents : write
10
- pull-requests : write
8
+ permissions : {}
9
+
10
+ env :
11
+ PYTHON_VERSION : " 3.10"
11
12
12
13
jobs :
13
- run-style-bot :
14
+ check-permissions :
14
15
if : >
15
16
contains(github.event.comment.body, '@bot /style') &&
16
17
github.event.issue.pull_request != null
17
18
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);
18
44
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
19
52
steps :
20
53
- name : Extract PR details
21
54
id : pr_info
61
94
62
95
- name : Set up Python
63
96
uses : actions/setup-python@v4
97
+ with :
98
+ python-version : ${{ env.PYTHON_VERSION }}
64
99
65
100
- name : Get Ruff Version from pre-commit-config.yaml
66
101
id : get-ruff-version
You can’t perform that action at this time.
0 commit comments