Skip to content

Commit 080d2d6

Browse files
check permissions of user before attempting to create branch (adobe#2985)
Co-authored-by: Robert Snow <[email protected]>
1 parent 841e237 commit 080d2d6

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: 'Check permissions'
2+
description: 'Checks if commentor has write access or above'
3+
runs:
4+
using: 'node16'
5+
main: 'index.js'

.github/actions/permissions/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
4+
const octokit = new github.GitHub(process.env.GITHUB_TOKEN);
5+
run();
6+
async function run() {
7+
const context = github.context;
8+
try {
9+
// Get permission level of actor
10+
const {data} = await octokit.repos.getCollaboratorPermissionLevel({
11+
...context.repo,
12+
username: context.actor
13+
});
14+
15+
if (!['admin','write'].includes(data.permission)) {
16+
core.setFailed('User doesn\'t have write permissions or higher');
17+
}
18+
} catch (error) {
19+
core.setFailed(error.message);
20+
}
21+
}

.github/workflows/pr-comment.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ jobs:
1818
node-version: '16'
1919
- name: install
2020
run: yarn install
21-
- name: Comment contains trigger
21+
- name: Check write permissions of commentor
22+
uses: ./.github/actions/permissions
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Create/update branch for fork PR
2226
uses: ./.github/actions/branch
2327
env:
2428
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)