mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 15:04:13 +08:00
formatting
This commit is contained in:
@@ -25,9 +25,13 @@ function extractGitHubContext(context: GitHubContext): Record<string, string> {
|
||||
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);
|
||||
|
||||
@@ -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}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,15 +177,22 @@ 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;
|
||||
|
||||
@@ -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/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -120,7 +122,7 @@ describe("detectMode with enhanced routing", () => {
|
||||
eventName: "issue_comment",
|
||||
payload: {
|
||||
issue: { number: 1, body: "Test" },
|
||||
comment: { body: "@claude help" }
|
||||
comment: { body: "@claude help" },
|
||||
} as any,
|
||||
entityNumber: 1,
|
||||
isPR: false,
|
||||
@@ -135,7 +137,7 @@ describe("detectMode with enhanced routing", () => {
|
||||
eventName: "issue_comment",
|
||||
payload: {
|
||||
issue: { number: 1, body: "Test" },
|
||||
comment: { body: "@claude help" }
|
||||
comment: { body: "@claude help" },
|
||||
} as any,
|
||||
entityNumber: 1,
|
||||
isPR: false,
|
||||
@@ -151,7 +153,7 @@ describe("detectMode with enhanced routing", () => {
|
||||
eventName: "pull_request_review_comment",
|
||||
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", () => {
|
||||
@@ -197,7 +201,7 @@ describe("detectMode with enhanced routing", () => {
|
||||
inputs: {
|
||||
...baseContext.inputs,
|
||||
trackProgress: true,
|
||||
prompt: "Review for security issues"
|
||||
prompt: "Review for security issues",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -215,7 +219,7 @@ describe("detectMode with enhanced routing", () => {
|
||||
inputs: {
|
||||
...baseContext.inputs,
|
||||
trackProgress: true,
|
||||
prompt: "Analyze this issue"
|
||||
prompt: "Analyze this issue",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user