Skip to content

Commit 45fa8cd

Browse files
committed
add step to check user permission
Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
1 parent 86a29ea commit 45fa8cd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

.github/workflows/e2e.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,35 @@ jobs:
6868
TEST_BITBUCKET_SERVER_USER: pipelines
6969
TEST_BITBUCKET_SERVER_E2E_REPOSITORY: PAC/pac-e2e-tests
7070
steps:
71+
- name: Check user permissions (detailed)
72+
id: check_perms
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
const actor = context.actor;
77+
const { owner, repo } = context.repo;
78+
79+
try {
80+
const response = await github.rest.repos.getCollaboratorPermissionLevel({
81+
owner,
82+
repo,
83+
username: actor,
84+
});
85+
86+
const userPermission = response.data.permission;
87+
88+
if (userPermission === 'admin') {
89+
core.info(`✅ Permission check successful. User @${actor} is an ADMIN.`);
90+
} else if (userPermission === 'write') {
91+
core.info(`✅ Permission check successful. User @${actor} has WRITE permission.`);
92+
} else {
93+
core.setFailed(`❌ Permission check failed. User @${actor} has '${userPermission}' permission, but 'write' or 'admin' is required to proceed.`);
94+
}
95+
96+
} catch (error) {
97+
core.setFailed(`Could not verify permission for @${actor}. They might not be a collaborator. Error: ${error.message}`);
98+
}
99+
71100
- uses: actions/checkout@v5
72101
with:
73102
ref: ${{ inputs.target_ref || github.event.pull_request.head.sha || github.sha }}

0 commit comments

Comments
 (0)