formatting

This commit is contained in:
km-anthropic
2025-08-28 14:32:26 -07:00
parent 07a69eeb9c
commit dbdd70852d
4 changed files with 57 additions and 32 deletions

View File

@@ -25,9 +25,13 @@ function extractGitHubContext(context: GitHubContext): Record<string, string> {
envVars.GITHUB_PR_NUMBER = String(context.entityNumber); envVars.GITHUB_PR_NUMBER = String(context.entityNumber);
// Extract branch info from payload if available // Extract branch info from payload if available
if (context.payload && 'pull_request' in context.payload && context.payload.pull_request) { if (
envVars.GITHUB_BASE_REF = context.payload.pull_request.base?.ref || ''; context.payload &&
envVars.GITHUB_HEAD_REF = context.payload.pull_request.head?.ref || ''; "pull_request" in context.payload &&
context.payload.pull_request
) {
envVars.GITHUB_BASE_REF = context.payload.pull_request.base?.ref || "";
envVars.GITHUB_HEAD_REF = context.payload.pull_request.head?.ref || "";
} }
} else { } else {
envVars.GITHUB_ISSUE_NUMBER = String(context.entityNumber); envVars.GITHUB_ISSUE_NUMBER = String(context.entityNumber);

View File

@@ -52,7 +52,12 @@ export function detectMode(context: GitHubContext): AutoDetectedMode {
// PR events (opened, synchronize, etc.) // PR events (opened, synchronize, etc.)
if (isEntityContext(context) && isPullRequestEvent(context)) { if (isEntityContext(context) && isPullRequestEvent(context)) {
const supportedActions = ["opened", "synchronize", "ready_for_review", "reopened"]; const supportedActions = [
"opened",
"synchronize",
"ready_for_review",
"reopened",
];
if (context.eventAction && supportedActions.includes(context.eventAction)) { if (context.eventAction && supportedActions.includes(context.eventAction)) {
// If prompt is provided, use agent mode (default for automation) // If prompt is provided, use agent mode (default for automation)
if (context.inputs.prompt) { if (context.inputs.prompt) {
@@ -82,17 +87,22 @@ function validateTrackProgressEvent(context: GitHubContext): void {
if (!validEvents.includes(context.eventName)) { if (!validEvents.includes(context.eventName)) {
throw new Error( throw new Error(
`track_progress is only supported for pull_request and issue events. ` + `track_progress is only supported for pull_request and issue events. ` +
`Current event: ${context.eventName}` `Current event: ${context.eventName}`,
); );
} }
// Additionally validate PR actions // Additionally validate PR actions
if (context.eventName === "pull_request" && context.eventAction) { if (context.eventName === "pull_request" && context.eventAction) {
const validActions = ["opened", "synchronize", "ready_for_review", "reopened"]; const validActions = [
"opened",
"synchronize",
"ready_for_review",
"reopened",
];
if (!validActions.includes(context.eventAction)) { if (!validActions.includes(context.eventAction)) {
throw new Error( throw new Error(
`track_progress for pull_request events is only supported for actions: ` + `track_progress for pull_request events is only supported for actions: ` +
`${validActions.join(", ")}. Current action: ${context.eventAction}` `${validActions.join(", ")}. Current action: ${context.eventAction}`,
); );
} }
} }

View File

@@ -177,15 +177,22 @@ export const tagMode: Mode = {
githubData: FetchDataResult, githubData: FetchDataResult,
useCommitSigning: boolean, useCommitSigning: boolean,
): string { ): string {
const defaultPrompt = generateDefaultPrompt(context, githubData, useCommitSigning); const defaultPrompt = generateDefaultPrompt(
context,
githubData,
useCommitSigning,
);
// If a custom prompt is provided, inject it into the tag mode prompt // If a custom prompt is provided, inject it into the tag mode prompt
if (context.githubContext?.inputs?.prompt) { if (context.githubContext?.inputs?.prompt) {
return defaultPrompt + ` return (
defaultPrompt +
`
<custom_instructions> <custom_instructions>
${context.githubContext.inputs.prompt} ${context.githubContext.inputs.prompt}
</custom_instructions>`; </custom_instructions>`
);
} }
return defaultPrompt; return defaultPrompt;

View File

@@ -79,7 +79,9 @@ describe("detectMode with enhanced routing", () => {
inputs: { ...baseContext.inputs, trackProgress: true }, inputs: { ...baseContext.inputs, trackProgress: true },
}; };
expect(() => detectMode(context)).toThrow(/track_progress for pull_request events is only supported for actions/); expect(() => detectMode(context)).toThrow(
/track_progress for pull_request events is only supported for actions/,
);
}); });
}); });
@@ -120,7 +122,7 @@ describe("detectMode with enhanced routing", () => {
eventName: "issue_comment", eventName: "issue_comment",
payload: { payload: {
issue: { number: 1, body: "Test" }, issue: { number: 1, body: "Test" },
comment: { body: "@claude help" } comment: { body: "@claude help" },
} as any, } as any,
entityNumber: 1, entityNumber: 1,
isPR: false, isPR: false,
@@ -135,7 +137,7 @@ describe("detectMode with enhanced routing", () => {
eventName: "issue_comment", eventName: "issue_comment",
payload: { payload: {
issue: { number: 1, body: "Test" }, issue: { number: 1, body: "Test" },
comment: { body: "@claude help" } comment: { body: "@claude help" },
} as any, } as any,
entityNumber: 1, entityNumber: 1,
isPR: false, isPR: false,
@@ -151,7 +153,7 @@ describe("detectMode with enhanced routing", () => {
eventName: "pull_request_review_comment", eventName: "pull_request_review_comment",
payload: { payload: {
pull_request: { number: 1, body: "Test" }, pull_request: { number: 1, body: "Test" },
comment: { body: "@claude check this" } comment: { body: "@claude check this" },
} as any, } as any,
entityNumber: 1, entityNumber: 1,
isPR: true, isPR: true,
@@ -170,7 +172,9 @@ describe("detectMode with enhanced routing", () => {
inputs: { ...baseContext.inputs, trackProgress: true }, inputs: { ...baseContext.inputs, trackProgress: true },
}; };
expect(() => detectMode(context)).toThrow(/track_progress is only supported for pull_request and issue events/); expect(() => detectMode(context)).toThrow(
/track_progress is only supported for pull_request and issue events/,
);
}); });
it("should use agent mode for workflow_dispatch without track_progress", () => { it("should use agent mode for workflow_dispatch without track_progress", () => {
@@ -197,7 +201,7 @@ describe("detectMode with enhanced routing", () => {
inputs: { inputs: {
...baseContext.inputs, ...baseContext.inputs,
trackProgress: true, trackProgress: true,
prompt: "Review for security issues" prompt: "Review for security issues",
}, },
}; };
@@ -215,7 +219,7 @@ describe("detectMode with enhanced routing", () => {
inputs: { inputs: {
...baseContext.inputs, ...baseContext.inputs,
trackProgress: true, trackProgress: true,
prompt: "Analyze this issue" prompt: "Analyze this issue",
}, },
}; };