fix: allow issue triggers without prepared branch

This commit is contained in:
Mark Wylde
2025-09-30 18:14:03 +01:00
parent ebd4882b3e
commit 225a4e6f3a
2 changed files with 22 additions and 17 deletions

View File

@@ -277,8 +277,6 @@ export function prepareContext(
throw new Error( throw new Error(
"ISSUE_NUMBER is required for issue_comment event for issues", "ISSUE_NUMBER is required for issue_comment event for issues",
); );
} else if (!claudeBranch) {
throw new Error("CLAUDE_BRANCH is required for issue_comment event");
} }
eventData = { eventData = {
@@ -288,7 +286,7 @@ export function prepareContext(
baseBranch, baseBranch,
issueNumber, issueNumber,
commentBody, commentBody,
claudeBranch, ...(claudeBranch && { claudeBranch }),
}; };
break; break;
@@ -305,10 +303,6 @@ export function prepareContext(
if (!baseBranch) { if (!baseBranch) {
throw new Error("BASE_BRANCH is required for issues event"); throw new Error("BASE_BRANCH is required for issues event");
} }
if (!claudeBranch) {
throw new Error("CLAUDE_BRANCH is required for issues event");
}
if (eventAction === "assigned") { if (eventAction === "assigned") {
if (!assigneeTrigger && !directPrompt) { if (!assigneeTrigger && !directPrompt) {
throw new Error( throw new Error(
@@ -322,7 +316,7 @@ export function prepareContext(
issueNumber, issueNumber,
baseBranch, baseBranch,
...(assigneeTrigger && { assigneeTrigger }), ...(assigneeTrigger && { assigneeTrigger }),
claudeBranch, ...(claudeBranch && { claudeBranch }),
}; };
} else if (eventAction === "labeled") { } else if (eventAction === "labeled") {
if (!labelTrigger) { if (!labelTrigger) {
@@ -334,7 +328,7 @@ export function prepareContext(
isPR: false, isPR: false,
issueNumber, issueNumber,
baseBranch, baseBranch,
claudeBranch, ...(claudeBranch && { claudeBranch }),
labelTrigger, labelTrigger,
}; };
} else if (eventAction === "opened") { } else if (eventAction === "opened") {

View File

@@ -69,10 +69,19 @@ describe("parseEnvVarsWithContext", () => {
} }
}); });
test("should throw error when CLAUDE_BRANCH is missing", () => { test("should allow missing CLAUDE_BRANCH and omit it from event data", () => {
expect(() => const result = prepareContext(
prepareContext(mockIssueCommentContext, "12345", "main"), mockIssueCommentContext,
).toThrow("CLAUDE_BRANCH is required for issue_comment event"); "12345",
"main",
);
if (
result.eventData.eventName === "issue_comment" &&
!result.eventData.isPR
) {
expect(result.eventData.claudeBranch).toBeUndefined();
}
}); });
test("should throw error when BASE_BRANCH is missing", () => { test("should throw error when BASE_BRANCH is missing", () => {
@@ -203,10 +212,12 @@ describe("parseEnvVarsWithContext", () => {
} }
}); });
test("should throw error when CLAUDE_BRANCH is missing for issues", () => { test("should allow issues event without CLAUDE_BRANCH", () => {
expect(() => const result = prepareContext(mockIssueOpenedContext, "12345", "main");
prepareContext(mockIssueOpenedContext, "12345", "main"),
).toThrow("CLAUDE_BRANCH is required for issues event"); if (result.eventData.eventName === "issues") {
expect(result.eventData.claudeBranch).toBeUndefined();
}
}); });
test("should throw error when BASE_BRANCH is missing for issues", () => { test("should throw error when BASE_BRANCH is missing for issues", () => {