codeowners-git 1.4.1 → 1.5.0
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 +9 -0
- package/dist/cli.js +46 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,11 +102,16 @@ Options:
|
|
|
102
102
|
- `--upstream, -u` Upstream branch name (defaults to local branch name)
|
|
103
103
|
- `--force, -f` Force push to remote
|
|
104
104
|
- `--keep-branch-on-failure, -k` Keep the created branch even if operation fails
|
|
105
|
+
- `--append` Add commits to existing branch instead of creating a new one
|
|
105
106
|
|
|
106
107
|
Example:
|
|
107
108
|
|
|
108
109
|
```bash
|
|
110
|
+
# Create a new branch
|
|
109
111
|
codeowners-git branch -o @myteam -b "feature/new-feature" -m "Add new feature" -p
|
|
112
|
+
|
|
113
|
+
# Add more commits to the same branch later
|
|
114
|
+
codeowners-git branch -o @myteam -b "feature/new-feature" -m "Add more changes" --append -p
|
|
110
115
|
```
|
|
111
116
|
|
|
112
117
|
### `multi-branch`
|
|
@@ -132,6 +137,7 @@ Options:
|
|
|
132
137
|
- `--default-owner, -d` Default owner to use when no codeowners are found for changed files
|
|
133
138
|
- `--ignore` Comma-separated patterns to exclude codeowners (e.g., 'team-a,team-b')
|
|
134
139
|
- `--include` Comma-separated patterns to include codeowners (e.g., 'team-_,@org/_')
|
|
140
|
+
- `--append` Add commits to existing branches instead of creating new ones
|
|
135
141
|
|
|
136
142
|
> **Note:** You cannot use both `--ignore` and `--include` options at the same time.
|
|
137
143
|
|
|
@@ -149,6 +155,9 @@ codeowners-git multi-branch -b "feature/new-feature" -m "Add new feature" --incl
|
|
|
149
155
|
|
|
150
156
|
# Use default owner when no codeowners found
|
|
151
157
|
codeowners-git multi-branch -b "feature/new-feature" -m "Add new feature" -d "@default-team"
|
|
158
|
+
|
|
159
|
+
# Add more commits to existing branches
|
|
160
|
+
codeowners-git multi-branch -b "feature/new-feature" -m "Add more changes" --append -p
|
|
152
161
|
```
|
|
153
162
|
|
|
154
163
|
This will:
|
package/dist/cli.js
CHANGED
|
@@ -14706,10 +14706,13 @@ var getOwner = (filePath) => {
|
|
|
14706
14706
|
const owner = instance.getOwner(filePath);
|
|
14707
14707
|
return owner;
|
|
14708
14708
|
};
|
|
14709
|
-
var getOwnerFiles = async (owner) => {
|
|
14709
|
+
var getOwnerFiles = async (owner, includeUnowned = false) => {
|
|
14710
14710
|
const changedFiles = await getChangedFiles();
|
|
14711
14711
|
return changedFiles.filter((file) => {
|
|
14712
14712
|
const owners = getOwner(file);
|
|
14713
|
+
if (includeUnowned && owners.length === 0) {
|
|
14714
|
+
return true;
|
|
14715
|
+
}
|
|
14713
14716
|
return owners.includes(owner);
|
|
14714
14717
|
});
|
|
14715
14718
|
};
|
|
@@ -14783,10 +14786,10 @@ var branch = async (options) => {
|
|
|
14783
14786
|
if (!options.branch || !options.message || !options.owner) {
|
|
14784
14787
|
throw new Error("Missing required options for branch creation");
|
|
14785
14788
|
}
|
|
14786
|
-
log.info("Starting branch creation process...");
|
|
14789
|
+
log.info(options.append ? "Starting branch update process..." : "Starting branch creation process...");
|
|
14787
14790
|
originalBranch = await getCurrentBranch();
|
|
14788
14791
|
log.info(`Currently on branch: ${originalBranch}`);
|
|
14789
|
-
filesToCommit = await getOwnerFiles(options.owner);
|
|
14792
|
+
filesToCommit = await getOwnerFiles(options.owner, options.isDefaultOwner || false);
|
|
14790
14793
|
if (filesToCommit.length <= 0) {
|
|
14791
14794
|
log.warn(`No files found for ${options.owner}. Skipping branch creation.`);
|
|
14792
14795
|
return;
|
|
@@ -14794,13 +14797,19 @@ var branch = async (options) => {
|
|
|
14794
14797
|
log.file(`Files to be committed:
|
|
14795
14798
|
${filesToCommit.join(`
|
|
14796
14799
|
`)}`);
|
|
14797
|
-
|
|
14798
|
-
|
|
14800
|
+
const branchAlreadyExists = await branchExists(options.branch);
|
|
14801
|
+
if (branchAlreadyExists && !options.append) {
|
|
14802
|
+
throw new Error(`Branch "${options.branch}" already exists. Use --append to add commits to it, or use a different name.`);
|
|
14799
14803
|
}
|
|
14800
14804
|
try {
|
|
14801
|
-
|
|
14802
|
-
|
|
14803
|
-
|
|
14805
|
+
if (branchAlreadyExists && options.append) {
|
|
14806
|
+
log.info(`Checking out existing branch "${options.branch}"...`);
|
|
14807
|
+
await checkout(options.branch);
|
|
14808
|
+
} else {
|
|
14809
|
+
log.info(`Creating new branch "${options.branch}"...`);
|
|
14810
|
+
await createBranch(options.branch);
|
|
14811
|
+
newBranchCreated = true;
|
|
14812
|
+
}
|
|
14804
14813
|
log.info(`Committing changes with message: "${options.message}" ${!options.verify ? "(no-verify)" : ""}...`);
|
|
14805
14814
|
await commitChanges(filesToCommit, {
|
|
14806
14815
|
message: options.message ?? "",
|
|
@@ -14816,7 +14825,11 @@ var branch = async (options) => {
|
|
|
14816
14825
|
}
|
|
14817
14826
|
log.info(`Checking out original branch "${originalBranch}"...`);
|
|
14818
14827
|
await checkout(originalBranch);
|
|
14819
|
-
|
|
14828
|
+
if (branchAlreadyExists && options.append) {
|
|
14829
|
+
log.success(options.push ? `Changes committed to existing branch "${options.branch}" and pushed to remote.` : `Changes committed to existing branch "${options.branch}".`);
|
|
14830
|
+
} else {
|
|
14831
|
+
log.success(options.push ? `Branch "${options.branch}" created, changes committed, and pushed to remote.` : `Branch "${options.branch}" created and changes committed.`);
|
|
14832
|
+
}
|
|
14820
14833
|
} catch (operationError) {
|
|
14821
14834
|
log.error(`Operation failed: ${operationError}`);
|
|
14822
14835
|
if (newBranchCreated) {
|
|
@@ -14863,28 +14876,32 @@ var multiBranch = async (options) => {
|
|
|
14863
14876
|
if (options.ignore && options.include) {
|
|
14864
14877
|
throw new Error("Cannot use both --ignore and --include options at the same time");
|
|
14865
14878
|
}
|
|
14866
|
-
log.info("Starting multi-branch creation process...");
|
|
14879
|
+
log.info(options.append ? "Starting multi-branch update process..." : "Starting multi-branch creation process...");
|
|
14867
14880
|
const changedFiles = await getChangedFiles();
|
|
14868
14881
|
if (changedFiles.length === 0) {
|
|
14869
14882
|
throw new Error("No changed files found in the repository");
|
|
14870
14883
|
}
|
|
14871
14884
|
const ownerSet = new Set;
|
|
14885
|
+
const filesWithoutOwners = [];
|
|
14872
14886
|
for (const file of changedFiles) {
|
|
14873
14887
|
const owners = getOwner(file);
|
|
14874
|
-
|
|
14875
|
-
|
|
14888
|
+
if (owners.length === 0) {
|
|
14889
|
+
filesWithoutOwners.push(file);
|
|
14890
|
+
} else {
|
|
14891
|
+
for (const owner of owners) {
|
|
14892
|
+
ownerSet.add(owner);
|
|
14893
|
+
}
|
|
14876
14894
|
}
|
|
14877
14895
|
}
|
|
14878
14896
|
let codeowners2 = Array.from(ownerSet);
|
|
14897
|
+
if (filesWithoutOwners.length > 0 && options.defaultOwner) {
|
|
14898
|
+
log.info(`Found ${filesWithoutOwners.length} files without owners. Adding default owner: ${options.defaultOwner}`);
|
|
14899
|
+
codeowners2.push(options.defaultOwner);
|
|
14900
|
+
}
|
|
14879
14901
|
if (codeowners2.length === 0) {
|
|
14880
14902
|
log.warn("No codeowners found for the changed files");
|
|
14881
|
-
|
|
14882
|
-
|
|
14883
|
-
codeowners2.push(options.defaultOwner);
|
|
14884
|
-
} else {
|
|
14885
|
-
log.info("Continuing without creating any branches (use --default-owner to specify a fallback)");
|
|
14886
|
-
return;
|
|
14887
|
-
}
|
|
14903
|
+
log.info("Continuing without creating any branches (use --default-owner to specify a fallback)");
|
|
14904
|
+
return;
|
|
14888
14905
|
} else {
|
|
14889
14906
|
log.info(`Found ${codeowners2.length} codeowners: ${codeowners2.join(", ")}`);
|
|
14890
14907
|
}
|
|
@@ -14914,7 +14931,7 @@ var multiBranch = async (options) => {
|
|
|
14914
14931
|
const sanitizedOwner = owner.replace(/[^a-zA-Z0-9-_@]/g, "-").replace(/^@/, "");
|
|
14915
14932
|
const branchName = `${options.branch}/${sanitizedOwner}`;
|
|
14916
14933
|
const commitMessage = `${options.message} - ${owner}`;
|
|
14917
|
-
log.info(`Creating branch for ${owner}...`);
|
|
14934
|
+
log.info(options.append ? `Updating branch for ${owner}...` : `Creating branch for ${owner}...`);
|
|
14918
14935
|
await branch({
|
|
14919
14936
|
owner,
|
|
14920
14937
|
branch: branchName,
|
|
@@ -14924,16 +14941,18 @@ var multiBranch = async (options) => {
|
|
|
14924
14941
|
remote: options.remote,
|
|
14925
14942
|
upstream: options.upstream,
|
|
14926
14943
|
force: options.force,
|
|
14927
|
-
keepBranchOnFailure: options.keepBranchOnFailure
|
|
14944
|
+
keepBranchOnFailure: options.keepBranchOnFailure,
|
|
14945
|
+
isDefaultOwner: owner === options.defaultOwner,
|
|
14946
|
+
append: options.append
|
|
14928
14947
|
});
|
|
14929
14948
|
results.success.push(owner);
|
|
14930
14949
|
} catch (error) {
|
|
14931
|
-
log.error(`Failed to create branch for ${owner}: ${error}`);
|
|
14950
|
+
log.error(`Failed to ${options.append ? "update" : "create"} branch for ${owner}: ${error}`);
|
|
14932
14951
|
results.failure.push(owner);
|
|
14933
14952
|
}
|
|
14934
14953
|
}
|
|
14935
|
-
log.header("Multi-branch creation summary");
|
|
14936
|
-
log.info(`Successfully created branches for ${results.success.length} of ${codeowners2.length} codeowners`);
|
|
14954
|
+
log.header(options.append ? "Multi-branch update summary" : "Multi-branch creation summary");
|
|
14955
|
+
log.info(options.append ? `Successfully updated branches for ${results.success.length} of ${codeowners2.length} codeowners` : `Successfully created branches for ${results.success.length} of ${codeowners2.length} codeowners`);
|
|
14937
14956
|
if (results.success.length) {
|
|
14938
14957
|
log.success(`Successful: ${results.success.join(", ")}`);
|
|
14939
14958
|
}
|
|
@@ -14946,7 +14965,7 @@ var multiBranch = async (options) => {
|
|
|
14946
14965
|
}
|
|
14947
14966
|
};
|
|
14948
14967
|
// package.json
|
|
14949
|
-
var version = "1.
|
|
14968
|
+
var version = "1.5.0";
|
|
14950
14969
|
|
|
14951
14970
|
// src/commands/version.ts
|
|
14952
14971
|
function getVersion() {
|
|
@@ -14957,6 +14976,6 @@ function getVersion() {
|
|
|
14957
14976
|
var program2 = new Command;
|
|
14958
14977
|
program2.name("codeowners").description("CLI tool for grouping and managing staged files by CODEOWNERS").version(getVersion());
|
|
14959
14978
|
program2.command("list").description("Lists all git changed files by CODEOWNER").option("-o, --owner <owner>", "Filter by specific code owner").option("-i, --include <patterns>", "Filter by owner patterns").action(listCodeowners);
|
|
14960
|
-
program2.command("branch").description("Create new branch with codeowner changes").requiredOption("-o, --owner <owner>", "Code owner name").requiredOption("-b, --branch <branch>", "Branch name").requiredOption("-m, --message <message>", "Commit message").option("-n, --no-verify", "Skip lint-staged or any other ci checks").option("-p, --push", "Push branch to remote after commit").option("-r, --remote <remote>", "Remote name to push to", "origin").option("-u, --upstream <upstream>", "Upstream branch name (defaults to local branch name)").option("-f, --force", "Force push to remote").option("-k, --keep-branch-on-failure", "Keep the created branch even if operation fails").action(branch);
|
|
14961
|
-
program2.command("multi-branch").description("Create branches for all codeowners").requiredOption("-b, --branch <branch>", "Base branch name (will be suffixed with codeowner name)").requiredOption("-m, --message <message>", "Base commit message (will be suffixed with codeowner name)").option("-n, --no-verify", "Skip lint-staged or any other ci checks").option("-p, --push", "Push branches to remote after commit").option("-r, --remote <remote>", "Remote name to push to", "origin").option("-u, --upstream <upstream>", "Upstream branch name pattern (defaults to local branch name)").option("-f, --force", "Force push to remote").option("-k, --keep-branch-on-failure", "Keep created branches even if operation fails").option("-d, --default-owner <defaultOwner>", "Default owner to use when no codeowners are found for changed files").option("--ignore <patterns>", "Comma-separated patterns to exclude codeowners (e.g., 'team-a,team-b')").option("--include <patterns>", "Comma-separated patterns to include codeowners (e.g., 'team-*,@org/*')").action(multiBranch);
|
|
14979
|
+
program2.command("branch").description("Create new branch with codeowner changes").requiredOption("-o, --owner <owner>", "Code owner name").requiredOption("-b, --branch <branch>", "Branch name").requiredOption("-m, --message <message>", "Commit message").option("-n, --no-verify", "Skip lint-staged or any other ci checks").option("-p, --push", "Push branch to remote after commit").option("-r, --remote <remote>", "Remote name to push to", "origin").option("-u, --upstream <upstream>", "Upstream branch name (defaults to local branch name)").option("-f, --force", "Force push to remote").option("-k, --keep-branch-on-failure", "Keep the created branch even if operation fails").option("--append", "Add commits to existing branch instead of creating a new one").action(branch);
|
|
14980
|
+
program2.command("multi-branch").description("Create branches for all codeowners").requiredOption("-b, --branch <branch>", "Base branch name (will be suffixed with codeowner name)").requiredOption("-m, --message <message>", "Base commit message (will be suffixed with codeowner name)").option("-n, --no-verify", "Skip lint-staged or any other ci checks").option("-p, --push", "Push branches to remote after commit").option("-r, --remote <remote>", "Remote name to push to", "origin").option("-u, --upstream <upstream>", "Upstream branch name pattern (defaults to local branch name)").option("-f, --force", "Force push to remote").option("-k, --keep-branch-on-failure", "Keep created branches even if operation fails").option("-d, --default-owner <defaultOwner>", "Default owner to use when no codeowners are found for changed files").option("--ignore <patterns>", "Comma-separated patterns to exclude codeowners (e.g., 'team-a,team-b')").option("--include <patterns>", "Comma-separated patterns to include codeowners (e.g., 'team-*,@org/*')").option("--append", "Add commits to existing branches instead of creating new ones").action(multiBranch);
|
|
14962
14981
|
program2.parse(process.argv);
|