|
| 1 | +# add-codeowners-to-repositories |
| 2 | + |
| 3 | +Adds a CODEOWNERS file to the default branch in a list of repositories. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js 18+ |
| 8 | +- `GITHUB_TOKEN` environment variable with `repo` scope |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +```bash |
| 13 | +npm install |
| 14 | +``` |
| 15 | + |
| 16 | +## Options |
| 17 | + |
| 18 | +| Option | Description | |
| 19 | +|--------|-------------| |
| 20 | +| `--repos-file <file>` | File containing list of repositories (org/repo format, one per line) | |
| 21 | +| `--codeowners <file>` | Path to the CODEOWNERS file to add | |
| 22 | +| `--overwrite` | Overwrite existing CODEOWNERS file (default: append) | |
| 23 | +| `--create-pr` | Create a pull request instead of committing directly | |
| 24 | +| `--branch <name>` | Branch name for PR (default: `add-codeowners`) | |
| 25 | +| `--pr-title <title>` | PR title (default: `Add CODEOWNERS file`) | |
| 26 | +| `--dry-run` | Show what would be done without making changes | |
| 27 | +| `--concurrency <n>` | Number of concurrent API calls (default: 10) | |
| 28 | +| `--help` | Show help message | |
| 29 | + |
| 30 | +### Environment Variables |
| 31 | + |
| 32 | +| Variable | Description | |
| 33 | +|----------|-------------| |
| 34 | +| `GITHUB_TOKEN` | GitHub PAT with `repo` scope (required) | |
| 35 | +| `GITHUB_API_URL` | API endpoint (defaults to `https://api.github.com`) | |
| 36 | + |
| 37 | +## Input File Format |
| 38 | + |
| 39 | +The repos file should contain one repository per line in `org/repo` format: |
| 40 | + |
| 41 | +``` |
| 42 | +my-org/repo-1 |
| 43 | +my-org/repo-2 |
| 44 | +other-org/repo-3 |
| 45 | +``` |
| 46 | + |
| 47 | +Lines starting with `#` are treated as comments and ignored. Empty lines are also ignored. |
| 48 | + |
| 49 | +## Behavior |
| 50 | + |
| 51 | +- Checks for existing CODEOWNERS in: `CODEOWNERS`, `.github/CODEOWNERS`, `docs/CODEOWNERS` |
| 52 | +- By default, appends new content to existing CODEOWNERS file |
| 53 | +- With `--overwrite`, replaces the entire CODEOWNERS file |
| 54 | +- Creates CODEOWNERS in the root if it doesn't exist |
| 55 | +- With `--create-pr`, creates a branch and pull request for review |
| 56 | + |
| 57 | +## Examples |
| 58 | + |
| 59 | +Add CODEOWNERS (append mode): |
| 60 | + |
| 61 | +```bash |
| 62 | +node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS |
| 63 | +``` |
| 64 | + |
| 65 | +Add CODEOWNERS (overwrite mode): |
| 66 | + |
| 67 | +```bash |
| 68 | +node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --overwrite |
| 69 | +``` |
| 70 | + |
| 71 | +Create PRs instead of committing directly: |
| 72 | + |
| 73 | +```bash |
| 74 | +node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --create-pr |
| 75 | +``` |
| 76 | + |
| 77 | +Create PRs with custom branch name and title: |
| 78 | + |
| 79 | +```bash |
| 80 | +node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --create-pr --branch my-branch --pr-title "Add CODEOWNERS for compliance" |
| 81 | +``` |
| 82 | + |
| 83 | +Dry run to see what would happen: |
| 84 | + |
| 85 | +```bash |
| 86 | +node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --dry-run |
| 87 | +``` |
| 88 | + |
| 89 | +With GitHub Enterprise Server: |
| 90 | + |
| 91 | +```bash |
| 92 | +GITHUB_API_URL=https://github.example.com/api/v3 node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS |
| 93 | +``` |
0 commit comments