@@ -293,24 +293,41 @@ class GitHubHelper {
293293 };
294294 }
295295 getActorPermission(repo, actor) {
296+ var _a;
296297 return __awaiter(this, void 0, void 0, function* () {
297- // https://docs.github.com/en/graphql/reference/enums#repositorypermission
298- // https://docs.github.com/en/graphql/reference/objects#repositorycollaboratoredge
299- // Returns 'READ', 'TRIAGE', 'WRITE', 'MAINTAIN', 'ADMIN'
300- const query = `query CollaboratorPermission($owner: String!, $repo: String!, $collaborator: String) {
301- repository(owner:$owner, name:$repo) {
302- collaborators(login: $collaborator) {
303- edges {
304- permission
305- }
306- }
307- }
308- }`;
309- const collaboratorPermission = yield this.octokit.graphql(query, Object.assign(Object.assign({}, repo), { collaborator: actor }));
310- core.debug(`CollaboratorPermission: ${(0, util_1.inspect)(collaboratorPermission.repository.collaborators.edges)}`);
311- return collaboratorPermission.repository.collaborators.edges.length > 0
312- ? collaboratorPermission.repository.collaborators.edges[0].permission.toLowerCase()
313- : 'none';
298+ // Use the REST API approach which can detect both direct and team-based permissions
299+ // This is more reliable than the GraphQL approach for team permissions and works better with default GITHUB_TOKEN
300+ try {
301+ const { data: collaboratorPermission } = yield this.octokit.rest.repos.getCollaboratorPermissionLevel(Object.assign(Object.assign({}, repo), { username: actor }));
302+ const permissions = (_a = collaboratorPermission.user) === null || _a === void 0 ? void 0 : _a.permissions;
303+ core.debug(`REST API collaborator permission: ${(0, util_1.inspect)(permissions)}`);
304+ // Use the detailed permissions object to get the highest permission level
305+ if (permissions) {
306+ // Check permissions in order of highest to lowest
307+ if (permissions.admin) {
308+ return 'admin';
309+ }
310+ else if (permissions.maintain) {
311+ return 'maintain';
312+ }
313+ else if (permissions.push) {
314+ return 'write';
315+ }
316+ else if (permissions.triage) {
317+ core.debug(`User ${actor} has triage permission via REST API`);
318+ return 'triage';
319+ }
320+ else if (permissions.pull) {
321+ core.debug(`User ${actor} has read permission via REST API`);
322+ return 'read';
323+ }
324+ }
325+ return 'none';
326+ }
327+ catch (error) {
328+ core.debug(`REST API permission check failed: ${utils.getErrorMessage(error)}`);
329+ return 'none';
330+ }
314331 });
315332 }
316333 tryAddReaction(repo, commentId, reaction) {
0 commit comments