Skip to content

Commit 5a7495c

Browse files
authored
Merge pull request #7380 from LemonDrop847/feat/issue-creation-script-sync-ghID-to-MD
feat:issue creation script to Sync GitHub ID back to Markdown File (fixes: #7368)
2 parents 348d2ad + 45f6a17 commit 5a7495c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

buildScripts/ai/createGhIssue.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {promises as fsp} from 'fs';
33
import os from 'os';
44
import path from 'path';
55
import {spawnSync} from 'child_process';
6-
import {Command} from 'commander/esm.mjs';
6+
import { Command } from 'commander/esm.mjs';
77

88
/**
99
* @summary Automates GitHub issue creation from local ticket markdown files.
@@ -18,7 +18,6 @@ const program = new Command();
1818

1919
program
2020
.name('neo-ai-create-gh-issue')
21-
.version(process.env.npm_package_version)
2221
.argument('<ticketPath>', 'Path to the local markdown ticket file')
2322
.option('-r, --repo <value>', 'Optional GitHub repository in owner/name format')
2423
.parse(process.argv);
@@ -74,7 +73,7 @@ if (!ticketPath) {
7473

7574
console.log(`Created GitHub issue #${issueNumber}: ${issueUrl}`);
7675

77-
const updatedBody = prependIssueMetadata(frontmatterBlock, bodyContent, issueNumber, issueUrl);
76+
const updatedBody = updateIssueMetadata(frontmatterBlock, bodyContent, issueNumber, issueUrl);
7877
const updatedContent = ensureTrailingNewline(updatedBody);
7978

8079
const fileDir = path.dirname(absoluteTicketPath);
@@ -208,10 +207,18 @@ function extractIssueNumber(issueUrl, stdout, stderr) {
208207
throw new Error('Unable to determine issue number from GitHub CLI output.');
209208
}
210209

211-
function prependIssueMetadata(frontmatterBlock, bodyContent, issueNumber, issueUrl) {
210+
function updateIssueMetadata(frontmatterBlock, bodyContent, issueNumber, issueUrl) {
211+
const placeholderRegex = /GH ticket id: #\d+/;
212212
const cleanedBody = prepareBodyForIssue(bodyContent);
213-
const metadata = `# GitHub Issue: #${issueNumber}\n# ${issueUrl}\n\n`;
214213

214+
if (placeholderRegex.test(cleanedBody)) {
215+
const replacementText = `GH ticket id: #${issueNumber}\nGH ticket url: ${issueUrl}`;
216+
const updatedBodyContent = cleanedBody.replace(placeholderRegex, replacementText);
217+
return `${frontmatterBlock}${updatedBodyContent}`;
218+
}
219+
220+
// Fallback to prepending if the placeholder is not found
221+
const metadata = `# GitHub Issue: #${issueNumber}\n# ${issueUrl}\n\n`;
215222
return `${frontmatterBlock}${metadata}${cleanedBody}`;
216223
}
217224

0 commit comments

Comments
 (0)