Skip to content

Commit 1574b6a

Browse files
authored
fix collaborator check
1 parent ede33f4 commit 1574b6a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

.github/workflows/integration-testing.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,31 @@ jobs:
2222
result-encoding: string
2323
script: |
2424
try {
25+
let username;
26+
if (context.payload.pull_request) {
27+
username = context.payload.pull_request.user.login;
28+
} else {
29+
// For non-PRs (eg. merge), check the actor (person who merged)
30+
username = context.actor;
31+
console.log(`No pull request context found, checking permissions for actor: ${username}`);
32+
}
33+
2534
const permissionResponse = await github.rest.repos.getCollaboratorPermissionLevel({
2635
owner: context.repo.owner,
2736
repo: context.repo.repo,
28-
username: context.payload.pull_request.user.login,
37+
username: username,
2938
});
3039
const permission = permissionResponse.data.permission;
3140
const hasWriteAccess = ['write', 'admin'].includes(permission);
3241
if (!hasWriteAccess) {
33-
console.log(`User ${context.payload.pull_request.user.login} does not have write access to the repository (permission: ${permission})`);
42+
console.log(`User ${username} does not have write access to the repository (permission: ${permission})`);
3443
return "manual-approval"
3544
} else {
36-
console.log(`Verifed ${context.payload.pull_request.user.login} has write access. Auto Approving PR Checks.`)
45+
console.log(`Verifed ${username} has write access. Auto Approving PR Checks.`)
3746
return "auto-approve"
3847
}
3948
} catch (error) {
40-
console.log(`${context.payload.pull_request.user.login} does not have write access. Requiring Manual Approval to run PR Checks.`)
49+
console.log(`${username} does not have write access. Requiring Manual Approval to run PR Checks.`)
4150
return "manual-approval"
4251
}
4352
check-access-and-checkout:

0 commit comments

Comments
 (0)