From dbdd70852de8b6486bd9710f45cfcce25d6ff947 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Thu, 28 Aug 2025 14:32:26 -0700 Subject: [PATCH] formatting --- src/modes/agent/index.ts | 18 +++++++++++------- src/modes/detector.ts | 20 +++++++++++++++----- src/modes/tag/index.ts | 17 ++++++++++++----- tests/modes/detector.test.ts | 34 +++++++++++++++++++--------------- 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/modes/agent/index.ts b/src/modes/agent/index.ts index 6a4dad6e..bf188284 100644 --- a/src/modes/agent/index.ts +++ b/src/modes/agent/index.ts @@ -13,27 +13,31 @@ import { isEntityContext } from "../../github/context"; */ function extractGitHubContext(context: GitHubContext): Record { const envVars: Record = {}; - + // Basic repository info envVars.GITHUB_REPOSITORY = context.repository.full_name; envVars.GITHUB_TRIGGER_ACTOR = context.actor; envVars.GITHUB_EVENT_NAME = context.eventName; - + // Entity-specific context (PR/issue numbers, branches, etc.) if (isEntityContext(context)) { if (context.isPR) { envVars.GITHUB_PR_NUMBER = String(context.entityNumber); - + // Extract branch info from payload if available - if (context.payload && '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 || ''; + if ( + context.payload && + "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 { envVars.GITHUB_ISSUE_NUMBER = String(context.entityNumber); } } - + return envVars; } diff --git a/src/modes/detector.ts b/src/modes/detector.ts index 11132968..92d1fede 100644 --- a/src/modes/detector.ts +++ b/src/modes/detector.ts @@ -52,7 +52,12 @@ export function detectMode(context: GitHubContext): AutoDetectedMode { // PR events (opened, synchronize, etc.) 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 prompt is provided, use agent mode (default for automation) if (context.inputs.prompt) { @@ -82,17 +87,22 @@ function validateTrackProgressEvent(context: GitHubContext): void { if (!validEvents.includes(context.eventName)) { throw new Error( `track_progress is only supported for pull_request and issue events. ` + - `Current event: ${context.eventName}` + `Current event: ${context.eventName}`, ); } - + // Additionally validate PR actions 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)) { throw new Error( `track_progress for pull_request events is only supported for actions: ` + - `${validActions.join(", ")}. Current action: ${context.eventAction}` + `${validActions.join(", ")}. Current action: ${context.eventAction}`, ); } } diff --git a/src/modes/tag/index.ts b/src/modes/tag/index.ts index cac4f255..e36b85a2 100644 --- a/src/modes/tag/index.ts +++ b/src/modes/tag/index.ts @@ -177,17 +177,24 @@ export const tagMode: Mode = { githubData: FetchDataResult, useCommitSigning: boolean, ): 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 (context.githubContext?.inputs?.prompt) { - return defaultPrompt + ` + return ( + defaultPrompt + + ` ${context.githubContext.inputs.prompt} -`; +` + ); } - + return defaultPrompt; }, diff --git a/tests/modes/detector.test.ts b/tests/modes/detector.test.ts index 00341731..6cbbcb31 100644 --- a/tests/modes/detector.test.ts +++ b/tests/modes/detector.test.ts @@ -79,7 +79,9 @@ describe("detectMode with enhanced routing", () => { 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/, + ); }); }); @@ -118,9 +120,9 @@ describe("detectMode with enhanced routing", () => { const context: GitHubContext = { ...baseContext, eventName: "issue_comment", - payload: { + payload: { issue: { number: 1, body: "Test" }, - comment: { body: "@claude help" } + comment: { body: "@claude help" }, } as any, entityNumber: 1, isPR: false, @@ -133,9 +135,9 @@ describe("detectMode with enhanced routing", () => { const context: GitHubContext = { ...baseContext, eventName: "issue_comment", - payload: { + payload: { issue: { number: 1, body: "Test" }, - comment: { body: "@claude help" } + comment: { body: "@claude help" }, } as any, entityNumber: 1, isPR: false, @@ -149,9 +151,9 @@ describe("detectMode with enhanced routing", () => { const context: GitHubContext = { ...baseContext, eventName: "pull_request_review_comment", - payload: { + payload: { pull_request: { number: 1, body: "Test" }, - comment: { body: "@claude check this" } + comment: { body: "@claude check this" }, } as any, entityNumber: 1, isPR: true, @@ -170,7 +172,9 @@ describe("detectMode with enhanced routing", () => { 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", () => { @@ -194,10 +198,10 @@ describe("detectMode with enhanced routing", () => { payload: { pull_request: { number: 1 } } as any, entityNumber: 1, isPR: true, - inputs: { - ...baseContext.inputs, + inputs: { + ...baseContext.inputs, trackProgress: true, - prompt: "Review for security issues" + prompt: "Review for security issues", }, }; @@ -212,14 +216,14 @@ describe("detectMode with enhanced routing", () => { payload: { issue: { number: 1, body: "Test" } } as any, entityNumber: 1, isPR: false, - inputs: { - ...baseContext.inputs, + inputs: { + ...baseContext.inputs, trackProgress: true, - prompt: "Analyze this issue" + prompt: "Analyze this issue", }, }; expect(detectMode(context)).toBe("tag"); }); }); -}); \ No newline at end of file +});