mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
Add mode support (#333)
* Add mode support * update "as any" with proper "as unknwon as ModeName" casting * Add documentation to README and registry.ts * Add tests for differen event types, integration flows, and error conditions * Clean up some tests * Minor test fix * Minor formatting test + switch from interface to type * correct the order of mkdir call * always configureGitAuth as there's already a fallback to handle null users by using the bot ID * simplify registry setup --------- Co-authored-by: km-anthropic <km-anthropic@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,9 @@ import type {
|
||||
PullRequestReviewEvent,
|
||||
PullRequestReviewCommentEvent,
|
||||
} from "@octokit/webhooks-types";
|
||||
import type { ModeName } from "../modes/registry";
|
||||
import { DEFAULT_MODE } from "../modes/registry";
|
||||
import { isValidMode } from "../modes/registry";
|
||||
|
||||
export type ParsedGitHubContext = {
|
||||
runId: string;
|
||||
@@ -27,6 +30,7 @@ export type ParsedGitHubContext = {
|
||||
entityNumber: number;
|
||||
isPR: boolean;
|
||||
inputs: {
|
||||
mode: ModeName;
|
||||
triggerPhrase: string;
|
||||
assigneeTrigger: string;
|
||||
labelTrigger: string;
|
||||
@@ -46,6 +50,11 @@ export type ParsedGitHubContext = {
|
||||
export function parseGitHubContext(): ParsedGitHubContext {
|
||||
const context = github.context;
|
||||
|
||||
const modeInput = process.env.MODE ?? DEFAULT_MODE;
|
||||
if (!isValidMode(modeInput)) {
|
||||
throw new Error(`Invalid mode: ${modeInput}.`);
|
||||
}
|
||||
|
||||
const commonFields = {
|
||||
runId: process.env.GITHUB_RUN_ID!,
|
||||
eventName: context.eventName,
|
||||
@@ -57,6 +66,7 @@ export function parseGitHubContext(): ParsedGitHubContext {
|
||||
},
|
||||
actor: context.actor,
|
||||
inputs: {
|
||||
mode: modeInput as ModeName,
|
||||
triggerPhrase: process.env.TRIGGER_PHRASE ?? "@claude",
|
||||
assigneeTrigger: process.env.ASSIGNEE_TRIGGER ?? "",
|
||||
labelTrigger: process.env.LABEL_TRIGGER ?? "",
|
||||
|
||||
Reference in New Issue
Block a user