Skip to content

feat: display the command used on the generated combined PR #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions internal/cmd/combine_prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type RESTClientInterface interface {
}

// CombinePRsWithStats combines PRs and returns stats for summary output
func CombinePRsWithStats(ctx context.Context, graphQlClient *api.GraphQLClient, restClient RESTClientInterface, repo github.Repo, pulls github.Pulls) (combined []string, mergeConflicts []string, combinedPRLink string, err error) {
func CombinePRsWithStats(ctx context.Context, graphQlClient *api.GraphQLClient, restClient RESTClientInterface, repo github.Repo, pulls github.Pulls, command string) (combined []string, mergeConflicts []string, combinedPRLink string, err error) {
workingBranchName := combineBranchName + workingBranchSuffix

repoDefaultBranch, err := getDefaultBranch(ctx, restClient, repo)
Expand Down Expand Up @@ -82,7 +82,7 @@ func CombinePRsWithStats(ctx context.Context, graphQlClient *api.GraphQLClient,
Logger.Warn("Failed to delete working branch", "branch", workingBranchName, "error", err)
}

prBody := generatePRBody(combined, mergeConflicts)
prBody := generatePRBody(combined, mergeConflicts, command)
prTitle := "Combined PRs"
prNumber, prErr := createPullRequestWithNumber(ctx, restClient, repo, prTitle, combineBranchName, repoDefaultBranch, prBody, addLabels, addAssignees)
if prErr != nil {
Expand Down Expand Up @@ -179,8 +179,8 @@ func getBranchSHA(ctx context.Context, client RESTClientInterface, repo github.R
return ref.Object.SHA, nil
}

// generatePRBody generates the body for the combined PR
func generatePRBody(combinedPRs, mergeFailedPRs []string) string {
// Updated generatePRBody to include the command used
func generatePRBody(combinedPRs, mergeFailedPRs []string, command string) string {
body := "✅ The following pull requests have been successfully combined:\n"
for _, pr := range combinedPRs {
body += "- " + pr + "\n"
Expand All @@ -192,7 +192,8 @@ func generatePRBody(combinedPRs, mergeFailedPRs []string) string {
}
}

body += "\n> Generated with [gh-combine](https://github.com/github/gh-combine)"
body += "\n> Generated with [gh-combine](https://github.com/github/gh-combine)\n"
body += fmt.Sprintf("\nCommand used:\n\n```bash\n%s\n```", command)

return body
}
Expand Down
79 changes: 78 additions & 1 deletion internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"

"github.com/cli/go-gh/v2/pkg/api"
Expand Down Expand Up @@ -350,7 +351,8 @@ func processRepository(ctx context.Context, client *api.RESTClient, graphQlClien
}{client}

// Combine the PRs and collect stats
combined, mergeConflicts, combinedPRLink, err := CombinePRsWithStats(ctx, graphQlClient, restClientWrapper, repo, matchedPRs)
commandString := buildCommandString([]string{repo.String()})
combined, mergeConflicts, combinedPRLink, err := CombinePRsWithStats(ctx, graphQlClient, restClientWrapper, repo, matchedPRs, commandString)
if err != nil {
return fmt.Errorf("failed to combine PRs: %w", err)
}
Expand Down Expand Up @@ -420,3 +422,78 @@ func displayStatsSummary(stats *StatsCollector, outputFormat string) {
displayPlainStats(stats)
}
}

// buildCommandString reconstructs the CLI command with all set flags and arguments
func buildCommandString(args []string) string {
cmd := []string{"gh combine"}
cmd = append(cmd, args...)

if branchPrefix != "" {
cmd = append(cmd, "--branch-prefix", branchPrefix)
}
if branchSuffix != "" {
cmd = append(cmd, "--branch-suffix", branchSuffix)
}
if branchRegex != "" {
cmd = append(cmd, "--branch-regex", branchRegex)
}
if len(selectLabels) > 0 {
cmd = append(cmd, "--labels", strings.Join(selectLabels, ","))
}
if len(ignoreLabels) > 0 {
cmd = append(cmd, "--ignore-labels", strings.Join(ignoreLabels, ","))
}
if len(addLabels) > 0 {
cmd = append(cmd, "--add-labels", strings.Join(addLabels, ","))
}
if len(addAssignees) > 0 {
cmd = append(cmd, "--add-assignees", strings.Join(addAssignees, ","))
}
if requireCI {
cmd = append(cmd, "--require-ci")
}
if dependabot {
cmd = append(cmd, "--dependabot")
}
if mustBeApproved {
cmd = append(cmd, "--require-approved")
}
if autoclose {
cmd = append(cmd, "--autoclose")
}
if updateBranch {
cmd = append(cmd, "--update-branch")
}
if baseBranch != "main" && baseBranch != "" {
cmd = append(cmd, "--base-branch", baseBranch)
}
if combineBranchName != "combined-prs" && combineBranchName != "" {
cmd = append(cmd, "--combine-branch-name", combineBranchName)
}
if workingBranchSuffix != "-working" && workingBranchSuffix != "" {
cmd = append(cmd, "--working-branch-suffix", workingBranchSuffix)
}
if reposFile != "" {
cmd = append(cmd, "--file", reposFile)
}
if minimum != 2 {
cmd = append(cmd, "--minimum", fmt.Sprintf("%d", minimum))
}
if defaultOwner != "" {
cmd = append(cmd, "--owner", defaultOwner)
}
if caseSensitiveLabels {
cmd = append(cmd, "--case-sensitive-labels")
}
if noColor {
cmd = append(cmd, "--no-color")
}
if noStats {
cmd = append(cmd, "--no-stats")
}
if outputFormat != "table" && outputFormat != "" {
cmd = append(cmd, "--output", outputFormat)
}

return strings.Join(cmd, " ")
}
Loading