Skip to content

Commit cdacfec

Browse files
authored
Merge pull request #4 from github/better-dependabot-support
better general usage and dependabot support
2 parents 3333b4a + e4b7653 commit cdacfec

File tree

3 files changed

+77
-22
lines changed

3 files changed

+77
-22
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ Basic usage of the `combine` command to combine multiple dependent pull requests
3939
gh combine owner/repo
4040
```
4141

42-
> 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.
42+
> 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.
43+
44+
### Basic with Dependabot
45+
46+
Combine all open pull requests in a repository that are created by dependabot:
47+
48+
```bash
49+
gh combine owner/repo --dependabot
50+
```
4351

4452
### With Passing CI
4553

@@ -101,6 +109,39 @@ You can also require a set of multiple labels
101109
gh combine owner/repo --labels security,dependencies
102110
```
103111

112+
### Only Combine Pull Requests that match a given Regex
113+
114+
```bash
115+
gh combine owner/repo --branch-regex "dependabot/.*"
116+
```
117+
118+
### Only Combine Pull Requests that match a branch prefix
119+
120+
```bash
121+
gh combine owner/repo --branch-prefix "dependabot/"
122+
```
123+
124+
### Only Combine Pull Requests that match a branch suffix
125+
126+
```bash
127+
gh combine owner/repo --branch-suffix "-some-cool-feature"
128+
```
129+
130+
### Ignore Pull Requests that have a certain Label
131+
132+
```bash
133+
gh combine owner/repo --ignore-label wip
134+
135+
# or use the --ignore-labels flag if you want to ignore multiple labels
136+
gh combine owner/repo --ignore-labels wip,dependencies
137+
```
138+
139+
### Update the Resulting Combined Pull Request Branch if Possible
140+
141+
```bash
142+
gh combine owner/repo --update-branch
143+
```
144+
104145
### Running with Debug Logging
105146

