From c7e05e27a5183e2af1de081dbe0a89298841d38c Mon Sep 17 00:00:00 2001 From: "Simen A. W. Olsen" Date: Sat, 7 Aug 2021 15:29:11 +0200 Subject: [PATCH 1/3] feat: Add merge-method option --- cmd/merge.go | 2 ++ cmd/root.go | 1 + merge/merge.go | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/merge.go b/cmd/merge.go index fdf8a14..d1199c4 100644 --- a/cmd/merge.go +++ b/cmd/merge.go @@ -19,6 +19,7 @@ import ( var mergeFlagThrottle string var mergeFlagIgnoreReviewApproval bool var mergeFlagIgnoreBuildStatus bool +var mergeMethod string // rate limits the # of PR merges. used to prevent load on CI system var mergeThrottle *time.Ticker @@ -92,6 +93,7 @@ func mergeOneRepo(r lib.Repo, ctx context.Context) error { CommitSHA: pushOutput.CommitSHA, RequireReviewApproval: !mergeFlagIgnoreReviewApproval, RequireBuildSuccess: !mergeFlagIgnoreBuildStatus, + MergeMethod: mergeMethod, } var output merge.Output if r.IsGitlab() { diff --git a/cmd/root.go b/cmd/root.go index e7d2786..d0aa497 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -34,6 +34,7 @@ func init() { mergeCmd.Flags().StringVarP(&mergeFlagThrottle, "throttle", "t", "30s", "Throttle number of merges, e.g. '30s' means 1 merge per 30 seconds") mergeCmd.Flags().BoolVar(&mergeFlagIgnoreReviewApproval, "ignore-review-approval", false, "Ignore whether or not the review has been approved") mergeCmd.Flags().BoolVar(&mergeFlagIgnoreBuildStatus, "ignore-build-status", false, "Ignore whether or not builds are passing") + mergeCmd.Flags().StringVarP(&mergeMethod, "merge-method", "m", "merge", "Merge method to use. Possible values include: merge, squash, and rebase") rootCmd.AddCommand(planCmd) planCmd.Flags().StringVarP(&planFlagBranch, "branch", "b", "", "Git branch to commit to") diff --git a/merge/merge.go b/merge/merge.go index 5780e74..36668d6 100644 --- a/merge/merge.go +++ b/merge/merge.go @@ -23,6 +23,8 @@ type Input struct { RequireReviewApproval bool // RequireBuildSuccess specifies if the PR must have a successful build before merging RequireBuildSuccess bool + // Merge method to use. Possible values include: "merge", "squash", and "rebase" + MergeMethod string } // Output from Push() @@ -95,7 +97,9 @@ func GitHubMerge(ctx context.Context, input Input, repoLimiter *time.Ticker, mer } // Merge the PR - options := &github.PullRequestOptions{} + options := &github.PullRequestOptions{ + MergeMethod: input.MergeMethod, + } commitMsg := "" <-mergeLimiter.C <-repoLimiter.C From ea927074e5f7018ac28f6fa8dbf81c1305a98c48 Mon Sep 17 00:00:00 2001 From: "Simen A. W. Olsen" Date: Sat, 7 Aug 2021 15:32:26 +0200 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e648830..98d0141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # changelog +HEAD + +- Add option to set merge method (merge, squash or rebase). (Example: `mp merge --merge-method squash`) + +--- + 2021-05-22 - v0.0.32 - Adds - `--diff` flag added to `mp plan` to show the diff of the changes made in each repo From 2c7c847df50060f83de59b909932bee7ea032292 Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 11 Aug 2021 21:01:02 -0700 Subject: [PATCH 3/3] cmd/merge: add validation to --merge-method --- cmd/merge.go | 23 +++++++++++++++++++++++ cmd/root.go | 4 ---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd/merge.go b/cmd/merge.go index d1199c4..bef04da 100644 --- a/cmd/merge.go +++ b/cmd/merge.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "fmt" "log" "os" "path/filepath" @@ -24,6 +25,8 @@ var mergeMethod string // rate limits the # of PR merges. used to prevent load on CI system var mergeThrottle *time.Ticker +var supportedMergeMethods = []string{"merge", "squash", "rebase"} + var mergeCmd = &cobra.Command{ Use: "merge", Short: "Merge pushed changes", @@ -47,6 +50,10 @@ var mergeCmd = &cobra.Command{ mergeThrottle = time.NewTicker(dur) } + if !contains(supportedMergeMethods, mergeMethod) { + log.Fatalf("Invalid --merge-method: %s", mergeMethod) + } + err = parallelize(repos, mergeOneRepo) if err != nil { log.Fatal(err) @@ -115,3 +122,19 @@ func mergeOneRepo(r lib.Repo, ctx context.Context) error { writeJSON(output, mergeOutputPath) return nil } + +func init() { + mergeCmd.Flags().StringVarP(&mergeFlagThrottle, "throttle", "t", "30s", "Throttle number of merges, e.g. '30s' means 1 merge per 30 seconds") + mergeCmd.Flags().BoolVar(&mergeFlagIgnoreReviewApproval, "ignore-review-approval", false, "Ignore whether or not the review has been approved") + mergeCmd.Flags().BoolVar(&mergeFlagIgnoreBuildStatus, "ignore-build-status", false, "Ignore whether or not builds are passing") + mergeCmd.Flags().StringVarP(&mergeMethod, "merge-method", "m", "merge", fmt.Sprintf("Merge method to use. Possible values include: %s", strings.Join(supportedMergeMethods, ", "))) +} + +func contains(list []string, item string) bool { + for _, each := range list { + if each == item { + return true + } + } + return false +} diff --git a/cmd/root.go b/cmd/root.go index d0aa497..560e43d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,10 +31,6 @@ func init() { rootCmd.AddCommand(docsCmd) rootCmd.AddCommand(mergeCmd) - mergeCmd.Flags().StringVarP(&mergeFlagThrottle, "throttle", "t", "30s", "Throttle number of merges, e.g. '30s' means 1 merge per 30 seconds") - mergeCmd.Flags().BoolVar(&mergeFlagIgnoreReviewApproval, "ignore-review-approval", false, "Ignore whether or not the review has been approved") - mergeCmd.Flags().BoolVar(&mergeFlagIgnoreBuildStatus, "ignore-build-status", false, "Ignore whether or not builds are passing") - mergeCmd.Flags().StringVarP(&mergeMethod, "merge-method", "m", "merge", "Merge method to use. Possible values include: merge, squash, and rebase") rootCmd.AddCommand(planCmd) planCmd.Flags().StringVarP(&planFlagBranch, "branch", "b", "", "Git branch to commit to")