Skip to content

Commit 309d97d

Browse files
committed
add a new --owners flag to assume the default owners of a given repo via the cli
1 parent 30392cc commit 309d97d

File tree

2 files changed

+61
-41
lines changed

2 files changed

+61
-41
lines changed

internal/cmd/repos.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"strings"
77
)
88

9-
// ParseRepositories parses repository names from arguments or file
10-
func ParseRepositories(args []string, reposFile string) ([]string, error) {
9+
// ParseRepositories parses repository names from arguments or file with support for default owner
10+
func ParseRepositories(args []string, reposFile string, defaultOwner string) ([]string, error) {
1111
var repos []string
1212

1313
// Parse from command line arguments
@@ -18,11 +18,11 @@ func ParseRepositories(args []string, reposFile string) ([]string, error) {
1818
splitRepos := strings.Split(arg, ",")
1919
for _, repo := range splitRepos {
2020
if trimmedRepo := strings.TrimSpace(repo); trimmedRepo != "" {
21-
repos = append(repos, trimmedRepo)
21+
repos = append(repos, applyDefaultOwner(trimmedRepo, defaultOwner))
2222
}
2323
}
2424
} else {
25-
repos = append(repos, arg)
25+
repos = append(repos, applyDefaultOwner(arg, defaultOwner))
2626
}
2727
}
2828
}
@@ -37,10 +37,18 @@ func ParseRepositories(args []string, reposFile string) ([]string, error) {
3737
lines := strings.Split(string(fileContent), "\n")
3838
for _, line := range lines {
3939
if trimmedLine := strings.TrimSpace(line); trimmedLine != "" && !strings.HasPrefix(trimmedLine, "#") {
40-
repos = append(repos, trimmedLine)
40+
repos = append(repos, applyDefaultOwner(trimmedLine, defaultOwner))
4141
}
4242
}
4343
}
4444

4545
return repos, nil
4646
}
47+
48+
// applyDefaultOwner adds the default owner to a repo name if it doesn't already have an owner
49+
func applyDefaultOwner(repo string, defaultOwner string) string {
50+
if defaultOwner == "" || strings.Contains(repo, "/") {
51+
return repo
52+
}
53+
return defaultOwner + "/" + repo
54+
}

internal/cmd/root.go

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/cli/go-gh/v2/pkg/api"
10+
1011
"github.com/spf13/cobra"
1112

1213
"github.com/github/gh-combine/internal/version"
@@ -28,6 +29,7 @@ var (
2829
ignoreLabels []string
2930
reposFile string
3031
minimum int
32+
defaultOwner string
3133
)
3234

