@@ -136,6 +136,8 @@ type Gerrit struct {
136
136
AutobumpPRIdentifier string `yaml:"autobumpPRIdentifier"`
137
137
// Gerrit CR Author. Only Required if using gerrit
138
138
Author string `yaml:"author"`
139
+ // Email account associated with gerrit author. Only required if using gerrit.
140
+ Email string `yaml:"email"`
139
141
// The path to the Gerrit httpcookie file. Only Required if using gerrit
140
142
CookieFile string `yaml:"cookieFile"`
141
143
// The path to the hosted Gerrit repo
@@ -375,7 +377,7 @@ func Run(o *Options) error {
375
377
}
376
378
msg := makeGerritCommit (o .Prefixes , versions , o .Gerrit .AutobumpPRIdentifier , changeId )
377
379
// TODO(mpherman): Add reviewers to CreateCR
378
- if err := createCR (msg , "master" , changeId , o .Gerrit .HostRepo , o .Gerrit .CookieFile , nil , nil , stdout , stderr ); err != nil {
380
+ if err := createCR (msg , "master" , changeId , o .Gerrit .HostRepo , o .Gerrit .CookieFile , o . Gerrit . Author , o . Gerrit . Email , nil , nil , stdout , stderr ); err != nil {
379
381
return fmt .Errorf ("Failled to create the CR: %w" , err )
380
382
}
381
383
}
@@ -724,7 +726,7 @@ func MakeGitCommit(remote, remoteBranch, name, email string, prefixes []Prefix,
724
726
}
725
727
726
728
func makeGerritCommit (prefixes []Prefix , versions map [string ][]string , commitTag , changeId string ) string {
727
- return fmt .Sprintf ("[%s] %s \n \n Change-Id: %s" , commitTag , makeCommitSummary (prefixes , versions ), changeId )
729
+ return fmt .Sprintf ("%s \n \n [%s] \n \n Change-Id: %s" , makeCommitSummary (prefixes , versions ), commitTag , changeId )
728
730
}
729
731
730
732
// GitCommitAndPush runs a sequence of git commands to commit.
@@ -981,8 +983,8 @@ func GerritNoOpChange(changeID, hostRepo string) (bool, error) {
981
983
var garbageBuf bytes.Buffer
982
984
var outBuf bytes.Buffer
983
985
// Fetch current pending CRs
984
- if err := Call (& garbageBuf , & garbageBuf , gitCmd , "fetch" , "origin " , "+refs/changes/*:refs/remotes/origin /changes/*" ); err != nil {
985
- return false , fmt .Errorf ("unable to fetch origin changes: %v -- \n OUTPUT: %s" , err , garbageBuf .String ())
986
+ if err := Call (& garbageBuf , & garbageBuf , gitCmd , "fetch" , "upstream " , "+refs/changes/*:refs/remotes/upstream /changes/*" ); err != nil {
987
+ return false , fmt .Errorf ("unable to fetch upstream changes: %v -- \n OUTPUT: %s" , err , garbageBuf .String ())
986
988
}
987
989
// Get PR with same ChangeID for this bump
988
990
if err := Call (& outBuf , & garbageBuf , gitCmd , "log" , "--all" , fmt .Sprintf ("--grep=Change-Id: %s" , changeID ), "-1" , "--format=%H" ); err != nil {
@@ -1004,7 +1006,19 @@ func GerritNoOpChange(changeID, hostRepo string) (bool, error) {
1004
1006
1005
1007
}
1006
1008
1007
- func createCR (msg , branch , changeID , hostRepo , cookieFile string , reviewers , cc []string , stdout , stderr io.Writer ) error {
1009
+ func createCR (msg , branch , changeID , hostRepo , cookieFile , author , email string , reviewers , cc []string , stdout , stderr io.Writer ) error {
1010
+ if err := Call (stdout , stderr , gitCmd , "config" , "http.cookiefile" , cookieFile ); err != nil {
1011
+ return fmt .Errorf ("unable to load cookiefile: %v" , err )
1012
+ }
1013
+ if err := Call (stdout , stderr , gitCmd , "config" , "user.name" , author ); err != nil {
1014
+ return fmt .Errorf ("unable to set username: %v" , err )
1015
+ }
1016
+ if err := Call (stdout , stderr , gitCmd , "config" , "user.email" , email ); err != nil {
1017
+ return fmt .Errorf ("unable to set password: %v" , err )
1018
+ }
1019
+ if err := Call (stdout , stderr , gitCmd , "remote" , "add" , "upstream" , hostRepo ); err != nil {
1020
+ return fmt .Errorf ("unable to add upstream remote: %v" , err )
1021
+ }
1008
1022
noOp , err := GerritNoOpChange (changeID , hostRepo )
1009
1023
if err != nil {
1010
1024
return fmt .Errorf ("error diffing previous bump: %v" , err )
@@ -1018,7 +1032,7 @@ func createCR(msg, branch, changeID, hostRepo, cookieFile string, reviewers, cc
1018
1032
if err := Call (stdout , stderr , gitCmd , "commit" , "-a" , "-v" , "-m" , msg ); err != nil {
1019
1033
return fmt .Errorf ("unable to commit: %v" , err )
1020
1034
}
1021
- if err := Call (stdout , stderr , gitCmd , "push" , "origin " , pushRef ); err != nil {
1035
+ if err := Call (stdout , stderr , gitCmd , "push" , "upstream " , pushRef ); err != nil {
1022
1036
return fmt .Errorf ("unable to push: %v" , err )
1023
1037
}
1024
1038
return nil
0 commit comments