split-by-codeowners 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -29
- package/action.yml +1 -1
- package/dist/index.js +8 -24
- package/dist/index.js.map +1 -1
- package/dist-cli/index.js +11 -31
- package/dist-cli/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,6 @@ steps:
|
|
|
32
32
|
- name: Split into CODEOWNERS PRs
|
|
33
33
|
uses: anatoliisf/split-by-codeowners@v1
|
|
34
34
|
with:
|
|
35
|
-
create_prs: "true"
|
|
36
35
|
github_token: ${{ github.token }}
|
|
37
36
|
```
|
|
38
37
|
|
|
@@ -55,34 +54,34 @@ npx split-by-codeowners --create-prs --base-branch main
|
|
|
55
54
|
|
|
56
55
|
### Inputs
|
|
57
56
|
|
|
58
|
-
| Name
|
|
59
|
-
|
|
|
60
|
-
| `codeowners_path`
|
|
61
|
-
| `base_ref`
|
|
62
|
-
| `include_unowned`
|
|
63
|
-
| `unowned_bucket_key` | no
|
|
64
|
-
| `max_buckets`
|
|
65
|
-
| `exclude_patterns`
|
|
66
|
-
| `patch_dir`
|
|
67
|
-
| `bucket_prefix`
|
|
68
|
-
| `dry_run`
|
|
69
|
-
| `cleanup_patches`
|
|
70
|
-
| `create_prs`
|
|
71
|
-
| `github_token`
|
|
72
|
-
| `base_branch`
|
|
73
|
-
| `branch_prefix`
|
|
74
|
-
| `commit_message`
|
|
75
|
-
| `pr_title`
|
|
76
|
-
| `pr_body`
|
|
77
|
-
| `draft`
|
|
57
|
+
| Name | Required | Default | Description |
|
|
58
|
+
| -------------------- | -------- | ------------------------------------- | ----------------------------------------------------------------------------- |
|
|
59
|
+
| `codeowners_path` | no | `CODEOWNERS` | Path to CODEOWNERS file |
|
|
60
|
+
| `base_ref` | no | `""` | Base ref for changed-files discovery (currently workspace-focused; see notes) |
|
|
61
|
+
| `include_unowned` | no | `"true"` | Include files with no owners in a special bucket |
|
|
62
|
+
| `unowned_bucket_key` | no | `__UNOWNED__` | Bucket key for unowned files |
|
|
63
|
+
| `max_buckets` | no | `"30"` | Fail if buckets exceed this number |
|
|
64
|
+
| `exclude_patterns` | no | `""` | Newline-separated glob patterns to exclude (minimatch) |
|
|
65
|
+
| `patch_dir` | no | `bucket-patches` | Directory to write per-bucket patch files |
|
|
66
|
+
| `bucket_prefix` | no | `bucket` | Patch file prefix |
|
|
67
|
+
| `dry_run` | no | `"false"` | Compute buckets but don’t write patches |
|
|
68
|
+
| `cleanup_patches` | no | `"false"` | Delete `patch_dir` after a successful run |
|
|
69
|
+
| `create_prs` | no | `"false"` | Create/update one PR per bucket |
|
|
70
|
+
| `github_token` | no | `""` | Token used for pushing branches + GitHub API (defaults to env `GITHUB_TOKEN`) |
|
|
71
|
+
| `base_branch` | no | `""` | Base branch for PRs (defaults to repo default branch) |
|
|
72
|
+
| `branch_prefix` | no | `codemods/` | Prefix for created branches |
|
|
73
|
+
| `commit_message` | no | `chore: automated changes` | Commit message for bucket PRs |
|
|
74
|
+
| `pr_title` | no | `chore: automated changes ({owners})` | PR title template (`{owners}`, `{bucket_key}`) |
|
|
75
|
+
| `pr_body` | no | *(see `action.yml`)* | PR body template (`{owners}`, `{bucket_key}`, `{files}`) |
|
|
76
|
+
| `draft` | no | `"false"` | Create PRs as drafts |
|
|
78
77
|
|
|
79
78
|
### Outputs
|
|
80
79
|
|
|
81
|
-
| Name
|
|
82
|
-
|
|
|
83
|
-
| `matrix_json`
|
|
80
|
+
| Name | Description |
|
|
81
|
+
| -------------- | ------------------------------------------------- |
|
|
82
|
+
| `matrix_json` | JSON for `strategy.matrix` (`{ include: [...] }`) |
|
|
84
83
|
| `buckets_json` | Full buckets JSON (owners + files + matched rule) |
|
|
85
|
-
| `prs_json`
|
|
84
|
+
| `prs_json` | If `create_prs=true`, list of created/updated PRs |
|
|
86
85
|
|
|
87
86
|
### Example: bucketize only (matrix + patches)
|
|
88
87
|
|
|
@@ -117,6 +116,32 @@ The CLI operates on your **current working tree** (modified + untracked files) a
|
|
|
117
116
|
npx split-by-codeowners --help
|
|
118
117
|
```
|
|
119
118
|
|
|
119
|
+
### Options
|
|
120
|
+
|
|
121
|
+
#### Common
|
|
122
|
+
|
|
123
|
+
- **`--codeowners <path>`**: Path to CODEOWNERS file (default: `CODEOWNERS`)
|
|
124
|
+
- **`--exclude <file|->`**: File containing newline-separated glob patterns to exclude, or `-` to read from stdin
|
|
125
|
+
- **`--include-unowned <true|false>`**: Include files with no owners in an `__UNOWNED__` bucket (default: `true`)
|
|
126
|
+
- **`--unowned-bucket-key <key>`**: Bucket key for unowned files (default: `__UNOWNED__`)
|
|
127
|
+
- **`--max-buckets <n>`**: Fail if number of buckets exceeds `n` (default: `30`)
|
|
128
|
+
- **`--patch-dir <dir>`**: Directory to write patch files (default: `bucket-patches`)
|
|
129
|
+
- **`--bucket-prefix <prefix>`**: Patch file prefix (default: `bucket`)
|
|
130
|
+
- **`--dry-run`**: Compute buckets but don’t write patches
|
|
131
|
+
- **`--cleanup-patches`**: Delete `patch_dir` after a successful run (default in this repo: enabled)
|
|
132
|
+
|
|
133
|
+
#### PR creation
|
|
134
|
+
|
|
135
|
+
- **`--create-prs`**: Create/update one PR per bucket (local: uses `gh` auth)
|
|
136
|
+
- **`--base-branch <branch>`**: Base branch for PRs (default: repo default branch)
|
|
137
|
+
- **`--branch-prefix <prefix>`**: Branch prefix for bucket branches (default: `codemods/`)
|
|
138
|
+
- **`--commit-message <msg>`**: Commit message for bucket commits
|
|
139
|
+
- **`--pr-title <tpl>`**: Title template (supports `{owners}`, `{bucket_key}`)
|
|
140
|
+
- **`--pr-body <tpl>`**: Body template (supports `{owners}`, `{bucket_key}`, `{files}`)
|
|
141
|
+
- **`--pr-body-mode <mode>`**: `custom|template|template_with_bucket|none`
|
|
142
|
+
- **`--pr-template-path <path>`**: PR template file path (used when `pr_body_mode=template*`)
|
|
143
|
+
- **`--draft <true|false>`**: Create PRs as drafts (default: `false`)
|
|
144
|
+
|
|
120
145
|
### Common examples
|
|
121
146
|
|
|
122
147
|
Exclude some paths:
|
|
@@ -131,11 +156,10 @@ Create/update PRs:
|
|
|
131
156
|
npx split-by-codeowners --create-prs --base-branch main
|
|
132
157
|
```
|
|
133
158
|
|
|
134
|
-
|
|
159
|
+
Use the repo PR template for PR creation (recommended):
|
|
135
160
|
|
|
136
161
|
```bash
|
|
137
|
-
|
|
138
|
-
npx split-by-codeowners --create-prs --token "$GH_TOKEN" --base-branch main
|
|
162
|
+
npx split-by-codeowners --create-prs --pr-body-mode template_with_bucket
|
|
139
163
|
```
|
|
140
164
|
|
|
141
165
|
### Notes on local PR creation
|
|
@@ -176,6 +200,5 @@ npm run build
|
|
|
176
200
|
|
|
177
201
|
This repo includes a manual workflow: `.github/workflows/publish-npm.yml`.
|
|
178
202
|
|
|
179
|
-
- Create an npm token with publish rights and add it as repo secret **`NPM_TOKEN`**.
|
|
180
203
|
- Bump `package.json` version and ensure `dist/` and `dist-cli/` are up to date.
|
|
181
204
|
- Run the workflow from the GitHub Actions UI (`workflow_dispatch`).
|
package/action.yml
CHANGED
|
@@ -59,7 +59,7 @@ inputs:
|
|
|
59
59
|
create_prs:
|
|
60
60
|
description: "If true, create/update one PR per bucket by pushing branches and calling GitHub API."
|
|
61
61
|
required: false
|
|
62
|
-
default: "
|
|
62
|
+
default: "true"
|
|
63
63
|
|
|
64
64
|
github_token:
|
|
65
65
|
description: "GitHub token used for API + pushing branches. Defaults to GITHUB_TOKEN."
|
package/dist/index.js
CHANGED
|
@@ -27542,34 +27542,18 @@ async function runSplit(config, logger) {
|
|
|
27542
27542
|
const isGitHubActions = process.env.GITHUB_ACTIONS === "true";
|
|
27543
27543
|
// Auth mode selection:
|
|
27544
27544
|
// - In GitHub Actions: ALWAYS use token-based API (gh may not be installed/auth'd).
|
|
27545
|
-
// - Locally:
|
|
27546
|
-
if (isGitHubActions
|
|
27547
|
-
|
|
27548
|
-
|
|
27549
|
-
let useGhCli = !isGitHubActions;
|
|
27550
|
-
let octokit = useGhCli ? null : (0, github_1.getOctokit)(token);
|
|
27551
|
-
let baseBranch;
|
|
27552
|
-
if (useGhCli) {
|
|
27553
|
-
try {
|
|
27554
|
-
const cwd = process.cwd();
|
|
27555
|
-
(0, ghcli_1.assertGhAuthenticated)(cwd);
|
|
27556
|
-
baseBranch = config.baseBranch || (0, ghcli_1.getDefaultBranchViaGh)(cwd);
|
|
27557
|
-
}
|
|
27558
|
-
catch (e) {
|
|
27559
|
-
if (token) {
|
|
27560
|
-
logger.warn("gh is not authenticated; falling back to token auth.");
|
|
27561
|
-
useGhCli = false;
|
|
27562
|
-
octokit = (0, github_1.getOctokit)(token);
|
|
27563
|
-
baseBranch = config.baseBranch || (await (0, github_1.getDefaultBranch)(octokit, repo));
|
|
27564
|
-
}
|
|
27565
|
-
else {
|
|
27566
|
-
throw e;
|
|
27567
|
-
}
|
|
27545
|
+
// - Locally: ALWAYS use gh CLI for best DevX (no token-based local mode).
|
|
27546
|
+
if (isGitHubActions) {
|
|
27547
|
+
if (!token) {
|
|
27548
|
+
throw new Error("Missing GitHub token (set github_token input or GITHUB_TOKEN / GH_TOKEN env var)");
|
|
27568
27549
|
}
|
|
27569
27550
|
}
|
|
27570
27551
|
else {
|
|
27571
|
-
|
|
27552
|
+
(0, ghcli_1.assertGhAuthenticated)(process.cwd());
|
|
27572
27553
|
}
|
|
27554
|
+
const useGhCli = !isGitHubActions;
|
|
27555
|
+
const octokit = useGhCli ? null : (0, github_1.getOctokit)(token);
|
|
27556
|
+
const baseBranch = config.baseBranch || (useGhCli ? (0, ghcli_1.getDefaultBranchViaGh)(process.cwd()) : await (0, github_1.getDefaultBranch)(octokit, repo));
|
|
27573
27557
|
const baseRef = "HEAD";
|
|
27574
27558
|
ensureDirExists((0, git_1.worktreeBaseDir)());
|
|
27575
27559
|
prs = [];
|