Skip to content

Commit

Permalink
Make target branch configurable
Browse files Browse the repository at this point in the history
This makes the target branch for review requests configurable and
removes the last references to 'master' to remove non-inclusive
terminology.
  • Loading branch information
kunickiaj committed Jul 12, 2021
1 parent b8b1fed commit 4e5bcf2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions cmd/taste.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 4e5bcf2

Please sign in to comment.