44
55const fs = require ( 'fs' ) ;
66
7- async function getIssueInfo ( github , context , inputs ) {
7+ async function getIssueInfo ( github , repo , inputs , eventName , payload ) {
88 let issueId ;
99
10- if ( context . eventName === 'workflow_dispatch' ) {
10+ if ( eventName === 'workflow_dispatch' ) {
1111 issueId = inputs . issue_id ;
1212 } else {
1313 // Handle both issue comments and PR comments
14- issueId = ( context . payload . issue ?. number || context . payload . pull_request ?. number ) ?. toString ( ) ;
14+ issueId = ( payload . issue ?. number || payload . pull_request ?. number ) ?. toString ( ) ;
1515 }
1616
1717 const command =
18- context . eventName === 'workflow_dispatch'
18+ eventName === 'workflow_dispatch'
1919 ? inputs . command
20- : context . payload . comment . body . match ( / ^ \/ s t r a n d s \s * ( .* ) $ / ) ?. [ 1 ] ?. trim ( ) || '' ;
20+ : payload . comment . body . match ( / ^ \/ s t r a n d s \s * ( .* ) $ / ) ?. [ 1 ] ?. trim ( ) || '' ;
2121
22- console . log ( `Event: ${ context . eventName } , Issue ID: ${ issueId } , Command: "${ command } "` ) ;
22+ console . log ( `Event: ${ eventName } , Issue ID: ${ issueId } , Command: "${ command } "` ) ;
2323
2424 const issue = await github . rest . issues . get ( {
25- owner : context . repo . owner ,
26- repo : context . repo . repo ,
25+ owner : repo . owner ,
26+ repo : repo . repo ,
2727 issue_number : issueId ,
2828 } ) ;
2929
3030 return { issueId, command, issue } ;
3131}
3232
33- async function determineBranch ( github , context , issueId , mode , isPullRequest ) {
33+ async function determineBranch ( github , repo , issueId , mode , isPullRequest ) {
3434 let branchName = 'main' ;
3535
3636 if ( mode === 'implementer' && ! isPullRequest ) {
3737 branchName = `agent-tasks/${ issueId } ` ;
3838
3939 const mainRef = await github . rest . git . getRef ( {
40- owner : context . repo . owner ,
41- repo : context . repo . repo ,
40+ owner : repo . owner ,
41+ repo : repo . repo ,
4242 ref : 'heads/main' ,
4343 } ) ;
4444
4545 try {
4646 await github . rest . git . createRef ( {
47- owner : context . repo . owner ,
48- repo : context . repo . repo ,
47+ owner : repo . owner ,
48+ repo : repo . repo ,
4949 ref : `refs/heads/${ branchName } ` ,
5050 sha : mainRef . data . object . sha ,
5151 } ) ;
@@ -59,8 +59,8 @@ async function determineBranch(github, context, issueId, mode, isPullRequest) {
5959 }
6060 } else if ( isPullRequest ) {
6161 const pr = await github . rest . pulls . get ( {
62- owner : context . repo . owner ,
63- repo : context . repo . repo ,
62+ owner : repo . owner ,
63+ repo : repo . repo ,
6464 pull_number : issueId ,
6565 } ) ;
6666 branchName = pr . data . head . ref ;
@@ -69,7 +69,7 @@ async function determineBranch(github, context, issueId, mode, isPullRequest) {
6969 return branchName ;
7070}
7171
72- function buildPrompts ( mode , issueId , isPullRequest , command , branchName , inputs ) {
72+ function buildPrompts ( mode , issueId , isPullRequest , command , branchName , inputs , repo ) {
7373 const sessionId =
7474 inputs . session_id ||
7575 ( mode === 'implementer' ? `${ mode } -${ branchName } ` . replace ( / [ \/ \\ ] / g, '-' ) : `${ mode } -${ issueId } ` ) ;
@@ -86,7 +86,7 @@ function buildPrompts(mode, issueId, isPullRequest, command, branchName, inputs)
8686
8787 let prompt = isPullRequest ? 'The pull request id is:' : 'The issue id is:' ;
8888 prompt += `${ issueId } \n` ;
89- prompt += `The repository is: aws/agentcore-cli \n` ;
89+ prompt += `The repository is: ${ repo . owner } / ${ repo . repo } \n` ;
9090
9191 if ( mode === 'tester' ) {
9292 const flowDescription = command . replace ( / ^ t e s t \s * / , '' ) . trim ( ) ;
@@ -105,7 +105,9 @@ function buildPrompts(mode, issueId, isPullRequest, command, branchName, inputs)
105105
106106module . exports = async ( context , github , core , inputs ) => {
107107 try {
108- const { issueId, command, issue } = await getIssueInfo ( github , context , inputs ) ;
108+ const repo = inputs . target_repo || { owner : context . repo . owner , repo : context . repo . repo } ;
109+
110+ const { issueId, command, issue } = await getIssueInfo ( github , repo , inputs , context . eventName , context . payload ) ;
109111
110112 const isPullRequest = ! ! issue . data . pull_request ;
111113
@@ -115,10 +117,18 @@ module.exports = async (context, github, core, inputs) => {
115117 ( isPullRequest ? 'implementer' : 'refiner' ) ;
116118 console . log ( `Is PR: ${ isPullRequest } , Mode: ${ mode } ` ) ;
117119
118- const branchName = await determineBranch ( github , context , issueId , mode , isPullRequest ) ;
120+ const branchName = await determineBranch ( github , repo , issueId , mode , isPullRequest ) ;
119121 console . log ( `Building prompts - mode: ${ mode } , issue: ${ issueId } , is PR: ${ isPullRequest } ` ) ;
120122
121- const { sessionId, systemPrompt, prompt } = buildPrompts ( mode , issueId , isPullRequest , command , branchName , inputs ) ;
123+ const { sessionId, systemPrompt, prompt } = buildPrompts (
124+ mode ,
125+ issueId ,
126+ isPullRequest ,
127+ command ,
128+ branchName ,
129+ inputs ,
130+ repo
131+ ) ;
122132
123133 console . log ( `Session ID: ${ sessionId } ` ) ;
124134 console . log ( `Task prompt: "${ prompt } "` ) ;
0 commit comments