mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
some structural simplification
This commit is contained in:
@@ -37,6 +37,17 @@ export type ScheduleEvent = {
|
||||
import type { ModeName } from "../modes/types";
|
||||
import { DEFAULT_MODE, isValidMode } from "../modes/registry";
|
||||
|
||||
// Event name constants for better maintainability
|
||||
const ENTITY_EVENT_NAMES = [
|
||||
"issues",
|
||||
"issue_comment",
|
||||
"pull_request",
|
||||
"pull_request_review",
|
||||
"pull_request_review_comment",
|
||||
] as const;
|
||||
|
||||
const AUTOMATION_EVENT_NAMES = ["workflow_dispatch", "schedule"] as const;
|
||||
|
||||
// Common fields shared by all context types
|
||||
type BaseContext = {
|
||||
runId: string;
|
||||
@@ -265,21 +276,12 @@ export function isIssuesAssignedEvent(
|
||||
export function isEntityContext(
|
||||
context: GitHubContext,
|
||||
): context is ParsedGitHubContext {
|
||||
return (
|
||||
context.eventName === "issues" ||
|
||||
context.eventName === "issue_comment" ||
|
||||
context.eventName === "pull_request" ||
|
||||
context.eventName === "pull_request_review" ||
|
||||
context.eventName === "pull_request_review_comment"
|
||||
);
|
||||
return ENTITY_EVENT_NAMES.includes(context.eventName as any);
|
||||
}
|
||||
|
||||
// Type guard to check if context is an automation context
|
||||
export function isAutomationContext(
|
||||
context: GitHubContext,
|
||||
): context is AutomationContext {
|
||||
return (
|
||||
context.eventName === "workflow_dispatch" ||
|
||||
context.eventName === "schedule"
|
||||
);
|
||||
return AUTOMATION_EVENT_NAMES.includes(context.eventName as any);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as core from "@actions/core";
|
||||
import { mkdir, writeFile } from "fs/promises";
|
||||
import type { Mode, ModeOptions, ModeResult } from "../types";
|
||||
import { isAutomationContext } from "../../github/context";
|
||||
|
||||
/**
|
||||
* Agent mode implementation.
|
||||
@@ -15,10 +16,7 @@ export const agentMode: Mode = {
|
||||
|
||||
shouldTrigger(context) {
|
||||
// Only trigger for automation events
|
||||
return (
|
||||
context.eventName === "workflow_dispatch" ||
|
||||
context.eventName === "schedule"
|
||||
);
|
||||
return isAutomationContext(context);
|
||||
},
|
||||
|
||||
prepareContext(context) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import type { Mode, ModeName } from "./types";
|
||||
import { tagMode } from "./tag";
|
||||
import { agentMode } from "./agent";
|
||||
import type { GitHubContext } from "../github/context";
|
||||
import { isAutomationContext } from "../github/context";
|
||||
|
||||
export const DEFAULT_MODE = "tag" as const;
|
||||
export const VALID_MODES = ["tag", "agent"] as const;
|
||||
@@ -44,11 +45,7 @@ export function getMode(name: ModeName, context: GitHubContext): Mode {
|
||||
}
|
||||
|
||||
// Validate mode can handle the event type
|
||||
if (
|
||||
name === "tag" &&
|
||||
(context.eventName === "workflow_dispatch" ||
|
||||
context.eventName === "schedule")
|
||||
) {
|
||||
if (name === "tag" && isAutomationContext(context)) {
|
||||
throw new Error(
|
||||
`Tag mode cannot handle ${context.eventName} events. Use 'agent' mode for automation events.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user