@@ -29,18 +29,9 @@ func GitLSRemote(repo *gaia.GitRepo) error {
2929}
3030
3131// Attach credentials if provided
32- var auth transport.AuthMethod
33- if repo .Username != "" && repo .Password != "" {
34- // Basic auth provided
35- auth = & http.BasicAuth {
36- Username :repo .Username ,
37- Password :repo .Password ,
38- }
39- }else if repo .PrivateKey .Key != "" {
40- auth ,err = ssh .NewPublicKeys (repo .PrivateKey .Username , []byte (repo .PrivateKey .Key ),repo .PrivateKey .Password )
41- if err != nil {
42- return err
43- }
32+ auth ,err := getAuthInfo (repo )
33+ if err != nil {
34+ return err
4435}
4536
4637// Create client
@@ -78,23 +69,13 @@ func GitLSRemote(repo *gaia.GitRepo) error {
7869// The destination will be attached to the given repo obj.
7970func gitCloneRepo (repo * gaia.GitRepo )error {
8071// Check if credentials were provided
81- var auth transport.AuthMethod
82- if repo .Username != "" && repo .Password != "" {
83- // Basic auth provided
84- auth = & http.BasicAuth {
85- Username :repo .Username ,
86- Password :repo .Password ,
87- }
88- }else if repo .PrivateKey .Key != "" {
89- var err error
90- auth ,err = ssh .NewPublicKeys (repo .PrivateKey .Username , []byte (repo .PrivateKey .Key ),repo .PrivateKey .Password )
91- if err != nil {
92- return err
93- }
72+ auth ,err := getAuthInfo (repo )
73+ if err != nil {
74+ return err
9475}
9576
9677// Clone repo
97- _ ,err : =git .PlainClone (repo .LocalDest ,false ,& git.CloneOptions {
78+ _ ,err = git .PlainClone (repo .LocalDest ,false ,& git.CloneOptions {
9879Auth :auth ,
9980URL :repo .URL ,
10081RecurseSubmodules :git .DefaultSubmoduleRecursionDepth ,
@@ -131,9 +112,16 @@ func updateAllCurrentPipelines() {
131112}
132113gaia .Cfg .Logger .Debug ("checking pipeline: " ,pipe .Name )
133114gaia .Cfg .Logger .Debug ("selected branch : " ,pipe .Repo .SelectedBranch )
115+ auth ,err := getAuthInfo (& pipe .Repo )
116+ if err != nil {
117+ // It's also an error if the repo is already up to date so we just move on.
118+ gaia .Cfg .Logger .Error ("error getting auth info while doing a pull request : " ,err .Error ())
119+ return
120+ }
134121tree ,_ := r .Worktree ()
135122err = tree .Pull (& git.PullOptions {
136123RemoteName :"origin" ,
124+ Auth :auth ,
137125})
138126if err != nil {
139127// It's also an error if the repo is already up to date so we just move on.
@@ -152,3 +140,21 @@ func updateAllCurrentPipelines() {
152140}
153141wg .Wait ()
154142}
143+
144+ func getAuthInfo (repo * gaia.GitRepo ) (transport.AuthMethod ,error ) {
145+ var auth transport.AuthMethod
146+ if repo .Username != "" && repo .Password != "" {
147+ // Basic auth provided
148+ auth = & http.BasicAuth {
149+ Username :repo .Username ,
150+ Password :repo .Password ,
151+ }
152+ }else if repo .PrivateKey .Key != "" {
153+ var err error
154+ auth ,err = ssh .NewPublicKeys (repo .PrivateKey .Username , []byte (repo .PrivateKey .Key ),repo .PrivateKey .Password )
155+ if err != nil {
156+ return nil ,err
157+ }
158+ }
159+ return auth ,nil
160+ }