mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-24 07:24:12 +08:00
feat: implement Claude Code GitHub Action v1.0 with auto-detection and slash commands
Major features: - Mode auto-detection based on GitHub event type - Unified prompt field replacing override_prompt and direct_prompt - Slash command system with pre-built commands - Full backward compatibility with v0.x Key changes: - Add mode detector for automatic mode selection - Implement slash command loader with YAML frontmatter support - Update action.yml with new prompt input - Create pre-built slash commands for common tasks - Update all tests for v1.0 compatibility Breaking changes (with compatibility): - Mode input now optional (auto-detected) - override_prompt deprecated (use prompt) - direct_prompt deprecated (use prompt)
This commit is contained in:
77
src/modes/detector.ts
Normal file
77
src/modes/detector.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import type { GitHubContext } from "../github/context";
|
||||
import {
|
||||
isEntityContext,
|
||||
isAutomationContext,
|
||||
isPullRequestEvent,
|
||||
isIssueCommentEvent,
|
||||
isPullRequestReviewCommentEvent,
|
||||
} from "../github/context";
|
||||
import { checkContainsTrigger } from "../github/validation/trigger";
|
||||
|
||||
export type AutoDetectedMode = "review" | "tag" | "agent";
|
||||
|
||||
export function detectMode(context: GitHubContext): AutoDetectedMode {
|
||||
if (isPullRequestEvent(context)) {
|
||||
const allowedActions = ["opened", "synchronize", "reopened"];
|
||||
const action = context.payload.action;
|
||||
if (allowedActions.includes(action)) {
|
||||
return "review";
|
||||
}
|
||||
}
|
||||
|
||||
if (isEntityContext(context)) {
|
||||
if (
|
||||
isIssueCommentEvent(context) ||
|
||||
isPullRequestReviewCommentEvent(context)
|
||||
) {
|
||||
if (checkContainsTrigger(context)) {
|
||||
return "tag";
|
||||
}
|
||||
}
|
||||
|
||||
if (context.eventName === "issues") {
|
||||
if (checkContainsTrigger(context)) {
|
||||
return "tag";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isAutomationContext(context)) {
|
||||
return "agent";
|
||||
}
|
||||
|
||||
return "agent";
|
||||
}
|
||||
|
||||
export function getModeDescription(mode: AutoDetectedMode): string {
|
||||
switch (mode) {
|
||||
case "review":
|
||||
return "Automated code review mode for pull requests";
|
||||
case "tag":
|
||||
return "Interactive mode triggered by @claude mentions";
|
||||
case "agent":
|
||||
return "Automation mode for scheduled tasks and workflows";
|
||||
default:
|
||||
return "Unknown mode";
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldUseTrackingComment(mode: AutoDetectedMode): boolean {
|
||||
return mode === "tag";
|
||||
}
|
||||
|
||||
export function getDefaultPromptForMode(
|
||||
mode: AutoDetectedMode,
|
||||
context: GitHubContext,
|
||||
): string | undefined {
|
||||
switch (mode) {
|
||||
case "review":
|
||||
return "/review";
|
||||
case "tag":
|
||||
return undefined;
|
||||
case "agent":
|
||||
return context.inputs?.directPrompt || context.inputs?.overridePrompt;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user