@@ -20,8 +20,9 @@ import (
20
20
"os"
21
21
"strings"
22
22
23
- git "gopkg.in/libgit2/git2go.v27 "
23
+ log "github.com/sirupsen/logrus "
24
24
"github.com/spf13/cobra"
25
+ git "gopkg.in/libgit2/git2go.v27"
25
26
)
26
27
27
28
var tasteCmd = & cobra.Command {
@@ -39,7 +40,7 @@ func init() {
39
40
RootCmd .AddCommand (tasteCmd )
40
41
41
42
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" )
43
44
}
44
45
45
46
func taste (cmd * cobra.Command , args []string ) {
@@ -74,26 +75,28 @@ func taste(cmd *cobra.Command, args []string) {
74
75
if len (reviewers ) > 0 {
75
76
refspec = fmt .Sprintf ("%s%%r=%s" , refspec , strings .Join (reviewers , ",r=" ))
76
77
}
78
+ log .WithField ("refspec" , refspec ).Debug ("Using refspec" )
77
79
78
80
remote , err := repo .Remotes .Lookup ("origin" )
79
81
if err != nil {
80
82
panic (err )
81
83
}
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
+ },
91
92
}
92
-
93
- pushOpts := & git.PushOptions {}
94
93
refspecs := []string {refspec }
95
94
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" )
97
100
}
98
101
99
102
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)
104
107
func certificateCheckCallback (cert * git.Certificate , valid bool , hostname string ) git.ErrorCode {
105
108
return 0
106
109
}
110
+
111
+ func transportMessageCallback (str string ) git.ErrorCode {
112
+ fmt .Printf (str )
113
+ return 0
114
+ }
0 commit comments