106147
```bash

internal/cmd/inputs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func ValidateInputs(args []string) error {
5050
if branchPrefix == "" && branchSuffix == "" && branchRegex == "" &&
5151
ignoreLabel == "" && len(ignoreLabels) == 0 && selectLabel == "" && len(selectLabels) == 0 &&
5252
!requireCI && !mustBeApproved {
53-
Logger.Warn("No filtering options specified. This will attempt to combine ALL open pull requests.")
53+
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.")
5454
}
5555

5656
return nil

internal/cmd/root.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
baseBranch string
3434
combineBranchName string
3535
workingBranchSuffix string
36+
dependabot bool
3637
)
3738

3839
// NewRootCmd creates the root command for the gh-combine CLI
@@ -42,8 +43,16 @@ func NewRootCmd() *cobra.Command {
4243
Short: "Combine multiple pull requests into a single PR",
4344
Long: `Combine multiple pull requests that match specific criteria into a single PR.
4445
Examples:
45-
# Basic usage with a single repository (will default to "--branch-prefix dependabot/" and "--minimum 2")
46-
gh combine octocat/hello-world
46+
# Note: You should use some form of filtering to avoid combining all open PRs in a repository.
47+
# For example, you can filter by branch name, labels, or other criteria.
48+
# Forms of filtering include:
49+
# --label, --labels, --ignore-label, --ignore-labels, --branch-prefix, --branch-suffix, --branch-regex, --dependabot, etc.
50+
51+
# Basic usage with a single repository to combine all pull requests into one
52+
gh combine owner/repo
53+
54+
# Basic usage to only combine pull requests from dependabot
55+
gh combine owner/repo --dependabot
4756
4857
# Multiple repositories (comma-separated)
4958
gh combine octocat/repo1,octocat/repo2
@@ -61,38 +70,38 @@ func NewRootCmd() *cobra.Command {
6170
gh combine --file repos.txt
6271
6372
# Filter PRs by branch name
64-
gh combine octocat/hello-world --branch-prefix dependabot/ # Only include PRs with the standard dependabot branch prefix
65-
gh combine octocat/hello-world --branch-suffix -update
66-
gh combine octocat/hello-world --branch-regex "dependabot/.*"
73+
gh combine owner/repo --branch-prefix dependabot/ # Only include PRs with the standard dependabot branch prefix
74+
gh combine owner/repo --branch-suffix -update
75+
gh combine owner/repo --branch-regex "dependabot/.*"
6776
6877
# Filter PRs by labels
69-
gh combine octocat/hello-world --label dependencies # PRs must have this single label
70-
gh combine octocat/hello-world --labels security,dependencies # PRs must have ALL these labels
78+
gh combine owner/repo --label dependencies # PRs must have this single label
79+
gh combine owner/repo --labels security,dependencies # PRs must have ALL these labels
7180
7281
# Exclude PRs by labels
73-
gh combine octocat/hello-world --ignore-label wip # Ignore PRs with this label
74-
gh combine octocat/hello-world --ignore-labels wip,draft # Ignore PRs with ANY of these labels
82+
gh combine owner/repo --ignore-label wip # Ignore PRs with this label
83+
gh combine owner/repo --ignore-labels wip,draft # Ignore PRs with ANY of these labels
7584
7685
# Set requirements for PRs to be combined
77-
gh combine octocat/hello-world --require-ci # Only include PRs with passing CI
78-
gh combine octocat/hello-world --require-approved # Only include approved PRs
79-
gh combine octocat/hello-world --minimum 3 # Need at least 3 matching PRs
86+
gh combine owner/repo --require-ci # Only include PRs with passing CI
87+
gh combine owner/repo --require-approved # Only include approved PRs
88+
gh combine owner/repo --minimum 3 # Need at least 3 matching PRs
8089
8190
# Add metadata to combined PR
82-
gh combine octocat/hello-world --add-labels security,dependencies # Add these labels to the new PR
83-
gh combine octocat/hello-world --add-assignees octocat,hubot # Assign users to the new PR
91+
gh combine owner/repo --add-labels security,dependencies # Add these labels to the new PR
92+
gh combine owner/repo --add-assignees octocat,hubot # Assign users to the new PR
8493
8594
# Additional options
86-
gh combine octocat/hello-world --autoclose # Close source PRs when combined PR is merged
87-
gh combine octocat/hello-world --base-branch main # Use a different base branch for the combined PR
88-
gh combine octocat/hello-world --combine-branch-name combined-prs # Use a different name for the combined PR branch
89-
gh combine octocat/hello-world --working-branch-suffix -working # Use a different suffix for the working branch
90-
gh combine octocat/hello-world --update-branch # Update the branch of the combined PR`,
95+
gh combine owner/repo --autoclose # Close source PRs when combined PR is merged
96+
gh combine owner/repo --base-branch main # Use a different base branch for the combined PR
97+
gh combine owner/repo --combine-branch-name combined-prs # Use a different name for the combined PR branch
98+
gh combine owner/repo --working-branch-suffix -working # Use a different suffix for the working branch
99+
gh combine owner/repo --update-branch # Update the branch of the combined PR`,
91100
RunE: runCombine,
92101
}
93102

94103
// Add flags
95-
rootCmd.Flags().StringVar(&branchPrefix, "branch-prefix", "dependabot/", "Branch prefix to filter PRs")
104+
rootCmd.Flags().StringVar(&branchPrefix, "branch-prefix", "", "Branch prefix to filter PRs")
96105
rootCmd.Flags().StringVar(&branchSuffix, "branch-suffix", "", "Branch suffix to filter PRs")
97106
rootCmd.Flags().StringVar(&branchRegex, "branch-regex", "", "Regex pattern to filter PRs by branch name")
98107

@@ -110,6 +119,7 @@ func NewRootCmd() *cobra.Command {
110119
// Other flags
111120
rootCmd.Flags().StringSliceVar(&addAssignees, "add-assignees", nil, "Comma-separated list of users to assign to the combined PR")
112121
rootCmd.Flags().BoolVar(&requireCI, "require-ci", false, "Only include PRs with passing CI checks")
122+
rootCmd.Flags().BoolVar(&dependabot, "dependabot", false, "Only include PRs with the dependabot branch prefix")
113123
rootCmd.Flags().BoolVar(&mustBeApproved, "require-approved", false, "Only include PRs that have been approved")
114124
rootCmd.Flags().BoolVar(&autoclose, "autoclose", false, "Close source PRs when combined PR is merged")
115125
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 {
142152

143153
Logger.Debug("starting gh-combine", "version", version.String())
144154

155+
// if the dependabot flag is set and branchPrefix is not already set, set the branch prefix to "dependabot/"
156+
if dependabot && branchPrefix == "" {
157+
}
158+
145159
// Input validation
146160
if err := ValidateInputs(args); err != nil {
147161
return err

0 commit comments

Comments
 (0)