Skip to content

Commit 55fd43d

Browse files
committed
feat: GFIC candidate check
Signed-off-by: exploreriii <133720349+exploreriii@users.noreply.github.com>
1 parent c698bb6 commit 55fd43d

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const { gfiCandidateNotReady } =
2+
require('../lib/comments/good-first-issue-candidate-reject');
3+
4+
const GFI_CANDIDATE_LABEL = 'Good First Issue Candidate';
5+
6+
const BROWSE_URLS = {
7+
gfi:
8+
'https://github.com/hiero-ledger/hiero-sdk-python/issues' +
9+
'?q=is%3Aissue+state%3Aopen+label%3A"Good+First+Issue"+no%3Aassignee',
10+
};
11+
12+
function requestsAssignment(body) {
13+
return typeof body === 'string' && /(^|\s)\/assign(\s|$)/i.test(body);
14+
}
15+
16+
function isGfiCandidate(issue) {
17+
return (issue.labels ?? []).some(
18+
l => l.name?.toLowerCase() === GFI_CANDIDATE_LABEL.toLowerCase()
19+
);
20+
}
21+
22+
module.exports = async ({ github, context }) => {
23+
const { issue, comment } = context.payload;
24+
const { owner, repo } = context.repo;
25+
26+
if (!issue || !comment) return;
27+
if (comment.user?.type === 'Bot') return;
28+
if (!requestsAssignment(comment.body)) return;
29+
if (!isGfiCandidate(issue)) return;
30+
31+
// Prevent duplicate comments
32+
const comments = await github.paginate(
33+
github.rest.issues.listComments,
34+
{
35+
owner,
36+
repo,
37+
issue_number: issue.number,
38+
per_page: 100,
39+
}
40+
);
41+
42+
const alreadyPosted = comments.some(c =>
43+
c.body?.includes('<!-- gfi-candidate-not-ready -->')
44+
);
45+
46+
if (alreadyPosted) return;
47+
48+
await github.rest.issues.createComment({
49+
owner,
50+
repo,
51+
issue_number: issue.number,
52+
body: gfiCandidateNotReady({
53+
username: comment.user.login,
54+
browseGfiUrl: BROWSE_URLS.gfi,
55+
}),
56+
});
57+
58+
console.log('[gfi-candidate-guard] Redirected user to available GFIs', {
59+
issue: issue.number,
60+
username: comment.user.login,
61+
});
62+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const gfiCandidateNotReady = ({ username, browseGfiUrl }) => {
2+
return `
3+
<!-- gfi-candidate-not-ready -->
4+
5+
🚫 **This issue is not ready to be assigned yet**
6+
7+
@${username}, this issue is currently marked as a **Good First Issue Candidate**.
8+
9+
It is waiting for a maintainer to review and confirm that it is suitable as a **Good First Issue**.
10+
11+
### ✅ What you can do now
12+
You can browse and pick from available **Good First Issues** that are ready to be assigned:
13+
👉 ${browseGfiUrl}
14+
15+
Thank you for your interest and patience 🙏
16+
`.trim();
17+
};
18+
19+
module.exports = { gfiCandidateNotReady };
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Enforce Good First Issue Candidate Guard
2+
3+
on:
4+
issues:
5+
types:
6+
- assigned
7+
8+
permissions:
9+
issues: write
10+
contents: read
11+
12+
jobs:
13+
enforce-GFIC:
14+
runs-on: ubuntu-latest
15+
16+
concurrency:
17+
group: GFIC-assign-${{ github.event.issue.number }}
18+
cancel-in-progress: false
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
23+
24+
- name: Enforce GFIC guard
25+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd #v8.0.0
26+
with:
27+
script: |
28+
const script = require('./.github/scripts/bots/bot-good-first-issue-candidate-checker.js');
29+
await script({ github, context });

0 commit comments

Comments
 (0)