| 245 | } |
| 246 | |
| 247 | async function commentOnIssue(issueNumber, prNumbers, packages) { |
| 248 | const packageList = packages |
| 249 | .map((p) => `- \`${p.name}@${p.version}\``) |
| 250 | .join(`\n`) |
| 251 | |
| 252 | const prLinks = prNumbers.map((pr) => `#${pr}`).join(`, `) |
| 253 | const prWord = prNumbers.length === 1 ? `PR` : `PRs` |
| 254 | |
| 255 | const body = `The ${prWord} fixing this issue (${prLinks}) has been released! :rocket: |
| 256 | |
| 257 | The following packages include the fix: |
| 258 | |
| 259 | ${packageList} |
| 260 | |
| 261 | Thanks for reporting!` |
| 262 | |
| 263 | try { |
| 264 | // Check if we already commented on this issue |
| 265 | const existingComments = execSync( |
| 266 | `gh api repos/${REPO}/issues/${issueNumber}/comments --jq '[.[] | select(.body | contains("A fix for this issue has been released!"))] | length'`, |
| 267 | { encoding: `utf8`, stdio: [`pipe`, `pipe`, `pipe`] } |
| 268 | ).trim() |
| 269 | |
| 270 | if (parseInt(existingComments, 10) > 0) { |
| 271 | console.log(` Already commented on issue #${issueNumber}, skipping`) |
| 272 | return |
| 273 | } |
| 274 | |
| 275 | // Use --body-file with stdin to avoid shell interpretation of backticks |
| 276 | execSync(`gh issue comment ${issueNumber} --repo ${REPO} --body-file -`, { |
| 277 | input: body, |
| 278 | encoding: `utf8`, |
| 279 | stdio: [`pipe`, `inherit`, `inherit`], |
| 280 | }) |
| 281 | console.log(` Commented on issue #${issueNumber}`) |
| 282 | } catch (e) { |
| 283 | console.error(` Failed to comment on issue #${issueNumber}:`, e.message) |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | main().catch((e) => { |
| 288 | console.error(e) |