@@ -250,6 +250,83 @@ Automatically generated by Auggie Assistant`;
250250 core . info ( '✅ Changes committed and pushed successfully' ) ;
251251}
252252
253+ /**
254+ * Create a new branch, commit changes, and create a PR targeting the original PR
255+ */
256+ async function createPRForChanges (
257+ commentId : number ,
258+ headBranch : string ,
259+ githubToken : string ,
260+ owner : string ,
261+ repo : string ,
262+ prNumber : number ,
263+ octokit : Octokit
264+ ) : Promise < { newBranch: string ; newPrNumber: number } > {
265+ core. info ( '📝 Creating new branch for PR...' ) ;
266+
267+ // Stage all changes
268+ await exec . exec ( 'git' , [ 'add' , '-A' ] ) ;
269+
270+ // Check if there are changes to commit using git status
271+ let statusOutput = '' ;
272+ await exec . exec ( 'git' , [ 'status' , '--porcelain' ] , {
273+ listeners : {
274+ stdout : ( data : Buffer ) => {
275+ statusOutput += data . toString ( ) ;
276+ } ,
277+ } ,
278+ } ) ;
279+
280+ const hasChanges = statusOutput . trim ( ) . length > 0 ;
281+
282+ if ( ! hasChanges ) {
283+ core . info ( 'ℹ️ No changes to commit' ) ;
284+ throw new Error ( 'No changes to create PR with' ) ;
285+ }
286+
287+ core . info ( `📝 Changes detected:\n${ statusOutput } ` ) ;
288+
289+ // Create a new branch name based on the comment ID
290+ const newBranch = `auggie/pr-${ prNumber } -comment-${ commentId } ` ;
291+ core . info ( `🌿 Creating new branch: ${ newBranch } ` ) ;
292+
293+ // Create and checkout new branch
294+ await exec . exec ( 'git' , [ 'checkout' , '-b' , newBranch ] ) ;
295+
296+ // Commit changes
297+ const commitMessage = `feat: implement changes requested in comment #${ commentId }
298+
299+ Automatically generated by Auggie Assistant` ;
300+
301+ await exec . exec ( 'git' , [ 'commit' , '-m' , commitMessage ] ) ;
302+
303+ // Push new branch
304+ core . info ( `🚀 Pushing to ${ newBranch } ...` ) ;
305+ const remoteUrl = `https://x-access-token:${ githubToken } @github.com/${ owner } /${ repo } .git` ;
306+ await exec . exec ( 'git' , [ 'push' , remoteUrl , `HEAD:${ newBranch } ` ] ) ;
307+
308+ core . info ( '✅ Changes committed and pushed to new branch' ) ;
309+
310+ // Create PR targeting the original PR's branch
311+ core . info ( `📬 Creating PR targeting ${ headBranch } ...` ) ;
312+ const { data : newPr } = await octokit . rest . pulls . create ( {
313+ owner,
314+ repo,
315+ title : `Changes from comment #${ commentId } on PR #${ prNumber } ` ,
316+ body : `This PR contains changes requested in [comment #${ commentId } ](https://github.com/${ owner } /${ repo } /pull/${ prNumber } #issuecomment-${ commentId } ) on PR #${ prNumber } .
317+
318+ Automatically generated by Auggie Assistant.
319+
320+ **Target Branch:** \`${ headBranch } \` (from PR #${ prNumber } )` ,
321+ head : newBranch ,
322+ base : headBranch ,
323+ } ) ;
324+
325+ core . info ( `✅ Created PR #${ newPr . number } ` ) ;
326+
327+ return { newBranch, newPrNumber : newPr . number } ;
328+ }
329+
253330/**
254331 * Invoke Auggie to implement changes
255332 */
@@ -395,6 +472,7 @@ async function main(): Promise<void> {
395472 const githubToken = getInput ( 'github_token' , true ) ;
396473 const commentIdStr = getInput ( 'comment_id' , true ) ;
397474 const eventName = getInput ( 'event_name' , true ) ;
475+ const commentBody = getInput ( 'comment_body' , false ) ;
398476
399477 // Validate inputs
400478 const commentId = Number . parseInt ( commentIdStr , 10 ) ;
@@ -407,10 +485,20 @@ async function main(): Promise<void> {
407485 // Create Octokit instance
408486 const octokit = new Octokit ( { auth : githubToken } ) ;
409487
410- // Note: Reaction is added in action.yml for immediate feedback
488+ // Detect command type (/commit or /pr)
489+ const isPrCommand = commentBody . includes ( '/pr' ) ;
490+ const isCommitCommand = commentBody . includes ( '/commit' ) ;
491+
492+ if ( ! isPrCommand && ! isCommitCommand ) {
493+ core . info ( 'ℹ️ No /commit or /pr command found in comment' ) ;
494+ core . setOutput ( 'success' , 'true' ) ;
495+ return ;
496+ }
497+
411498 core . info ( `🎯 Starting PR Assistant for comment ${ commentId } ` ) ;
412499 core . info ( `📦 Repository: ${ owner } /${ repo } ` ) ;
413500 core . info ( `📝 Event: ${ eventName } ` ) ;
501+ core . info ( `🔧 Command: ${ isPrCommand ? '/pr' : '/commit' } ` ) ;
414502
415503 // Step 2: Get PR number
416504 core . info ( '🔍 Finding associated PR...' ) ;
@@ -435,29 +523,66 @@ async function main(): Promise<void> {
435523 try {
436524 await invokeAuggie ( context ) ;
437525
438- // Step 6: Commit and push changes
439- await commitAndPush ( commentId , context . headBranch , githubToken , owner , repo ) ;
526+ // Step 6: Commit and push changes (different behavior for /pr vs /commit)
527+ if ( isPrCommand ) {
528+ // For /pr: create a new branch and PR targeting the original PR
529+ const { newPrNumber } = await createPRForChanges (
530+ commentId ,
531+ context . headBranch ,
532+ githubToken ,
533+ owner ,
534+ repo ,
535+ prNumber ,
536+ octokit
537+ ) ;
538+
539+ // Step 7: Add success comment to original PR
540+ const quotedComment = context . commentBody
541+ . split ( '\n' )
542+ . map ( line => `> ${ line } ` )
543+ . join ( '\n' ) ;
544+
545+ await addPRComment (
546+ octokit ,
547+ owner ,
548+ repo ,
549+ prNumber ,
550+ `${ quotedComment }
551+
552+ ✅ Successfully implemented the requested changes!
440553
441- // Step 7: Add success comment to PR
442- const quotedComment = context . commentBody
443- . split ( '\n' )
444- . map ( line => `> ${ line } ` )
445- . join ( '\n' ) ;
554+ Created PR #${ newPrNumber } with the changes targeting \`${ context . headBranch } \`.
446555
447- await addPRComment (
448- octokit ,
449- owner ,
450- repo ,
451- prNumber ,
452- `${ quotedComment }
556+ 👉 [View the new PR](https://github.com/${ owner } /${ repo } /pull/${ newPrNumber } )`
557+ ) ;
558+
559+ core . info ( `✨ PR Assistant completed successfully - created PR #${ newPrNumber } ` ) ;
560+ } else {
561+ // For /commit: commit directly to the PR branch (existing behavior)
562+ await commitAndPush ( commentId , context . headBranch , githubToken , owner , repo ) ;
563+
564+ // Step 7: Add success comment to PR
565+ const quotedComment = context . commentBody
566+ . split ( '\n' )
567+ . map ( line => `> ${ line } ` )
568+ . join ( '\n' ) ;
569+
570+ await addPRComment (
571+ octokit ,
572+ owner ,
573+ repo ,
574+ prNumber ,
575+ `${ quotedComment }
453576
454577✅ Successfully implemented the requested changes!
455578
456579The changes have been committed to the \`${ context . headBranch } \` branch.`
457- ) ;
580+ ) ;
581+
582+ core . info ( '✨ PR Assistant completed successfully' ) ;
583+ }
458584
459585 core . setOutput ( 'success' , 'true' ) ;
460- core . info ( '✨ PR Assistant completed successfully' ) ;
461586 } catch ( error ) {
462587 // Add failure comment to PR
463588 const quotedComment = context . commentBody
0 commit comments