Skip to content

Commit a4a4696

Browse files
authored
fix: skip /assign reminder for repository collaborators [(hiero-ledger#1367)] (hiero-ledger#1420)
Signed-off-by: Parv Ninama <ninamaparv@gmail.com>
1 parent ea81547 commit a4a4696

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,57 @@ If you’d like to work on this **Good First Issue**, just comment:
8484
and 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 ///
88139
module.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
{

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
158158
- Modified and renamed hasIntermediateOrAdvancedLabel() to check if issue label is beginner or higher (#1385)
159159

160160
### Fixed
161+
- Good First Issue bot no longer posts `/assign` reminders for repository collaborators. (#1367)
161162
- GFI workflow casing
162163
- Update `bot-workflows.yml` to trigger only on open PRs with failed workflows; ignore closed PRs and branches without open PRs.
163164
- Fixed step-security/harden-runner action SHA in merge conflict bot workflow (#1278)

0 commit comments

Comments
 (0)