3335
// NewRootCmd creates the root command for the gh-combine CLI
@@ -36,41 +38,50 @@ func NewRootCmd() *cobra.Command {
3638
Use: "combine [repo1,repo2,...]",
3739
Short: "Combine multiple pull requests into a single PR",
3840
Long: `Combine multiple pull requests that match specific criteria into a single PR.
39-
Examples:
40-
# Basic usage with a single repository
41-
gh combine octocat/hello-world
42-
43-
# Multiple repositories (comma-separated)
44-
gh combine octocat/repo1,octocat/repo2
45-
46-
# Using a file with repository names (one per line)
47-
gh combine --file repos.txt
48-
49-
# Filter PRs by branch name
50-
gh combine octocat/hello-world --branch-prefix dependabot-
51-
gh combine octocat/hello-world --branch-suffix -update
52-
gh combine octocat/hello-world --branch-regex "dependabot/.*"
53-
54-
# Filter PRs by labels
55-
gh combine octocat/hello-world --label dependencies # PRs must have this single label
56-
gh combine octocat/hello-world --labels security,dependencies # PRs must have ALL these labels
57-
58-
# Exclude PRs by labels
59-
gh combine octocat/hello-world --ignore-label wip # Ignore PRs with this label
60-
gh combine octocat/hello-world --ignore-labels wip,draft # Ignore PRs with ANY of these labels
61-
62-
# Set requirements for PRs to be combined
63-
gh combine octocat/hello-world --require-ci # Only include PRs with passing CI
64-
gh combine octocat/hello-world --require-approved # Only include approved PRs
65-
gh combine octocat/hello-world --minimum 3 # Need at least 3 matching PRs
66-
67-
# Add metadata to combined PR
68-
gh combine octocat/hello-world --add-labels security,dependencies # Add these labels to the new PR
69-
gh combine octocat/hello-world --assignees octocat,hubot # Assign users to the new PR
70-
71-
# Additional options
72-
gh combine octocat/hello-world --autoclose # Close source PRs when combined PR is merged
73-
gh combine octocat/hello-world --update-branch # Update the branch of the combined PR`,
41+
Examples:
42+
# Basic usage with a single repository
43+
gh combine octocat/hello-world
44+
45+
# Multiple repositories (comma-separated)
46+
gh combine octocat/repo1,octocat/repo2
47+
48+
# Multiple repositories (no commas)
49+
gh combine octocat/repo1 octocat/repo2
50+
51+
# Using default owner for repositories
52+
gh combine --owner octocat repo1 repo2
53+
54+
# Using default owner for only some repositories
55+
gh combine --owner octocat repo1 octocat/repo2
56+
57+
# Using a file with repository names (one per line: owner/repo format)
58+
gh combine --file repos.txt
59+
60+
# Filter PRs by branch name
61+
gh combine octocat/hello-world --branch-prefix dependabot/
62+
gh combine octocat/hello-world --branch-suffix -update
63+
gh combine octocat/hello-world --branch-regex "dependabot/.*"
64+
65+
# Filter PRs by labels
66+
gh combine octocat/hello-world --label dependencies # PRs must have this single label
67+
gh combine octocat/hello-world --labels security,dependencies # PRs must have ALL these labels
68+
69+
# Exclude PRs by labels
70+
gh combine octocat/hello-world --ignore-label wip # Ignore PRs with this label
71+
gh combine octocat/hello-world --ignore-labels wip,draft # Ignore PRs with ANY of these labels
72+
73+
# Set requirements for PRs to be combined
74+
gh combine octocat/hello-world --require-ci # Only include PRs with passing CI
75+
gh combine octocat/hello-world --require-approved # Only include approved PRs
76+
gh combine octocat/hello-world --minimum 3 # Need at least 3 matching PRs
77+
78+
# Add metadata to combined PR
79+
gh combine octocat/hello-world --add-labels security,dependencies # Add these labels to the new PR
80+
gh combine octocat/hello-world --assignees octocat,hubot # Assign users to the new PR
81+
82+
# Additional options
83+
gh combine octocat/hello-world --autoclose # Close source PRs when combined PR is merged
84+
gh combine octocat/hello-world --update-branch # Update the branch of the combined PR`,
7485
RunE: runCombine,
7586
}
7687

@@ -98,6 +109,7 @@ func NewRootCmd() *cobra.Command {
98109
rootCmd.Flags().BoolVar(&updateBranch, "update-branch", false, "Update the branch of the combined PR if possible")
99110
rootCmd.Flags().StringVar(&reposFile, "file", "", "File containing repository names, one per line")
100111
rootCmd.Flags().IntVar(&minimum, "minimum", 2, "Minimum number of PRs to combine")
112+
rootCmd.Flags().StringVar(&defaultOwner, "owner", "", "Default owner for repositories (if not specified in repo name or missing from file inputs)")
101113

102114
// Add deprecated flags for backward compatibility
103115
// rootCmd.Flags().IntVar(&minimum, "min-combine", 2, "Minimum number of PRs to combine (deprecated, use --minimum)")
@@ -130,7 +142,7 @@ func runCombine(cmd *cobra.Command, args []string) error {
130142
defer spinner.Stop()
131143

132144
// Parse repositories from args or file
133-
repos, err := ParseRepositories(args, reposFile)
145+
repos, err := ParseRepositories(args, reposFile, defaultOwner)
134146
if err != nil {
135147
return fmt.Errorf("failed to parse repositories: %w", err)
136148
}

0 commit comments

Comments
 (0)