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

@@ -13,27 +13,31 @@ import { isEntityContext } from "../../github/context";
*/
function extractGitHubContext(context: GitHubContext): Record<string, string> {
const envVars: Record<string, string> = {};
// 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;
}

View File

@@ -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}`,
);
}
}

View File

@@ -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 +
`
<custom_instructions>
${context.githubContext.inputs.prompt}
</custom_instructions>`;
</custom_instructions>`
);
}
return defaultPrompt;
},

View File

@@ -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");
});
});
});
});