Skip to content

Commit be87bd1

Browse files
committed
fix: script
Signed-off-by: exploreriii <133720349+exploreriii@users.noreply.github.com>
1 parent 530a4c6 commit be87bd1

1 file changed

Lines changed: 28 additions & 30 deletions

File tree

.github/scripts/bots/reject-good-first-issue-candidates.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,30 @@ const BROWSE_URLS = {
99
'?q=is%3Aissue+state%3Aopen+label%3A"Good+First+Issue"+no%3Aassignee',
1010
};
1111

12-
function requestsAssignment(body) {
13-
return typeof body === 'string' && /(^|\s)\/assign(\s|$)/i.test(body);
14-
}
15-
1612
function isGfiCandidate(issue) {
1713
return (issue.labels ?? []).some(
1814
l => l.name?.toLowerCase() === GFI_CANDIDATE_LABEL.toLowerCase()
1915
);
2016
}
2117

2218
module.exports = async ({ github, context }) => {
23-
console.log('[gfi-candidate-guard] Workflow triggered', {
24-
issue: context.payload.issue?.number,
25-
commenter: context.payload.comment?.user?.login,
26-
labels: context.payload.issue?.labels?.map(l => l.name),
27-
body: context.payload.comment?.body,
28-
});
29-
30-
const { issue, comment } = context.payload;
19+
const { issue, assignee, sender } = context.payload;
3120
const { owner, repo } = context.repo;
3221

33-
if (!issue || !comment) {
34-
console.log('[gfi-candidate-guard] Exit: missing issue or comment');
35-
return;
36-
}
22+
console.log('[gfi-candidate-guard] Workflow triggered', {
23+
issue: issue?.number,
24+
assignee: assignee?.login,
25+
assignedBy: sender?.login,
26+
labels: issue?.labels?.map(l => l.name),
27+
});
3728

38-
if (comment.user?.type === 'Bot') {
39-
console.log('[gfi-candidate-guard] Exit: bot comment');
29+
if (!issue || !assignee) {
30+
console.log('[gfi-candidate-guard] Exit: missing issue or assignee');
4031
return;
4132
}
4233

43-
if (!requestsAssignment(comment.body)) {
44-
console.log('[gfi-candidate-guard] Exit: no /assign command');
34+
if (sender?.type === 'Bot') {
35+
console.log('[gfi-candidate-guard] Exit: bot actor');
4536
return;
4637
}
4738

@@ -50,12 +41,21 @@ module.exports = async ({ github, context }) => {
5041
return;
5142
}
5243

53-
console.log('[gfi-candidate-guard] GFI candidate assignment attempted', {
44+
console.log('[gfi-candidate-guard] Invalid assignment detected', {
5445
issue: issue.number,
55-
username: comment.user.login,
46+
assignee: assignee.login,
47+
assignedBy: sender.login,
48+
});
49+
50+
// 🚨 ENFORCEMENT: remove the assignee
51+
await github.rest.issues.removeAssignees({
52+
owner,
53+
repo,
54+
issue_number: issue.number,
55+
assignees: [assignee.login],
5656
});
5757

58-
// Prevent duplicate comments
58+
// Prevent duplicate rejection comments
5959
const comments = await github.paginate(
6060
github.rest.issues.listComments,
6161
{
@@ -71,29 +71,27 @@ module.exports = async ({ github, context }) => {
7171
);
7272

7373
if (alreadyPosted) {
74-
console.log('[gfi-candidate-guard] Exit: rejection already posted', {
75-
issue: issue.number,
76-
});
74+
console.log('[gfi-candidate-guard] Exit: rejection already posted');
7775
return;
7876
}
7977

8078
console.log('[gfi-candidate-guard] Posting rejection comment', {
8179
issue: issue.number,
82-
username: comment.user.login,
80+
username: assignee.login,
8381
});
8482

8583
await github.rest.issues.createComment({
8684
owner,
8785
repo,
8886
issue_number: issue.number,
8987
body: gfiCandidateNotReady({
90-
username: comment.user.login,
88+
username: assignee.login,
9189
browseGfiUrl: BROWSE_URLS.gfi,
9290
}),
9391
});
9492

95-
console.log('[gfi-candidate-guard] Redirected user to available GFIs', {
93+
console.log('[gfi-candidate-guard] Assignment reverted and user notified', {
9694
issue: issue.number,
97-
username: comment.user.login,
95+
username: assignee.login,
9896
});
9997
};

0 commit comments

Comments
 (0)