From 4e5bcf2cd97d622b2f685403728d11eedc10c4ef Mon Sep 17 00:00:00 2001 From: Adam Kunicki Date: Sun, 11 Jul 2021 20:34:26 -0700 Subject: [PATCH] Make target branch configurable This makes the target branch for review requests configurable and removes the last references to 'master' to remove non-inclusive terminology. --- README.md | 4 ++++ cmd/taste.go | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6aad3bb..051443e 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ jira: username: alice gerrit: url: https://gerrit.googlesource.com +# optional section, you can specify persistent defaults for some flags +defaults: + # beer will use 'trunk' for creating reviews instead of the default of 'main' + branch: trunk ``` ## Usage diff --git a/cmd/taste.go b/cmd/taste.go index 0e936ab..f363067 100644 --- a/cmd/taste.go +++ b/cmd/taste.go @@ -17,13 +17,14 @@ package cmd import ( "fmt" + "github.com/spf13/viper" "os" "strings" - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" ) var tasteCmd = &cobra.Command{ @@ -42,11 +43,16 @@ func init() { tasteCmd.Flags().BoolVar(&wip, "wip", false, "Setting this flag will post a WIP review") tasteCmd.Flags().StringSliceVarP(&reviewers, "reviewers", "r", nil, "Comma separated list of email ids of reviewers to add") + tasteCmd.Flags().String("branch", "main", "Target branch for review") + + _ = viper.BindPFlag("defaults.branch", tasteCmd.Flags().Lookup("branch")) } func taste(cmd *cobra.Command, args []string) { dryRun, _ := cmd.Flags().GetBool("dry-run") isWIP, _ := cmd.Flags().GetBool("wip") + targetBranch := viper.GetString("defaults.branch") + log.WithField("targetBranch", targetBranch).Debug("Determined target branch for comparison") reviewers, _ := cmd.Flags().GetStringArray("reviewers") if dryRun { @@ -65,9 +71,9 @@ func taste(cmd *cobra.Command, args []string) { var ref string if isWIP { - ref = "master%wip" + ref = fmt.Sprintf("%s%%wip", targetBranch) } else { - ref = "master" + ref = targetBranch } refspec := fmt.Sprintf("HEAD:refs/for/%s", ref)