codeowners-git 1.8.0 → 2.0.1

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.
Files changed (3) hide show
  1. package/README.md +184 -41
  2. package/dist/cli.js +702 -494
  3. package/package.json +4 -2
package/README.md CHANGED
@@ -13,7 +13,7 @@ Managing large-scale migrations in big monorepos with multiple codeowners can be
13
13
  - Streamlining the review process with smaller, targeted PRs.
14
14
  - **Graceful error handling** with automatic recovery from failures.
15
15
 
16
- > **Note:** This tool works with **unstaged files**. Make sure to check if your files are unstaged before proceeding.
16
+ > ❗❗ ❗ **Note:** Starting from v2.0.0, this tool works with **staged files**. Stage your changes with `git add` before running commands.
17
17
 
18
18
  https://github.com/user-attachments/assets/7cc0a924-f03e-47f3-baad-63eca9e8e4a8
19
19
 
@@ -73,6 +73,44 @@ The tool will automatically:
73
73
  - Set the PR title to your commit message
74
74
  - Create PRs against the repository's default branch
75
75
 
76
+ ### Owner Pattern Matching
77
+
78
+ The `--include` and `--ignore` options support glob patterns for flexible owner filtering:
79
+
80
+ | Pattern | Description | Example Match |
81
+ | ------------ | ----------------- | ---------------------------------- |
82
+ | `@org/team` | Exact match | `@org/team` only |
83
+ | `*team` | Ends with | `@org/team`, `@company/team` |
84
+ | `@org/*` | Starts with (org) | `@org/team-a`, `@org/team-b` |
85
+ | `*ce-*` | Contains | `@org/ce-orca`, `@company/ce-team` |
86
+ | `*orca,*rme` | Multiple patterns | Either pattern matches |
87
+
88
+ **Key behavior:**
89
+
90
+ - `*` matches any character **including `/`** (slashes are normalized)
91
+ - `*/ce-orca` and `*ce-orca` behave identically
92
+ - Patterns are case-sensitive
93
+ - Multiple patterns can be comma-separated
94
+
95
+ ### Path Pattern Matching
96
+
97
+ Path patterns use [micromatch](https://github.com/micromatch/micromatch) syntax:
98
+
99
+ | Pattern | Description | Example Match |
100
+ | ----------------------- | ------------------------------ | ----------------------------------------------- |
101
+ | `src` | Directory (auto-appends `/**`) | All files in `src/` |
102
+ | `src/` | Directory with trailing slash | All files in `src/` |
103
+ | `**/*.ts` | Glob pattern | All `.ts` files |
104
+ | `{src,docs}` | Brace expansion | Files in `src/` or `docs/` |
105
+ | `packages/{a,b}/**` | Combined | Files in `packages/a/` or `packages/b/` |
106
+ | `packages/**/{foo,bar}` | Nested braces | Directories named `foo` or `bar` under packages |
107
+
108
+ **Key behavior:**
109
+
110
+ - Directories without glob chars automatically match all files inside (`src` → `src/**`)
111
+ - Use brace expansion `{a,b}` for multiple patterns (not comma-separated)
112
+ - Supports full micromatch/glob syntax: `*`, `**`, `?`, `[...]`, `{...}`
113
+
76
114
  ## Commands
77
115
 
78
116
  ### `--version`
@@ -91,44 +129,78 @@ cg --version
91
129
 
92
130
  ### `list`
93
131
 
94
- List current CODEOWNERS entries.
132
+ List changed files with their CODEOWNERS.
95
133
 
96
134
  Usage:
97
135
 
98
136
  ```bash
99
- codeowners-git list [options]
137
+ codeowners-git list [pattern] [options]
100
138
  # or
101
- cg list [options]
139
+ cg list [pattern] [options]
102
140
  ```
103
141
 
142
+ Arguments:
143
+
144
+ - `[pattern]` Optional path pattern to filter files (micromatch syntax)
145
+
104
146
  Options:
105
147
 
106
- - `--owner, -o` Filter by specific owner
107
- - `--include, -i` Include specific patterns
148
+ - `--include, -i` Filter by owner patterns (glob syntax)
149
+ - `--group, -g` Group files by code owner
150
+ - `--exclusive, -e` Only include files with a single owner (no co-owned files)
151
+ - `--co-owned, -c` Only include files with multiple owners (co-owned files)
108
152
 
109
- Example:
153
+ Examples:
110
154
 
111
155
  ```bash
112
- codeowners-git list -o @myteam
113
- # or
114
- cg list -o @myteam
156
+ # List all changed files with owners
157
+ cg list
158
+
159
+ # Filter by path pattern
160
+ cg list src/
161
+ cg list "packages/{basics,shared}/**"
162
+
163
+ # Filter by owner pattern
164
+ cg list --include "*ce-*"
165
+
166
+ # Group output by owner
167
+ cg list --group
168
+
169
+ # Combine filters
170
+ cg list "packages/" --include "@myorg/*" --group
171
+
172
+ # List only files with a single owner (exclude co-owned files)
173
+ cg list --exclusive
174
+
175
+ # List only files where @myteam is the sole owner
176
+ cg list --include "@myteam" --exclusive
177
+
178
+ # List only co-owned files (files with multiple owners)
179
+ cg list --co-owned
180
+
181
+ # List co-owned files where @myteam is one of the owners
182
+ cg list --include "@myteam" --co-owned
115
183
  ```
116
184
 
117
185
  ### `branch`
118
186
 
119
- Manage branch permissions in CODEOWNERS file.
187
+ Create a branch with changes owned by a specific codeowner.
120
188
 
121
189
  Usage:
122
190
 
123
191
  ```bash
124
- codeowners-git branch [options]
192
+ codeowners-git branch [pattern] [options]
125
193
  # or
126
- cg branch [options]
194
+ cg branch [pattern] [options]
127
195
  ```
128
196
 
197
+ Arguments:
198
+
199
+ - `[pattern]` Optional path pattern to filter files (micromatch syntax). Examples: `packages`, `**/*.tsx`, `{packages,apps}`
200
+
129
201
  Options:
130
202
 
131
- - `--owner, -o` Specify owner(s) to add/remove
203
+ - `--include, -i` Code owner pattern to filter files (supports glob patterns like `*team`, `@org/*`)
132
204
  - `--branch, -b` Specify branch pattern
133
205
  - `--message, -m` Commit message for changes
134
206
  - `--no-verify, -n` Skips lint-staged and other checks before committing
@@ -140,23 +212,47 @@ Options:
140
212
  - `--append` Add commits to existing branch instead of creating a new one
141
213
  - `--pr` Create a pull request after pushing (requires `--push` and GitHub CLI)
142
214
  - `--draft-pr` Create a draft pull request after pushing (requires `--push` and GitHub CLI)
215
+ - `--exclusive, -e` Only include files where the owner is the sole owner (no co-owned files)
216
+ - `--co-owned, -c` Only include files with multiple owners (co-owned files)
143
217
 
144
218
  Example:
145
219
 
146
220
  ```bash
147
- # Create a new branch
148
- codeowners-git branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p
149
- # or
150
- cg branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p
221
+ # Create a new branch with all files owned by @myteam
222
+ cg branch -i @myteam -b "feature/new-feature" -m "Add new feature" -p
223
+
224
+ # Filter to only files in the packages directory
225
+ cg branch "packages" -i @myteam -b "feature/packages" -m "Update packages" -p
226
+
227
+ # Filter with glob pattern (only .tsx files)
228
+ cg branch "**/*.tsx" -i @myteam -b "feature/tsx" -m "Update tsx files" -p
229
+
230
+ # Filter multiple directories (brace expansion)
231
+ cg branch "{packages,apps}" -i @myteam -b "feature/update" -m "Update packages and apps" -p
151
232
 
152
233
  # Create a branch and automatically create a pull request
153
- cg branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p --pr
234
+ cg branch -i @myteam -b "feature/new-feature" -m "Add new feature" -p --pr
154
235
 
155
236
  # Create a branch and automatically create a draft pull request
156
- cg branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p --draft-pr
237
+ cg branch -i @myteam -b "feature/new-feature" -m "Add new feature" -p --draft-pr
157
238
 
158
239
  # Add more commits to the same branch later
159
- cg branch -o @myteam -b "feature/new-feature" -m "Add more changes" --append -p
240
+ cg branch -i @myteam -b "feature/new-feature" -m "Add more changes" --append -p
241
+
242
+ # Use glob patterns to match multiple teams
243
+ cg branch -i "*ce-*" -b "feature/ce-teams" -m "Changes for CE teams" -p
244
+
245
+ # Match all teams in an organization
246
+ cg branch -i "@myorg/*" -b "feature/org-changes" -m "Org-wide changes" -p
247
+
248
+ # Match multiple specific patterns
249
+ cg branch -i "*orca,*rme" -b "feature/specific-teams" -m "Targeted changes" -p
250
+
251
+ # Only include files where @myteam is the sole owner (exclude co-owned files)
252
+ cg branch -i @myteam -b "feature/exclusive" -m "Team exclusive changes" -p --exclusive
253
+
254
+ # Only include co-owned files where @myteam is one of the owners
255
+ cg branch -i @myteam -b "feature/co-owned" -m "Co-owned changes" -p --co-owned
160
256
  ```
161
257
 
162
258
  ### `multi-branch`
@@ -166,11 +262,15 @@ Create branches for all codeowners with changes.
166
262
  Usage:
167
263
 
168
264
  ```bash
169
- codeowners-git multi-branch [options]
265
+ codeowners-git multi-branch [pattern] [options]
170
266
  # or
171
- cg multi-branch [options]
267
+ cg multi-branch [pattern] [options]
172
268
  ```
173
269
 
270
+ Arguments:
271
+
272
+ - `[pattern]` Optional path pattern to filter files (micromatch syntax). Examples: `packages`, `**/*.tsx`, `{packages,apps}`
273
+
174
274
  Options:
175
275
 
176
276
  - `--branch, -b` Base branch name (will be suffixed with codeowner name)
@@ -182,44 +282,65 @@ Options:
182
282
  - `--force, -f` Force push to remote
183
283
  - `--keep-branch-on-failure, -k` Keep created branches even if operation fails
184
284
  - `--default-owner, -d` Default owner to use when no codeowners are found for changed files
185
- - `--ignore` Comma-separated patterns to exclude codeowners (e.g., 'team-a,team-b')
186
- - `--include` Comma-separated patterns to include codeowners (e.g., 'team-_,@org/_')
285
+ - `--ignore` Glob patterns to exclude codeowners (e.g., `*team-a`, `@org/*`)
286
+ - `--include` Glob patterns to include codeowners (e.g., `*ce-*`, `@org/*`)
187
287
  - `--append` Add commits to existing branches instead of creating new ones
188
288
  - `--pr` Create pull requests after pushing (requires `--push` and GitHub CLI)
189
289
  - `--draft-pr` Create draft pull requests after pushing (requires `--push` and GitHub CLI)
290
+ - `--exclusive, -e` Only include files where each owner is the sole owner (no co-owned files)
291
+ - `--co-owned, -c` Only include files with multiple owners (co-owned files)
190
292
 
191
- > **Note:** You cannot use both `--ignore` and `--include` options at the same time.
293
+ > **Note:** You cannot use both `--ignore` and `--include` options at the same time. You also cannot use both `--exclusive` and `--co-owned` options at the same time.
192
294
 
193
295
  Example:
194
296
 
195
297
  ```bash
196
298
  # Create branches for all codeowners
197
- codeowners-git multi-branch -b "feature/new-feature" -m "Add new feature" -p
198
- # or
199
299
  cg multi-branch -b "feature/new-feature" -m "Add new feature" -p
200
300
 
301
+ # Filter to only files in the packages directory
302
+ cg multi-branch "packages" -b "feature/packages" -m "Update packages" -p
303
+
304
+ # Filter with glob pattern (only .tsx files)
305
+ cg multi-branch "**/*.tsx" -b "feature/tsx" -m "Update tsx files" -p
306
+
307
+ # Filter multiple directories (brace expansion)
308
+ cg multi-branch "{packages,apps}" -b "feature/update" -m "Update" -p
309
+
201
310
  # Create branches and automatically create pull requests for each
202
311
  cg multi-branch -b "feature/new-feature" -m "Add new feature" -p --pr
203
312
 
204
313
  # Create branches and automatically create draft pull requests for each
205
314
  cg multi-branch -b "feature/new-feature" -m "Add new feature" -p --draft-pr
206
315
 
207
- # Exclude specific teams
208
- cg multi-branch -b "feature/new-feature" -m "Add new feature" --ignore "@ce-orca,@ce-ece"
316
+ # Exclude specific teams using glob patterns
317
+ cg multi-branch -b "feature/new-feature" -m "Add new feature" --ignore "*ce-orca,*ce-ece"
318
+
319
+ # Exclude all teams in an organization
320
+ cg multi-branch -b "feature/new-feature" -m "Add new feature" --ignore "@excluded-org/*"
321
+
322
+ # Include only teams matching a pattern
323
+ cg multi-branch -b "feature/new-feature" -m "Add new feature" --include "*ce-*"
209
324
 
210
- # Include only specific patterns
211
- cg multi-branch -b "feature/new-feature" -m "Add new feature" --include "@team-*"
325
+ # Include only specific organization
326
+ cg multi-branch -b "feature/new-feature" -m "Add new feature" --include "@myorg/*"
212
327
 
213
328
  # Use default owner when no codeowners found
214
329
  cg multi-branch -b "feature/new-feature" -m "Add new feature" -d "@default-team"
215
330
 
216
331
  # Add more commits to existing branches
217
332
  cg multi-branch -b "feature/new-feature" -m "Add more changes" --append -p
333
+
334
+ # Only include files where each owner is the sole owner (exclude co-owned files)
335
+ cg multi-branch -b "feature/exclusive" -m "Exclusive changes" -p --exclusive
336
+
337
+ # Only include co-owned files
338
+ cg multi-branch -b "feature/co-owned" -m "Co-owned changes" -p --co-owned
218
339
  ```
219
340
 
220
341
  This will:
221
342
 
222
- 1. Find all codeowners for the staged files in your repository
343
+ 1. Find all codeowners for the staged files
223
344
  2. Apply any ignore/include filters if specified
224
345
  3. For each codeowner (e.g., @team-a, @team-b):
225
346
  - Create a branch like `feature/new-feature/team-a`
@@ -229,21 +350,27 @@ This will:
229
350
 
230
351
  ### `extract`
231
352
 
232
- Extract file changes from a source branch or commit to your working directory (unstaged). This is useful when you want to copy changes from another branch to review and then commit using the `branch` command.
353
+ Extract file changes from a source branch or commit to your working directory. This is useful when you want to copy changes from another branch to review and then stage them for committing using the `branch` command.
233
354
 
234
355
  Usage:
235
356
 
236
357
  ```bash
237
- codeowners-git extract [options]
358
+ codeowners-git extract [pattern] [options]
238
359
  # or
239
- cg extract [options]
360
+ cg extract [pattern] [options]
240
361
  ```
241
362
 
363
+ Arguments:
364
+
365
+ - `[pattern]` Optional path pattern to filter files (micromatch syntax). Examples: `packages`, `**/*.tsx`, `{packages,apps}`
366
+
242
367
  Options:
243
368
 
244
369
  - `--source, -s` **(required)** Source branch or commit to extract from
245
- - `--owner, -o` Filter extracted files by code owner (supports micromatch patterns like `@team-*`)
370
+ - `--include, -i` Filter extracted files by code owner (supports glob patterns like `*team`, `@org/*`)
246
371
  - `--compare-main` Compare source against main branch instead of detecting merge-base
372
+ - `--exclusive, -e` Only include files where the owner is the sole owner (no co-owned files)
373
+ - `--co-owned, -c` Only include files with multiple owners (co-owned files)
247
374
 
248
375
  Examples:
249
376
 
@@ -251,18 +378,34 @@ Examples:
251
378
  # Extract all changes from a branch (files will be unstaged in working directory)
252
379
  cg extract -s feature/other-team
253
380
 
254
- # Extract only specific owner's files using micromatch patterns
255
- cg extract -s feature/other-team -o "@my-team"
256
- cg extract -s feature/other-team -o "@team-*"
381
+ # Extract only specific owner's files
382
+ cg extract -s feature/other-team -i "@my-team"
383
+
384
+ # Extract using glob patterns
385
+ cg extract -s feature/other-team -i "*ce-*"
386
+ cg extract -s feature/other-team -i "@myorg/*"
257
387
 
258
388
  # Extract from a commit hash
259
389
  cg extract -s abc123def
260
390
 
261
391
  # Extract comparing against main (instead of detecting merge-base)
262
392
  cg extract -s feature/long-running --compare-main
393
+
394
+ # Filter by path pattern
395
+ cg extract "packages/" -s feature/other-team
396
+ cg extract "{packages,apps}" -s feature/other-team -i "@my-team"
397
+
398
+ # Extract only files where owner is the sole owner (no co-owned files)
399
+ cg extract -s feature/other-team -i "@my-team" --exclusive
400
+
401
+ # Extract only co-owned files (files with multiple owners)
402
+ cg extract -s feature/other-team --co-owned
403
+
404
+ # Extract co-owned files where @my-team is one of the owners
405
+ cg extract -s feature/other-team -i "@my-team" --co-owned
263
406
  ```
264
407
 
265
- > **Note:** Files are extracted unstaged, allowing you to review and modify them. Use the `branch` command afterward to create a branch, commit, push, and create PRs.
408
+ > **Note:** Files are extracted to your working directory (unstaged), allowing you to review and modify them. Stage the files with `git add`, then use the `branch` command to create a branch, commit, push, and create PRs.
266
409
 
267
410
  ### `recover`
268
411