-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add Node.js version of add-codeowners-to-repositories #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
a94ad2a
feat: add add-codeowners-to-repositories node.js script
joshjohanning 34ad73d
feat: add options for creating pull requests in add-codeowners script
joshjohanning 1a1457b
docs: update README to streamline options section and remove usage ex…
joshjohanning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # add-codeowners-to-repositories | ||
|
|
||
| Adds a CODEOWNERS file to the default branch in a list of repositories. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js 18+ | ||
| - `GITHUB_TOKEN` environment variable with `repo` scope | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Description | | ||
| |--------|-------------| | ||
| | `--repos-file <file>` | File containing list of repositories (org/repo format, one per line) | | ||
| | `--codeowners <file>` | Path to the CODEOWNERS file to add | | ||
| | `--overwrite` | Overwrite existing CODEOWNERS file (default: append) | | ||
| | `--create-pr` | Create a pull request instead of committing directly | | ||
| | `--branch <name>` | Branch name for PR (default: `add-codeowners`) | | ||
| | `--pr-title <title>` | PR title (default: `Add CODEOWNERS file`) | | ||
| | `--dry-run` | Show what would be done without making changes | | ||
| | `--concurrency <n>` | Number of concurrent API calls (default: 10) | | ||
| | `--help` | Show help message | | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| | Variable | Description | | ||
| |----------|-------------| | ||
| | `GITHUB_TOKEN` | GitHub PAT with `repo` scope (required) | | ||
| | `GITHUB_API_URL` | API endpoint (defaults to `https://api.github.com`) | | ||
|
|
||
| ## Input File Format | ||
|
|
||
| The repos file should contain one repository per line in `org/repo` format: | ||
|
|
||
| ``` | ||
| my-org/repo-1 | ||
| my-org/repo-2 | ||
| other-org/repo-3 | ||
| ``` | ||
|
|
||
| Lines starting with `#` are treated as comments and ignored. Empty lines are also ignored. | ||
|
|
||
| ## Behavior | ||
|
|
||
| - Checks for existing CODEOWNERS in: `CODEOWNERS`, `.github/CODEOWNERS`, `docs/CODEOWNERS` | ||
| - By default, appends new content to existing CODEOWNERS file | ||
| - With `--overwrite`, replaces the entire CODEOWNERS file | ||
| - Creates CODEOWNERS in the root if it doesn't exist | ||
| - With `--create-pr`, creates a branch and pull request for review | ||
|
|
||
| ## Examples | ||
|
|
||
| Add CODEOWNERS (append mode): | ||
|
|
||
| ```bash | ||
| node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS | ||
| ``` | ||
|
|
||
| Add CODEOWNERS (overwrite mode): | ||
|
|
||
| ```bash | ||
| node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --overwrite | ||
| ``` | ||
|
|
||
| Create PRs instead of committing directly: | ||
|
|
||
| ```bash | ||
| node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --create-pr | ||
| ``` | ||
|
|
||
| Create PRs with custom branch name and title: | ||
|
|
||
| ```bash | ||
| node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --create-pr --branch my-branch --pr-title "Add CODEOWNERS for compliance" | ||
| ``` | ||
|
|
||
| Dry run to see what would happen: | ||
|
|
||
| ```bash | ||
| node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS --dry-run | ||
| ``` | ||
|
|
||
| With GitHub Enterprise Server: | ||
|
|
||
| ```bash | ||
| GITHUB_API_URL=https://github.example.com/api/v3 node add-codeowners-to-repositories.js --repos-file repos.txt --codeowners ./CODEOWNERS | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.