Skip to content

Commit cd9ca69

Browse files
ci: notify GFI support team only after first issue comment (hiero-ledger#1258)
Signed-off-by: undefinedIsMyLife <[email protected]>
1 parent 011f388 commit cd9ca69

File tree

3 files changed

+79
-40
lines changed

3 files changed

+79
-40
lines changed

.github/scripts/gfi_notify_team.js

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,105 @@
1-
// Script to notify the team when a GFI issue is labeled.
1+
// Script to notify the team when a GFI issue receives its first human comment.
22

33
const marker = '<!-- GFI Issue Notification -->';
44
const TEAM_ALIAS = '@hiero-ledger/hiero-sdk-good-first-issue-support';
55

6-
async function notifyTeam(github, owner, repo, issue, message, marker) {
7-
const comment = `${marker} :wave: Hello Team :wave:
6+
async function notifyTeam(github, owner, repo, issue, message) {
7+
const commentBody = `${marker} :wave: Hello Team :wave:
88
${TEAM_ALIAS}
99
1010
${message}
1111
12-
Repository: ${owner}/${repo} : Issue: #${issue.number} - ${issue.title || '(no title)'}
12+
Repository: ${owner}/${repo}
13+
Issue: #${issue.number} - ${issue.title || '(no title)'}
1314
14-
Best Regards,
15+
Best Regards,
1516
Python SDK team`;
1617

1718
try {
1819
await github.rest.issues.createComment({
1920
owner,
2021
repo,
2122
issue_number: issue.number,
22-
body: comment,
23+
body: commentBody,
2324
});
24-
console.log(`Notified team about GFI issue #${issue.number}`);
25+
console.log(`Notified team about GFI issue #${issue.number}`);
2526
return true;
26-
} catch (commentErr) {
27-
console.log(`Failed to notify team about GFI issue #${issue.number}:`, commentErr.message || commentErr);
27+
} catch (err) {
28+
console.log(`Failed to notify team for #${issue.number}:`, err.message);
2829
return false;
2930
}
3031
}
3132

3233
module.exports = async ({ github, context }) => {
34+
console.log('Context debug:', {
35+
actor: context.actor,
36+
eventName: context.eventName,
37+
repo: context.repo,
38+
});
39+
3340
try {
3441
const { owner, repo } = context.repo;
35-
const { issue, label } = context.payload;
42+
const { issue, comment } = context.payload;
43+
44+
if (!issue?.number || !comment) {
45+
return console.log('No issue or comment found in payload');
46+
}
3647

37-
if (!issue?.number) return console.log('No issue in payload');
48+
// Ignore bot comments
49+
if (comment.user?.type === 'Bot') {
50+
return console.log('Ignoring bot comment');
51+
}
3852

39-
const labelName = label?.name;
40-
if (!labelName) return;
53+
const labels = issue.labels?.map(l => l.name) || [];
54+
55+
const isGFI = labels.includes('good first issue')
4156

42-
let message = '';
43-
if (labelName === 'Good First Issue') {
44-
message = 'There is a new GFI in the Python SDK which is ready to be assigned';
45-
} else if (labelName === 'Good First Issue Candidate') {
46-
message = 'An issue in the Python SDK requires immediate attention to verify if it is a GFI and label it appropriately';
47-
} else {
48-
return;
57+
if (!isGFI) {
58+
return console.log('Issue is not a GFI');
4959
}
5060

51-
// Check for existing comment
52-
const comments = await github.paginate(github.rest.issues.listComments, {
53-
owner, repo, issue_number: issue.number, per_page: 100
54-
});
61+
// Skip if already assigned
62+
if (issue.assignees && issue.assignees.length > 0) {
63+
return console.log('Issue already assigned');
64+
}
65+
66+
// Fetch all issue comments
67+
const comments = await github.paginate(
68+
github.rest.issues.listComments,
69+
{
70+
owner,
71+
repo,
72+
issue_number: issue.number,
73+
per_page: 100,
74+
}
75+
);
76+
77+
// Skip if notification already exists
5578
if (comments.some(c => c.body?.includes(marker))) {
5679
return console.log(`Notification already exists for #${issue.number}`);
5780
}
5881

59-
// Post notification
60-
const success = await notifyTeam(github, owner, repo, issue, message, marker);
82+
// Check if this is the FIRST non-bot comment
83+
const earlierNonBotComments = comments.filter(c =>
84+
c.id !== comment.id &&
85+
c.user?.type !== 'Bot'
86+
);
6187

62-
if (success) {
63-
console.log('=== Summary ===');
64-
console.log(`Repository: ${owner}/${repo}`);
65-
console.log(`Issue Number: ${issue.number}`);
66-
console.log(`Label: ${labelName}`);
67-
console.log(`Message: ${message}`);
88+
if (earlierNonBotComments.length > 0) {
89+
return console.log('Not the first non-bot comment, skipping');
6890
}
6991

92+
const message = `@${comment.user.login} commented on this **Good First Issue** and may be ready to be assigned. Please review and assign if appropriate.`;
93+
94+
95+
await notifyTeam(github, owner, repo, issue, message);
96+
97+
console.log('=== Summary ===');
98+
console.log(`Repository: ${owner}/${repo}`);
99+
console.log(`Issue Number: ${issue.number}`);
100+
console.log(`Triggered by: @${comment.user.login}`);
101+
console.log(`Message: ${message}`);
70102
} catch (err) {
71-
console.log('❌ Error:', err.message);
103+
console.log('❌ Error:', err.message);
72104
}
73105
};

.github/workflows/bot-gfi-notify-team.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# This workflow notifies the GFI support team when an issue is labeled as a GFI or GFI Candidate.
22
name: GFI Issue Notification
33
on:
4-
issues:
4+
issue_comment:
55
types:
6-
- labeled
6+
- created
77

88
permissions:
99
issues: write
@@ -13,11 +13,17 @@ jobs:
1313
gfi_notify_team:
1414
runs-on: ubuntu-latest
1515
if: >
16-
(github.event_name == 'issues' && (
17-
github.event.label.name == 'Good First Issue' ||
18-
github.event.label.name == 'Good First Issue Candidate'
19-
))
16+
github.event.issue.labels &&
17+
contains(
18+
join(github.event.issue.labels.*.name, ','),
19+
'Good First Issue'
20+
)
2021
22+
23+
concurrency:
24+
group: gfi-notify-issue-${{ github.event.issue.number }}
25+
cancel-in-progress: false
26+
2127
steps:
2228
- name: Harden the runner
2329
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Changelog
1+
# Changelog
22

33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org).
@@ -76,6 +76,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
7676
- Added merge conflict bot workflow (`.github/workflows/bot-merge-conflict.yml`) and helper script (`.github/scripts/bot-merge-conflict.js`) to detect and notify about PR merge conflicts, with retry logic for unknown mergeable states, idempotent commenting, and push-to-main recheck logic (#1247)
7777

7878
### Changed
79+
- Updated Good First Issue notifications to trigger only after the first comment is posted, reducing noise on unassigned issues.(#1212)
7980
- Bumped requests from 2.32.3 to 2.32.4 to 2.32.5
8081
- Moved `docs/sdk_developers/how_to_link_issues.md` to `docs/sdk_developers/training/workflow/how_to_link_issues.md` and updated all references (#1222)
8182
- Moved docs/sdk_developers/project_structure.md to docs/sdk_developers/training/setup/project_structure.md and ensured all previous references are updated [#1223](https://github.com/hiero-ledger/hiero-sdk-python/issues/1223)

0 commit comments

Comments
 (0)