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:
km-anthropic
2025-07-23 20:35:11 -07:00
committed by GitHub
parent 963754fa12
commit a58dc37018
16 changed files with 348 additions and 34 deletions

View File

@@ -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 ?? "",