Skip to content

Commit df3bbee

Browse files
zakisknoorsk-dev
authored andcommitted
add step to check user permission
Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
1 parent 46b1833 commit df3bbee

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
@@ -112,6 +112,35 @@ jobs:
112112
TEST_BITBUCKET_SERVER_USER: pipelines
113113
TEST_BITBUCKET_SERVER_E2E_REPOSITORY: PAC/pac-e2e-tests
114114
steps:
115+
- name: Check user permissions (detailed)
116+
id: check_perms
117+
uses: actions/github-script@v7
118+
with:
119+
script: |
120+
const actor = context.actor;
121+
const { owner, repo } = context.repo;
122+
123+
try {
124+
const response = await github.rest.repos.getCollaboratorPermissionLevel({
125+
owner,
126+
repo,
127+
username: actor,
128+
});
129+
130+
const userPermission = response.data.permission;
131+
132+
if (userPermission === 'admin') {
133+
core.info(`✅ Permission check successful. User @${actor} is an ADMIN.`);
134+
} else if (userPermission === 'write') {
135+
core.info(`✅ Permission check successful. User @${actor} has WRITE permission.`);
136+
} else {
137+
core.setFailed(`❌ Permission check failed. User @${actor} has '${userPermission}' permission, but 'write' or 'admin' is required to proceed.`);
138+
}
139+
140+
} catch (error) {
141+
core.setFailed(`Could not verify permission for @${actor}. They might not be a collaborator. Error: ${error.message}`);
142+
}
143+
115144
- uses: actions/checkout@v5
116145
with:
117146
ref: ${{ inputs.target_ref || github.event.pull_request.head.sha || github.sha }}

0 commit comments

Comments
 (0)