Skip to content

Commit 56e6ed3

Browse files
authored
fix: update next-issue recommendation bot comment logic (#1617)
Signed-off-by: Parv Ninama <[email protected]> Signed-off-by: Parv <[email protected]>
1 parent 14cda1e commit 56e6ed3

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

.github/scripts/bot-next-issue-recommendation.js

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,41 @@ module.exports = async ({ github, context, core }) => {
6969
}
7070

7171
let recommendedIssues = [];
72+
let recommendedLabel = null;
73+
let isFallback = false;
74+
let recommendationScope = 'repo';
7275

73-
if (difficultyLevels.goodFirstIssue) {
74-
// Recommend beginner issues first, then Good First Issues
75-
recommendedIssues = await searchIssues(github, core, repoOwner, repoName, 'beginner');
76-
if (recommendedIssues.length === 0) {
77-
recommendedIssues = await searchIssues(github, core, repoOwner, repoName, 'good first issue');
78-
}
79-
} else if (difficultyLevels.beginner) {
80-
// Recommend beginner or Good First Issues
81-
recommendedIssues = await searchIssues(github, core, repoOwner, repoName, 'beginner');
82-
if (recommendedIssues.length === 0) {
83-
recommendedIssues = await searchIssues(github, core, repoOwner, repoName, 'good first issue');
84-
}
76+
recommendedIssues = await searchIssues(github, core, repoOwner, repoName, 'beginner');
77+
recommendedLabel = 'Beginner';
78+
79+
if (recommendedIssues.length === 0) {
80+
isFallback = true;
81+
recommendedIssues = await searchIssues(github, core, repoOwner, repoName, 'good first issue');
82+
recommendedLabel = 'Good First Issue';
83+
}
84+
85+
if (recommendedIssues.length === 0) {
86+
recommendationScope = 'org';
87+
recommendedLabel = 'Good First Issue';
88+
recommendedIssues = await github.rest.search.issuesAndPullRequests({
89+
q: `org:hiero-ledger type:issue state:open label:"good first issue" no:assignee`,
90+
per_page: 6,
91+
}).then(res => res.data.items);
8592
}
93+
94+
// Remove the issue they just solved
95+
recommendedIssues = recommendedIssues.filter(i => i.number !== issueNumber);
8696

8797
// Generate and post comment
88-
await generateAndPostComment(github, context, core, prNumber, recommendedIssues, difficultyLevels.goodFirstIssue);
98+
const completedLabel = difficultyLevels.goodFirstIssue ? 'Good First Issue' : 'Beginner';
99+
const completedLabelText = completedLabel === 'Beginner' ? 'Beginner issue' : completedLabel;
100+
const recommendationMeta = {
101+
completedLabelText,
102+
recommendedLabel,
103+
isFallback,
104+
recommendationScope,
105+
};
106+
await generateAndPostComment(github, context, core, prNumber, recommendedIssues, recommendationMeta);
89107

90108
} catch (error) {
91109
core.setFailed(`Error processing issue #${issueNumber}: ${error.message}`);
@@ -94,12 +112,12 @@ module.exports = async ({ github, context, core }) => {
94112

95113
async function searchIssues(github, core, owner, repo, label) {
96114
try {
97-
const query = `repo:${owner}/${repo} is:issue is:open label:"${label}" no:assignee`;
115+
const query = `repo:${owner}/${repo} type:issue state:open label:"${label}" no:assignee`;
98116
core.info(`Searching for issues with query: ${query}`);
99117

100118
const { data: searchResult } = await github.rest.search.issuesAndPullRequests({
101119
q: query,
102-
per_page: 5,
120+
per_page: 6,
103121
});
104122

105123
core.info(`Found ${searchResult.items.length} issues with label "${label}"`);
@@ -110,15 +128,21 @@ async function searchIssues(github, core, owner, repo, label) {
110128
}
111129
}
112130

113-
async function generateAndPostComment(github, context, core, prNumber, recommendedIssues, wasGoodFirstIssue) {
131+
async function generateAndPostComment(github, context, core, prNumber, recommendedIssues, { completedLabelText, recommendedLabel, isFallback, recommendationScope }) {
114132
const marker = '<!-- next-issue-bot-marker -->';
115133

116134
// Build comment content
117-
let comment = `${marker}\n\n🎉 **Congratulations on completing a beginner/Good First Issue!**\n\n`;
135+
let comment = `${marker}\n\n🎉 **Nice work completing a ${completedLabelText}!**\n\n`;
118136
comment += `Thank you for your contribution to the Hiero Python SDK! We're excited to have you as part of our community.\n\n`;
119137

120138
if (recommendedIssues.length > 0) {
121-
comment += `Here are some ${wasGoodFirstIssue ? 'beginner-level' : 'similar'} issues you might be interested in working on next:\n\n`;
139+
if (recommendationScope === 'org') {
140+
comment += `Here are some **Good First Issues across the Hiero organization** you might be interested in working on next:\n\n`;
141+
} else if (isFallback) {
142+
comment += `Here are some **${recommendedLabel}** issues at a similar level you might be interested in working on next:\n\n`;
143+
} else {
144+
comment += `Here are some issues labeled **${recommendedLabel}** you might be interested in working on next:\n\n`;
145+
}
122146

123147
// Sanitize title: escape markdown link syntax and special characters
124148
const sanitizeTitle = (title) => title
@@ -143,8 +167,11 @@ async function generateAndPostComment(github, context, core, prNumber, recommend
143167
}
144168
});
145169
} else {
146-
comment += `There are currently no open ${wasGoodFirstIssue ? 'beginner' : 'similar'} issues in this repository. \n\n`;
147-
comment += `You can check out good first issues across the entire Hiero organization: [Hiero Good First Issues](https://github.com/issues?q=is%3Aopen+is%3Aissue+org%3Ahiero-ledger+archived%3Afalse+label%3A%22good+first+issue%22+)\n\n`;
170+
comment += `There are currently no open issues available at or near the ${completedLabelText} level in this repository.\n\n`;
171+
const orgLabel = recommendedLabel === 'Beginner' ? 'beginner' : 'good first issue';
172+
const orgLabelQuery = encodeURIComponent(`label:"${orgLabel}"`);
173+
comment += `You can check out ${recommendedLabel.toLowerCase()} issues across the entire Hiero organization: ` +
174+
`[Hiero ${recommendedLabel} Issues](https://github.com/issues?q=org%3Ahiero-ledger+type%3Aissue+state%3Aopen+${orgLabelQuery})\n\n`;
148175
}
149176

150177
comment += `🌟 **Stay connected with the project:**\n`;

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
220220
- Formatted key-related unit test files (`key_utils_test.py`, `test_key_format.py`, `test_key_list.py`) using the black formatter
221221

222222
### Fixed
223-
223+
- Fix the next-issue recommendation bot to post the correct issue recommendation comment. (#1593)
224224
- Ensured that the GFI assignment bot skips posting `/assign` reminders for repository collaborators to avoid unnecessary notifications.(#1568).
225225
- Reduced notification spam by skipping the entire advanced qualification job for non-advanced issues and irrelevant events (#1517)
226226
- Aligned token freeze example filename references and improved error handling by catching broader exceptions with clearer messages. (#1412)

0 commit comments

Comments
 (0)