@@ -3,7 +3,7 @@ import {promises as fsp} from 'fs';
33import os from 'os' ;
44import path from 'path' ;
55import { 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
1919program
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 = / G H t i c k e t i d : # \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