Skip to content

Commit 6816815

Browse files
Copilotpelikhan
andauthored
[WIP] Review context handling in push_to_pull_request_branch (#19604)
* Initial plan * Fix: handle undefined context in push_to_pull_request_branch Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 943e57b commit 6816815

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

actions/setup/js/push_to_pull_request_branch.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ async function main(config = {}) {
192192
// Compute the target branch name based on target configuration
193193
let pullNumber;
194194
if (target === "triggering") {
195-
pullNumber = context.payload?.pull_request?.number || context.payload?.issue?.number;
195+
pullNumber = typeof context !== "undefined" ? context.payload?.pull_request?.number || context.payload?.issue?.number : undefined;
196196

197197
if (!pullNumber) {
198198
return { success: false, error: 'push-to-pull-request-branch with target "triggering" requires pull request context' };

actions/setup/js/push_to_pull_request_branch.test.cjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ index 0000000..abc1234
334334
expect(result.error).toContain("pull request context");
335335
});
336336

337+
it('should fail gracefully with target "triggering" when context is undefined (MCP daemon mode)', async () => {
338+
delete global.context;
339+
340+
const patchPath = createPatchFile();
341+
342+
const module = await loadModule();
343+
const handler = await module.main({ target: "triggering" });
344+
const result = await handler({ patch_path: patchPath }, {});
345+
346+
expect(result.success).toBe(false);
347+
expect(result.error).toContain("pull request context");
348+
});
349+
337350
it('should handle schedule event with target "*" and explicit PR number', async () => {
338351
mockContext.eventName = "schedule";
339352
delete mockContext.payload.pull_request;

0 commit comments

Comments
 (0)