mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
formatting
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user