Skip to content

Commit

Permalink
sync: add verbose logging messages (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
craftamap committed Aug 29, 2021
1 parent d4df8f7 commit c4ae503
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions cmd/commands/pr/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/cli/cli/git"
"github.com/cli/cli/utils"
Expand All @@ -23,7 +24,7 @@ var (

const (
MethodOptionMerge = "merge"
MethodOptionRebase = "Rebase"
MethodOptionRebase = "rebase"
)

func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) {
Expand All @@ -39,14 +40,18 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) {
// In order to check if the method exists in the config, we need to check here
syncMethodIsSet := viper.IsSet("sync-method")
if !syncMethodIsSet {
logging.Note("You can configure your preferred way of syncing by running TODO")
logging.Note(
"You can configure your preferred way of syncing by adding the following line to your configuration: ",
aurora.BgBrightBlack(aurora.White(" sync-method = merge ")).String(),
" or ",
aurora.BgBrightBlack(aurora.White(" sync-method = rebase ")).String(),
)
}
if !cmd.Flags().Lookup("method").Changed {
if syncMethodIsSet && !cmd.Flags().Lookup("method").Changed {
Method = viper.GetString("sync-method")
}

if Method != MethodOptionRebase && Method != MethodOptionMerge {
logging.Error("\"%s\" is not a valid method (select one of these: %s, %s)", Method, MethodOptionRebase, MethodOptionMerge)
return fmt.Errorf("\"%s\" is not a valid method (select one of these: %s, %s)", Method, MethodOptionRebase, MethodOptionMerge)
}
return nil
Expand All @@ -70,7 +75,7 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) {
return
}
if len(prs.Values) == 0 {
logging.Warning("Nothing on this branch")
logging.Error("No pull request on this branch")
return
}
id = prs.Values[0].ID
Expand All @@ -81,7 +86,7 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) {
return
}
if ucc, err := git.UncommittedChangeCount(); err == nil && ucc > 0 {
logging.Warning(utils.Pluralize(ucc, "uncommitted change; This might lead to issues"))
logging.Warning(utils.Pluralize(ucc, "uncommitted change"), "; This might lead to issues")
}

remoteDestinationBranch := fmt.Sprintf("origin/%s", pr.Destination.Branch.Name)
Expand All @@ -94,6 +99,17 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) {
cmdQueue = append(cmdQueue, []string{"git", "merge", "--commit", remoteDestinationBranch})
}

var builder strings.Builder
for _, cmd := range cmdQueue {
builder.WriteString(" ")
for _, cmdPart := range cmd {
builder.WriteString(cmdPart)
builder.WriteString(" ")
}
builder.WriteString("\n")
}
logging.Note(fmt.Sprintf("Syncing by running the following commands: \n%v", builder.String()))

err = processCmdQueue(cmdQueue)
if err != nil {
logging.Error(err)
Expand Down

0 comments on commit c4ae503

Please sign in to comment.