@@ -146,28 +146,41 @@ 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 === 'maintain' ||
161+ permission === 'read' ;
162+
163+ console . log ( '[gfi-assign] isRepoCollaborator:' , {
164+ username,
165+ permission,
166+ isTeamMember,
167+ } ) ;
168+
169+ return isTeamMember ;
155170 } 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- }
171+ if ( isPermissionFailure ( error ) || error ?. status === 404 ) {
172+ console . log (
173+ '[gfi-assign] isRepoCollaborator: no permission / not collaborator' ,
174+ { username, status : error . status }
175+ ) ;
163176 return false ;
164177 }
165- throw error ; // unexpected error
178+ throw error ;
166179 }
167-
168180}
169181
170182
183+
171184/// START OF SCRIPT ///
172185module . exports = async ( { github, context } ) => {
173186 try {
@@ -220,7 +233,7 @@ module.exports = async ({ github, context }) => {
220233 username,
221234 } ) ;
222235
223- if ( isTeamMember ) {
236+ if ( isTeamMember ) {
224237 console . log ( '[gfi-assign] Skip reminder: commenter is collaborator' ) ;
225238 return ;
226239 }
@@ -397,4 +410,4 @@ module.exports = async ({ github, context }) => {
397410 } ) ;
398411 throw error ;
399412 }
400- } ;
413+ } ;
0 commit comments