From 91a8d6c8d87e2dd4f9cb03bf5c9cd913301b6832 Mon Sep 17 00:00:00 2001 From: Boris Cherny Date: Thu, 1 Jan 2026 13:19:30 -0800 Subject: [PATCH] docs: add push event documentation and tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address code review feedback: - Add push event to supported events list in docs/custom-automations.md - Add auto-rebase example workflow using push events - Add tests for isPushEvent type guard - Add tests for push event mode detection - Add test to verify track_progress throws error for push events 🤖 Generated with [Claude Code](https://claude.ai/code) --- docs/custom-automations.md | 40 ++++++++++++++++++++++++ test/modes/detector.test.ts | 62 +++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/docs/custom-automations.md b/docs/custom-automations.md index fabb52f..c366af9 100644 --- a/docs/custom-automations.md +++ b/docs/custom-automations.md @@ -21,6 +21,7 @@ This action supports the following GitHub events ([learn more GitHub event trigg - `issues` - When issues are opened or assigned - `pull_request_review` - When PR reviews are submitted - `pull_request_review_comment` - When comments are made on PR reviews +- `push` - When commits are pushed to a branch - `repository_dispatch` - Custom events triggered via API - `workflow_dispatch` - Manual workflow triggers (coming soon) @@ -120,3 +121,42 @@ For more control over Claude's behavior, use the `claude_args` input to pass CLI ``` This provides full access to Claude Code CLI capabilities while maintaining the simplified action interface. + +## Auto-Rebase PRs on Push + +Automatically keep PRs up to date when the main branch is updated: + +```yaml +name: Auto-Rebase PRs + +on: + push: + branches: [main] + +permissions: + contents: write + pull-requests: write + id-token: write + +jobs: + rebase-prs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: anthropics/claude-code-action@v1 + with: + prompt: | + Find all open PRs that are behind main and merge main into them. + For each PR: + 1. Check out the PR branch + 2. Merge main into the branch + 3. Push the updated branch + + Skip any PRs with merge conflicts - just report them. + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} +``` + +This workflow triggers whenever commits are pushed to main and uses Claude to automatically merge main into any stale PR branches, keeping them up to date. diff --git a/test/modes/detector.test.ts b/test/modes/detector.test.ts index 199f094..254e5e7 100644 --- a/test/modes/detector.test.ts +++ b/test/modes/detector.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from "bun:test"; import { detectMode } from "../../src/modes/detector"; import type { GitHubContext } from "../../src/github/context"; +import { isPushEvent } from "../../src/github/context"; describe("detectMode with enhanced routing", () => { const baseContext = { @@ -257,4 +258,65 @@ describe("detectMode with enhanced routing", () => { expect(detectMode(context)).toBe("tag"); }); }); + + describe("Push Events", () => { + it("should use agent mode for push events", () => { + const context: GitHubContext = { + ...baseContext, + eventName: "push", + payload: {} as any, + inputs: { ...baseContext.inputs, prompt: "Merge main into stale PRs" }, + }; + + expect(detectMode(context)).toBe("agent"); + }); + + it("should throw error when track_progress is used with push event", () => { + const context: GitHubContext = { + ...baseContext, + eventName: "push", + payload: {} as any, + inputs: { ...baseContext.inputs, trackProgress: true }, + }; + + expect(() => detectMode(context)).toThrow( + /track_progress is only supported /, + ); + }); + }); + + describe("isPushEvent type guard", () => { + it("should return true for push events", () => { + const context: GitHubContext = { + ...baseContext, + eventName: "push", + payload: {} as any, + }; + + expect(isPushEvent(context)).toBe(true); + }); + + it("should return false for non-push events", () => { + const issueContext: GitHubContext = { + ...baseContext, + eventName: "issues", + eventAction: "opened", + payload: { issue: { number: 1, body: "Test" } } as any, + entityNumber: 1, + isPR: false, + }; + + expect(isPushEvent(issueContext)).toBe(false); + }); + + it("should return false for workflow_dispatch events", () => { + const context: GitHubContext = { + ...baseContext, + eventName: "workflow_dispatch", + payload: {} as any, + }; + + expect(isPushEvent(context)).toBe(false); + }); + }); });