Skip to content

Commit 8a2b0a1

Browse files
author
Adam Kunicki
committed
Fix taste command, report progress
1 parent d3d3a28 commit 8a2b0a1

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

cmd/taste.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
"os"
2121
"strings"
2222

23-
git "gopkg.in/libgit2/git2go.v27"
23+
log "github.com/sirupsen/logrus"
2424
"github.com/spf13/cobra"
25+
git "gopkg.in/libgit2/git2go.v27"
2526
)
2627

2728
var tasteCmd = &cobra.Command{
@@ -39,7 +40,7 @@ func init() {
3940
RootCmd.AddCommand(tasteCmd)
4041

4142
tasteCmd.Flags().BoolVar(&wip, "wip", false, "Setting this flag will post a WIP review")
42-
tasteCmd.Flags().StringArrayVarP(&reviewers, "reviewers", "r", nil, "Comma separated list of email ids of reviewers to add")
43+
tasteCmd.Flags().StringSliceVarP(&reviewers, "reviewers", "r", nil, "Comma separated list of email ids of reviewers to add")
4344
}
4445

4546
func taste(cmd *cobra.Command, args []string) {
@@ -74,26 +75,28 @@ func taste(cmd *cobra.Command, args []string) {
7475
if len(reviewers) > 0 {
7576
refspec = fmt.Sprintf("%s%%r=%s", refspec, strings.Join(reviewers, ",r="))
7677
}
78+
log.WithField("refspec", refspec).Debug("Using refspec")
7779

7880
remote, err := repo.Remotes.Lookup("origin")
7981
if err != nil {
8082
panic(err)
8183
}
82-
83-
callbacks := &git.RemoteCallbacks{
84-
CredentialsCallback: credentialsCallback,
85-
CertificateCheckCallback: certificateCheckCallback,
86-
}
87-
88-
err = remote.ConnectPush(callbacks, nil, make([]string, 0))
89-
if err != nil {
90-
panic(err)
84+
log.WithField("remote", remote).Debug("Discovered remote")
85+
86+
pushOpts := &git.PushOptions{
87+
RemoteCallbacks: git.RemoteCallbacks{
88+
CredentialsCallback: credentialsCallback,
89+
CertificateCheckCallback: certificateCheckCallback,
90+
SidebandProgressCallback: transportMessageCallback,
91+
},
9192
}
92-
93-
pushOpts := &git.PushOptions{}
9493
refspecs := []string{refspec}
9594
err = remote.Push(refspecs, pushOpts)
96-
95+
if err != nil {
96+
log.WithError(err).Error("Error pushing review")
97+
os.Exit(1)
98+
}
99+
log.Info("Pushed review")
97100
}
98101

99102
func credentialsCallback(url string, username string, allowedTypes git.CredType) (git.ErrorCode, *git.Cred) {
@@ -104,3 +107,8 @@ func credentialsCallback(url string, username string, allowedTypes git.CredType)
104107
func certificateCheckCallback(cert *git.Certificate, valid bool, hostname string) git.ErrorCode {
105108
return 0
106109
}
110+
111+
func transportMessageCallback(str string) git.ErrorCode {
112+
fmt.Printf(str)
113+
return 0
114+
}

0 commit comments

Comments
 (0)