Skip to content

Commit 9f35bc0

Browse files
committed
fix: correctly detect team members using permission level API
Signed-off-by: Abhijeet Saharan <abhijeetsaharan2236@gmail.com>
1 parent 5a1393c commit 9f35bc0

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

.github/scripts/bot-gfi-assign-on-comment.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,40 @@ async function isRepoCollaborator({ github, owner, repo, username }) {
146146
}
147147

148148
try {
149-
await github.rest.repos.checkCollaborator({
149+
const response = await github.rest.repos.getCollaboratorPermissionLevel({
150150
owner,
151151
repo,
152152
username,
153153
});
154-
return true; // 204 = collaborator
154+
155+
const permission = response?.data?.permission;
156+
157+
const isTeamMember =
158+
permission === 'admin' ||
159+
permission === 'write' ||
160+
permission === 'read';
161+
162+
console.log('[gfi-assign] isRepoCollaborator:', {
163+
username,
164+
permission,
165+
isTeamMember,
166+
});
167+
168+
return isTeamMember;
155169
} catch (error) {
156-
if (error?.status === 404 || isPermissionFailure(error)) {
157-
if (isPermissionFailure(error)) {
158-
console.log(
159-
'[gfi-assign] isRepoCollaborator: insufficient permissions; treating as non-collaborator',
160-
{ owner, repo, username, status: error.status }
161-
);
162-
}
170+
if (isPermissionFailure(error) || error?.status === 404) {
171+
console.log(
172+
'[gfi-assign] isRepoCollaborator: no permission / not collaborator',
173+
{ username, status: error.status }
174+
);
163175
return false;
164176
}
165-
throw error; // unexpected error
177+
throw error;
166178
}
167-
168179
}
169180

170181

182+
171183
/// START OF SCRIPT ///
172184
module.exports = async ({ github, context }) => {
173185
try {

0 commit comments

Comments
 (0)