Skip to content

Commit 5246fc6

Browse files
authored
fix: prevent LinkBot from posting duplicate missing-issue comments (hiero-ledger#1475)
Signed-off-by: Parv Ninama <[email protected]>
1 parent 1d28ad7 commit 5246fc6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.github/scripts/bot-pr-missing-linked-issue.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
const LINKBOT_MARKER = '<!-- LinkBot Missing Issue -->';
2+
13
module.exports = async ({ github, context }) => {
24
let prNumber;
35
try {
46
const isDryRun = process.env.DRY_RUN === 'true';
5-
prNumber = parseInt(process.env.PR_NUMBER) || context.payload.pull_request.number;
7+
prNumber = Number(process.env.PR_NUMBER) || context.payload.pull_request?.number;
8+
9+
if (!prNumber) {
10+
throw new Error('PR number could not be determined');
11+
}
612

713
console.log(`Processing PR #${prNumber} (Dry run: ${isDryRun})`);
814

@@ -38,7 +44,7 @@ module.exports = async ({ github, context }) => {
3844
});
3945

4046
const alreadyCommented = comments.data.some(comment =>
41-
comment.body.includes("this is LinkBot")
47+
comment.body?.includes(LINKBOT_MARKER)
4248
);
4349

4450
if (alreadyCommented) {
@@ -47,8 +53,9 @@ module.exports = async ({ github, context }) => {
4753
}
4854

4955
if (!regex.test(body)) {
50-
const commentBody = [
51-
`Hi @${prData.user.login}, this is **LinkBot** 👋`,
56+
const safeAuthor = authorLogin ?? 'there' ;
57+
const commentBody = [ `${LINKBOT_MARKER}` +
58+
`Hi @${safeAuthor}, this is **LinkBot** 👋`,
5259
``,
5360
`Linking pull requests to issues helps us significantly with reviewing pull requests and keeping the repository healthy.`,
5461
``,

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
173173
- Enhance TopicInfo `__str__` method and tests with additional coverage, and update the format_key function in `key_format.py` to handle objects with a _to_proto method.
174174

175175
### Fixed
176+
- Prevent LinkBot from posting duplicate “missing linked issue” comments on pull requests. (#1475)
176177
- Refined intermediate assignment guard to validate Beginner issue completion with improved logging and GraphQL-based counting. (#1424)
177178
- Improved filename-related error handling with clearer and more descriptive error messages.(#1413)
178179
- Good First Issue bot no longer posts `/assign` reminders for repository collaborators. (#1367)

0 commit comments

Comments
 (0)