diff --git a/cmd/governctl/pr/merge.go b/cmd/governctl/pr/merge.go index e8c4721..7f35342 100644 --- a/cmd/governctl/pr/merge.go +++ b/cmd/governctl/pr/merge.go @@ -6,6 +6,7 @@ package pr import ( + "bufio" "bytes" "context" "fmt" @@ -288,14 +289,24 @@ func (opts *Merge) Run(ctx context.Context, args []string) error { var output []byte cmd = exec.Command("gh", "auth", "token") cmd.Stderr = log.G(ctx).WriterLevel(logrus.ErrorLevel) + stderr, _ := cmd.StderrPipe() + scanner := bufio.NewScanner(stderr) if output, err = cmd.Output(); err != nil { - return fmt.Errorf("could not backup token: %w", err) + if scanner.Scan() { + if strings.HasPrefix(scanner.Text(), "no oauth token found") { + log.G(ctx).Warn("no token to back up, skipping") + token = "" + } else { + return fmt.Errorf("could not backup token: %w", err) + } + } else { + return fmt.Errorf("could not read error to backup token: %w", err) + } + } else { + token = string(output) } - token = string(output) - if strings.HasPrefix(token, "no oauth token found") { - token = "" - } else if !strings.HasPrefix(token, "gh") { + if token != "" && !strings.HasPrefix(token, "gh") { return fmt.Errorf("could not backup token, invalid format (try running `gh auth token` manually): %w", err) }