diff --git a/README.md b/README.md index 93a7802..b5408d6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,15 @@ Basic usage of the `combine` command to combine multiple dependent pull requests gh combine owner/repo ``` -> By default, this command runs with the `--branch-prefix dependabot/` flag set. All branches in the `owner/repo` repository that start with `dependabot/` will be combined. +> By default, this command will attempt to combine all open pull requests in the repository. You should use generally use some form of filtering to limit the number of pull requests that are combined. See the examples below for more information. + +### Basic with Dependabot + +Combine all open pull requests in a repository that are created by dependabot: + +```bash +gh combine owner/repo --dependabot +``` ### With Passing CI @@ -101,6 +109,39 @@ You can also require a set of multiple labels gh combine owner/repo --labels security,dependencies ``` +### Only Combine Pull Requests that match a given Regex + +```bash +gh combine owner/repo --branch-regex "dependabot/.*" +``` + +### Only Combine Pull Requests that match a branch prefix + +```bash +gh combine owner/repo --branch-prefix "dependabot/" +``` + +### Only Combine Pull Requests that match a branch suffix + +```bash +gh combine owner/repo --branch-suffix "-some-cool-feature" +``` + +### Ignore Pull Requests that have a certain Label + +```bash +gh combine owner/repo --ignore-label wip + +# or use the --ignore-labels flag if you want to ignore multiple labels +gh combine owner/repo --ignore-labels wip,dependencies +``` + +### Update the Resulting Combined Pull Request Branch if Possible + +```bash +gh combine owner/repo --update-branch +``` + ### Running with Debug Logging ```bash diff --git a/internal/cmd/inputs.go b/internal/cmd/inputs.go index 05236f3..3f04dd5 100644 --- a/internal/cmd/inputs.go +++ b/internal/cmd/inputs.go @@ -50,7 +50,7 @@ func ValidateInputs(args []string) error { if branchPrefix == "" && branchSuffix == "" && branchRegex == "" && ignoreLabel == "" && len(ignoreLabels) == 0 && selectLabel == "" && len(selectLabels) == 0 && !requireCI && !mustBeApproved { - Logger.Warn("No filtering options specified. This will attempt to combine ALL open pull requests.") + Logger.Warn("No filtering options specified. This will attempt to combine ALL open pull requests. Use --label, --labels, --ignore-label, --ignore-labels, --branch-prefix, --branch-suffix, --branch-regex, --dependabot, etc to filter.") } return nil diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 1fbe244..43ba7ab 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -33,6 +33,7 @@ var ( baseBranch string combineBranchName string workingBranchSuffix string + dependabot bool ) // NewRootCmd creates the root command for the gh-combine CLI @@ -42,8 +43,16 @@ func NewRootCmd() *cobra.Command { Short: "Combine multiple pull requests into a single PR", Long: `Combine multiple pull requests that match specific criteria into a single PR. Examples: - # Basic usage with a single repository (will default to "--branch-prefix dependabot/" and "--minimum 2") - gh combine octocat/hello-world + # Note: You should use some form of filtering to avoid combining all open PRs in a repository. + # For example, you can filter by branch name, labels, or other criteria. + # Forms of filtering include: + # --label, --labels, --ignore-label, --ignore-labels, --branch-prefix, --branch-suffix, --branch-regex, --dependabot, etc. + + # Basic usage with a single repository to combine all pull requests into one + gh combine owner/repo + + # Basic usage to only combine pull requests from dependabot + gh combine owner/repo --dependabot # Multiple repositories (comma-separated) gh combine octocat/repo1,octocat/repo2 @@ -61,38 +70,38 @@ func NewRootCmd() *cobra.Command { gh combine --file repos.txt # Filter PRs by branch name - gh combine octocat/hello-world --branch-prefix dependabot/ # Only include PRs with the standard dependabot branch prefix - gh combine octocat/hello-world --branch-suffix -update - gh combine octocat/hello-world --branch-regex "dependabot/.*" + gh combine owner/repo --branch-prefix dependabot/ # Only include PRs with the standard dependabot branch prefix + gh combine owner/repo --branch-suffix -update + gh combine owner/repo --branch-regex "dependabot/.*" # Filter PRs by labels - gh combine octocat/hello-world --label dependencies # PRs must have this single label - gh combine octocat/hello-world --labels security,dependencies # PRs must have ALL these labels + gh combine owner/repo --label dependencies # PRs must have this single label + gh combine owner/repo --labels security,dependencies # PRs must have ALL these labels # Exclude PRs by labels - gh combine octocat/hello-world --ignore-label wip # Ignore PRs with this label - gh combine octocat/hello-world --ignore-labels wip,draft # Ignore PRs with ANY of these labels + gh combine owner/repo --ignore-label wip # Ignore PRs with this label + gh combine owner/repo --ignore-labels wip,draft # Ignore PRs with ANY of these labels # Set requirements for PRs to be combined - gh combine octocat/hello-world --require-ci # Only include PRs with passing CI - gh combine octocat/hello-world --require-approved # Only include approved PRs - gh combine octocat/hello-world --minimum 3 # Need at least 3 matching PRs + gh combine owner/repo --require-ci # Only include PRs with passing CI + gh combine owner/repo --require-approved # Only include approved PRs + gh combine owner/repo --minimum 3 # Need at least 3 matching PRs # Add metadata to combined PR - gh combine octocat/hello-world --add-labels security,dependencies # Add these labels to the new PR - gh combine octocat/hello-world --add-assignees octocat,hubot # Assign users to the new PR + gh combine owner/repo --add-labels security,dependencies # Add these labels to the new PR + gh combine owner/repo --add-assignees octocat,hubot # Assign users to the new PR # Additional options - gh combine octocat/hello-world --autoclose # Close source PRs when combined PR is merged - gh combine octocat/hello-world --base-branch main # Use a different base branch for the combined PR - gh combine octocat/hello-world --combine-branch-name combined-prs # Use a different name for the combined PR branch - gh combine octocat/hello-world --working-branch-suffix -working # Use a different suffix for the working branch - gh combine octocat/hello-world --update-branch # Update the branch of the combined PR`, + gh combine owner/repo --autoclose # Close source PRs when combined PR is merged + gh combine owner/repo --base-branch main # Use a different base branch for the combined PR + gh combine owner/repo --combine-branch-name combined-prs # Use a different name for the combined PR branch + gh combine owner/repo --working-branch-suffix -working # Use a different suffix for the working branch + gh combine owner/repo --update-branch # Update the branch of the combined PR`, RunE: runCombine, } // Add flags - rootCmd.Flags().StringVar(&branchPrefix, "branch-prefix", "dependabot/", "Branch prefix to filter PRs") + rootCmd.Flags().StringVar(&branchPrefix, "branch-prefix", "", "Branch prefix to filter PRs") rootCmd.Flags().StringVar(&branchSuffix, "branch-suffix", "", "Branch suffix to filter PRs") rootCmd.Flags().StringVar(&branchRegex, "branch-regex", "", "Regex pattern to filter PRs by branch name") @@ -110,6 +119,7 @@ func NewRootCmd() *cobra.Command { // Other flags rootCmd.Flags().StringSliceVar(&addAssignees, "add-assignees", nil, "Comma-separated list of users to assign to the combined PR") rootCmd.Flags().BoolVar(&requireCI, "require-ci", false, "Only include PRs with passing CI checks") + rootCmd.Flags().BoolVar(&dependabot, "dependabot", false, "Only include PRs with the dependabot branch prefix") rootCmd.Flags().BoolVar(&mustBeApproved, "require-approved", false, "Only include PRs that have been approved") rootCmd.Flags().BoolVar(&autoclose, "autoclose", false, "Close source PRs when combined PR is merged") rootCmd.Flags().BoolVar(&updateBranch, "update-branch", false, "Update the branch of the combined PR if possible") @@ -142,6 +152,10 @@ func runCombine(cmd *cobra.Command, args []string) error { Logger.Debug("starting gh-combine", "version", version.String()) + // if the dependabot flag is set and branchPrefix is not already set, set the branch prefix to "dependabot/" + if dependabot && branchPrefix == "" { + } + // Input validation if err := ValidateInputs(args); err != nil { return err