mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
feat: add push event support for automation workflows
Add support for `push` events as an automation event type, enabling workflows triggered by pushes to use claude-code-action. Changes: - Add PushEvent to automation event types in context.ts - Add case handler for push events in parseGitHubContext() - Add isPushEvent() type guard - Add test for push event mode detection This enables use cases like auto-rebasing PRs when main is updated, where a workflow triggers on push to main and uses a prompt to instruct Claude to merge main into stale PR branches.
This commit is contained in:
@@ -6,6 +6,7 @@ import type {
|
|||||||
PullRequestEvent,
|
PullRequestEvent,
|
||||||
PullRequestReviewEvent,
|
PullRequestReviewEvent,
|
||||||
PullRequestReviewCommentEvent,
|
PullRequestReviewCommentEvent,
|
||||||
|
PushEvent,
|
||||||
WorkflowRunEvent,
|
WorkflowRunEvent,
|
||||||
} from "@octokit/webhooks-types";
|
} from "@octokit/webhooks-types";
|
||||||
import { CLAUDE_APP_BOT_ID, CLAUDE_BOT_LOGIN } from "./constants";
|
import { CLAUDE_APP_BOT_ID, CLAUDE_BOT_LOGIN } from "./constants";
|
||||||
@@ -65,6 +66,7 @@ const AUTOMATION_EVENT_NAMES = [
|
|||||||
"repository_dispatch",
|
"repository_dispatch",
|
||||||
"schedule",
|
"schedule",
|
||||||
"workflow_run",
|
"workflow_run",
|
||||||
|
"push",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// Derive types from constants for better maintainability
|
// Derive types from constants for better maintainability
|
||||||
@@ -112,14 +114,15 @@ export type ParsedGitHubContext = BaseContext & {
|
|||||||
isPR: boolean;
|
isPR: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Context for automation events (workflow_dispatch, repository_dispatch, schedule, workflow_run)
|
// Context for automation events (workflow_dispatch, repository_dispatch, schedule, workflow_run, push)
|
||||||
export type AutomationContext = BaseContext & {
|
export type AutomationContext = BaseContext & {
|
||||||
eventName: AutomationEventName;
|
eventName: AutomationEventName;
|
||||||
payload:
|
payload:
|
||||||
| WorkflowDispatchEvent
|
| WorkflowDispatchEvent
|
||||||
| RepositoryDispatchEvent
|
| RepositoryDispatchEvent
|
||||||
| ScheduleEvent
|
| ScheduleEvent
|
||||||
| WorkflowRunEvent;
|
| WorkflowRunEvent
|
||||||
|
| PushEvent;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Union type for all contexts
|
// Union type for all contexts
|
||||||
@@ -235,6 +238,13 @@ export function parseGitHubContext(): GitHubContext {
|
|||||||
payload: context.payload as unknown as WorkflowRunEvent,
|
payload: context.payload as unknown as WorkflowRunEvent,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case "push": {
|
||||||
|
return {
|
||||||
|
...commonFields,
|
||||||
|
eventName: "push",
|
||||||
|
payload: context.payload as unknown as PushEvent,
|
||||||
|
};
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported event type: ${context.eventName}`);
|
throw new Error(`Unsupported event type: ${context.eventName}`);
|
||||||
}
|
}
|
||||||
@@ -276,6 +286,12 @@ export function isIssuesAssignedEvent(
|
|||||||
return isIssuesEvent(context) && context.eventAction === "assigned";
|
return isIssuesEvent(context) && context.eventAction === "assigned";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPushEvent(
|
||||||
|
context: GitHubContext,
|
||||||
|
): context is AutomationContext & { payload: PushEvent } {
|
||||||
|
return context.eventName === "push";
|
||||||
|
}
|
||||||
|
|
||||||
// Type guard to check if context is an entity context (has entityNumber and isPR)
|
// Type guard to check if context is an entity context (has entityNumber and isPR)
|
||||||
export function isEntityContext(
|
export function isEntityContext(
|
||||||
context: GitHubContext,
|
context: GitHubContext,
|
||||||
|
|||||||
@@ -60,6 +60,15 @@ describe("Mode Registry", () => {
|
|||||||
expect(mode.name).toBe("agent");
|
expect(mode.name).toBe("agent");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getMode auto-detects agent for push event", () => {
|
||||||
|
const pushContext = createMockAutomationContext({
|
||||||
|
eventName: "push",
|
||||||
|
});
|
||||||
|
const mode = getMode(pushContext);
|
||||||
|
expect(mode).toBe(agentMode);
|
||||||
|
expect(mode.name).toBe("agent");
|
||||||
|
});
|
||||||
|
|
||||||
test("getMode auto-detects agent for repository_dispatch with client_payload", () => {
|
test("getMode auto-detects agent for repository_dispatch with client_payload", () => {
|
||||||
const contextWithPayload = createMockAutomationContext({
|
const contextWithPayload = createMockAutomationContext({
|
||||||
eventName: "repository_dispatch",
|
eventName: "repository_dispatch",
|
||||||
|
|||||||
Reference in New Issue
Block a user