|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is an Octoherd script that automates the merging of Renovate dependency update PRs across multiple repositories. It's designed to handle major version library updates, "all non-major updates" PRs, and projen update PRs. |
| 8 | + |
| 9 | +## Key Commands |
| 10 | + |
| 11 | +### Running the Script |
| 12 | +```bash |
| 13 | +# Basic usage |
| 14 | +node cli.js \ |
| 15 | + -R time-loop/*-cdk \ |
| 16 | + -T ghp_TOKEN \ |
| 17 | + --majorVersion v11 |
| 18 | + |
| 19 | +# Handle "all non-major updates" PRs |
| 20 | +node cli.js \ |
| 21 | + -R time-loop/*-cdk \ |
| 22 | + -T ghp_TOKEN \ |
| 23 | + --majorVersion all |
| 24 | + |
| 25 | +# Handle projen update PRs |
| 26 | +node cli.js \ |
| 27 | + -R time-loop/*-cdk \ |
| 28 | + -T ghp_TOKEN \ |
| 29 | + --majorVersion projen |
| 30 | +``` |
| 31 | + |
| 32 | +### Testing |
| 33 | +```bash |
| 34 | +npm test # Alias for: node script.js |
| 35 | +npm start # Alias for: node cli.js |
| 36 | +``` |
| 37 | + |
| 38 | +## Architecture |
| 39 | + |
| 40 | +### Core Files |
| 41 | +- **cli.js** - Entry point that imports and runs the script using `@octoherd/cli/run` |
| 42 | +- **script.js** - Main script logic exported as `async function script(octokit, repository, options)` |
| 43 | + |
| 44 | +### Workflow Logic (script.js) |
| 45 | + |
| 46 | +The script follows this sequence for each repository: |
| 47 | + |
| 48 | +1. **Safety checks** (lines 46-61): |
| 49 | + - Skip archived repositories |
| 50 | + - Check for `octoherd-no-touch` topic to skip protected repos |
| 51 | + |
| 52 | +2. **PR Discovery** (lines 63-100): |
| 53 | + - Search for PRs matching the expected title pattern |
| 54 | + - For special cases (`all` and `projen`), check `maxAgeDays` to avoid stale merged PRs |
| 55 | + - Skip if PR is already merged, closed, or in draft state |
| 56 | + |
| 57 | +3. **PR Validation** (lines 104-191): |
| 58 | + - Uses GraphQL query to fetch comprehensive PR status |
| 59 | + - Checks: mergeable state, review decision, CI status (statusCheckRollup) |
| 60 | + - Exits early if PR cannot be updated, CI failing, or conflicts exist |
| 61 | + |
| 62 | +4. **Auto-approval** (lines 193-239): |
| 63 | + - Attempts to approve PR if not already approved and viewer can approve |
| 64 | + - Re-checks approval status after attempting approval |
| 65 | + |
| 66 | +5. **Merge** (lines 241-253): |
| 67 | + - Squash merges the PR with standardized commit title format |
| 68 | + |
| 69 | +6. **Workflow Re-run** (lines 256-305): |
| 70 | + - If no PR exists, finds the relevant workflow (renovate.yml or update-projen-main.yml) |
| 71 | + - Checks if workflow is already running |
| 72 | + - Validates that at least 30 minutes have passed since the last workflow run (throttling) |
| 73 | + - Re-runs the last workflow if it's not currently active and throttle period has elapsed |
| 74 | + - Throttling prevents excessive CI usage when the script runs frequently |
| 75 | + |
| 76 | +### Special Cases |
| 77 | + |
| 78 | +The script handles three distinct patterns via the `--majorVersion` parameter: |
| 79 | + |
| 80 | +- **Standard major version** (e.g., `v11`): Targets PRs like "fix(deps): update dependency @time-loop/cdk-library to v11" |
| 81 | +- **`all`**: Targets "fix(deps): update all non-major dependencies" PRs, uses `maxAgeDays` parameter |
| 82 | +- **`projen`**: Targets "fix(deps): upgrade projen" PRs from `update-projen-main` workflow, uses `maxAgeDays` parameter |
| 83 | + |
| 84 | +### Options |
| 85 | + |
| 86 | +- `--majorVersion` (required): Major version (e.g., `v11`), `all`, or `projen` |
| 87 | +- `--library` (default: `@time-loop/cdk-library`): Library name (ignored for `all` and `projen`) |
| 88 | +- `--maxAgeDays` (default: 7): Maximum age in days for merged PRs (only used with `all` and `projen`) |
| 89 | +- `--merge` (default: true): Whether to merge PRs. Use `--no-merge` to validate PRs without actually merging them |
| 90 | + |
| 91 | +### PAT Requirements |
| 92 | + |
| 93 | +The GitHub Personal Access Token needs: |
| 94 | +- `repo` - Full control of private repositories |
| 95 | + |
| 96 | +## Key Implementation Details |
| 97 | + |
| 98 | +- Uses `@octoherd/cli` framework for multi-repository operations |
| 99 | +- Combines REST API and GraphQL for comprehensive PR status checking |
| 100 | +- Workflow re-run logic ensures Renovate runs are triggered when PRs don't exist |
| 101 | +- The `noTouchTopicName` constant (`octoherd-no-touch`) provides escape hatch for repositories |
0 commit comments