|
| 1 | +// Script to notify the team when a Good First Issue Candidate is created. |
| 2 | + |
| 3 | +const marker = '<!-- GFI Candidate Notification -->'; |
| 4 | +const TEAM_ALIAS = '@hiero-ledger/hiero-sdk-good-first-issue-support'; |
| 5 | + |
| 6 | + |
| 7 | +async function notifyTeam(github, owner, repo, issue, message) { |
| 8 | + const dryRun = process.env.DRY_RUN === 'true'; |
| 9 | + if (dryRun) { |
| 10 | + console.log('Notified team about GFI candidate'); |
| 11 | + console.log(`Repo: ${owner}/${repo}`); |
| 12 | + console.log(`Issue: #${issue.number} - ${issue.title}`); |
| 13 | + console.log(`Message:\n${message}`); |
| 14 | + return true; |
| 15 | + } |
| 16 | + const comment = `${marker} :wave: Hello Team :wave: |
| 17 | +${TEAM_ALIAS} |
| 18 | +
|
| 19 | +${message} |
| 20 | +
|
| 21 | +Repository: ${owner}/${repo} |
| 22 | +Issue: #${issue.number} - ${issue.title || '(no title)'} |
| 23 | +
|
| 24 | +Best Regards, |
| 25 | +Hiero Python SDK team`; |
| 26 | + |
| 27 | + try { |
| 28 | + await github.rest.issues.createComment({ |
| 29 | + owner, |
| 30 | + repo, |
| 31 | + issue_number: issue.number, |
| 32 | + body: comment, |
| 33 | + }); |
| 34 | + console.log(`Notified team about #${issue.number}`); |
| 35 | + return true; |
| 36 | + } catch (err) { |
| 37 | + console.log( |
| 38 | + `Failed to notify team about GFI candidate #${issue.number}:`, |
| 39 | + err.message || err |
| 40 | + ); |
| 41 | + return false; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +module.exports = async ({ github, context }) => { |
| 46 | + try { |
| 47 | + const { owner, repo } = context.repo; |
| 48 | + const { issue, label } = context.payload; |
| 49 | + const dryRun = process.env.DRY_RUN === 'true'; |
| 50 | + |
| 51 | + if (!issue?.number || !label?.name) { |
| 52 | + return console.log('Missing issue or label in payload'); |
| 53 | + } |
| 54 | + |
| 55 | + // Only handle Good First Issue Candidate |
| 56 | + if (label.name.toLowerCase() !== 'good first issue candidate') { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + // Checking dry run |
| 61 | + dryRun && console.log('DRY-RUN active'); |
| 62 | + |
| 63 | + // Prevent duplicate notifications |
| 64 | + const comments = await github.paginate( |
| 65 | + github.rest.issues.listComments, |
| 66 | + { owner, repo, issue_number: issue.number, per_page: 100 } |
| 67 | + ); |
| 68 | + |
| 69 | + if (comments.some(c => c.body?.includes(marker))) { |
| 70 | + return console.log(`Notification already exists for #${issue.number}`); |
| 71 | + } |
| 72 | + |
| 73 | + const message = |
| 74 | + 'A new Good First Issue Candidate has been created. Please review it and confirm whether it should be labeled as a Good First Issue.'; |
| 75 | + |
| 76 | + const success = await notifyTeam(github, owner, repo, issue, message); |
| 77 | + |
| 78 | + if (success) { |
| 79 | + console.log('=== Summary ==='); |
| 80 | + console.log(`Repository: ${owner}/${repo}`); |
| 81 | + console.log(`Issue Number: ${issue.number}`); |
| 82 | + console.log(`Label: ${label.name}`); |
| 83 | + } |
| 84 | + } catch (err) { |
| 85 | + console.log('❌ Error:', err.message); |
| 86 | + throw err; |
| 87 | + } |
| 88 | +}; |
0 commit comments