Skip to content

Commit 726573b

Browse files
committed
fix: pass target_repo as explicit param instead of overriding context.repo, add comment on continue-on-error
1 parent 9ea6d4a commit 726573b

2 files changed

Lines changed: 37 additions & 27 deletions

File tree

.github/scripts/javascript/process-inputs.cjs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,48 @@
44

55
const 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(/^\/strands\s*(.*)$/)?.[1]?.trim() || '';
20+
: payload.comment.body.match(/^\/strands\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(/^test\s*/, '').trim();
@@ -105,7 +105,9 @@ function buildPrompts(mode, issueId, isPullRequest, command, branchName, inputs)
105105

106106
module.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}"`);

.github/workflows/strands-command.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
fetch-depth: 0
7171

7272
- name: Add strands-running label
73+
# continue-on-error: workflow_dispatch from a fork targets the fork repo
74+
# where the upstream issue/PR doesn't exist, causing a 404.
7375
continue-on-error: true
7476
uses: actions/github-script@v8
7577
with:
@@ -87,17 +89,15 @@ jobs:
8789
uses: actions/github-script@v8
8890
with:
8991
script: |
90-
// When dispatched from a fork, override the repo getter to point at upstream
91-
if (context.eventName === 'workflow_dispatch' && context.repo.owner !== 'aws') {
92-
Object.defineProperty(context, 'repo', {
93-
get: () => ({ owner: 'aws', repo: 'agentcore-cli' })
94-
});
95-
}
9692
const processInputs = require('./.github/scripts/javascript/process-inputs.cjs');
9793
const inputs = {
9894
issue_id: '${{ inputs.issue_id }}',
9995
command: '${{ inputs.command }}',
100-
session_id: '${{ inputs.session_id }}'
96+
session_id: '${{ inputs.session_id }}',
97+
// When dispatched from a fork, target the upstream repo for API calls
98+
...(context.eventName === 'workflow_dispatch' && context.repo.owner !== 'aws'
99+
? { target_repo: { owner: 'aws', repo: 'agentcore-cli' } }
100+
: {}),
101101
};
102102
await processInputs(context, github, core, inputs);
103103

0 commit comments

Comments
 (0)