@@ -84,6 +84,57 @@ If you’d like to work on this **Good First Issue**, just comment:
8484and you’ll be automatically assigned. Feel free to ask questions here if anything is unclear!` ;
8585}
8686
87+ /// HELPERS TO DETECT COLLABORATORS ///
88+
89+ function hasValidInputs ( { github, owner, repo, username } ) {
90+ return Boolean (
91+ github &&
92+ typeof owner === 'string' &&
93+ typeof repo === 'string' &&
94+ typeof username === 'string' &&
95+ owner &&
96+ repo &&
97+ username
98+ ) ;
99+ }
100+
101+ function isPermissionFailure ( error ) {
102+ return error ?. status === 401 || error ?. status === 403 ;
103+ }
104+
105+ async function isRepoCollaborator ( { github, owner, repo, username } ) {
106+ if ( ! hasValidInputs ( { github, owner, repo, username } ) ) {
107+ console . log ( '[gfi-assign] isRepoCollaborator: invalid args' , {
108+ owner,
109+ repo,
110+ username,
111+ } ) ;
112+ return false ;
113+ }
114+
115+ try {
116+ await github . rest . repos . checkCollaborator ( {
117+ owner,
118+ repo,
119+ username,
120+ } ) ;
121+ return true ; // 204 = collaborator
122+ } catch ( error ) {
123+ if ( error ?. status === 404 || isPermissionFailure ( error ) ) {
124+ if ( isPermissionFailure ( error ) ) {
125+ console . log (
126+ '[gfi-assign] isRepoCollaborator: insufficient permissions; treating as non-collaborator' ,
127+ { owner, repo, username, status : error . status }
128+ ) ;
129+ }
130+ return false ;
131+ }
132+ throw error ; // unexpected error
133+ }
134+
135+ }
136+
137+
87138/// START OF SCRIPT ///
88139module . exports = async ( { github, context } ) => {
89140 try {
@@ -127,6 +178,20 @@ module.exports = async ({ github, context }) => {
127178 issueIsGoodFirstIssue ( issue ) &&
128179 ! issue . assignees ?. length
129180 ) {
181+ const username = comment . user . login ;
182+
183+ const isTeamMember = await isRepoCollaborator ( {
184+ github,
185+ owner,
186+ repo,
187+ username,
188+ } ) ;
189+
190+ if ( isTeamMember ) {
191+ console . log ( '[gfi-assign] Skip reminder: commenter is collaborator' ) ;
192+ return ;
193+ }
194+
130195 const comments = await github . paginate (
131196 github . rest . issues . listComments ,
132197 {
0 commit comments