@@ -29,18 +29,9 @@ func GitLSRemote(repo *gaia.GitRepo) error {
29
29
}
30
30
31
31
// 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
44
35
}
45
36
46
37
// Create client
@@ -78,23 +69,13 @@ func GitLSRemote(repo *gaia.GitRepo) error {
78
69
// The destination will be attached to the given repo obj.
79
70
func gitCloneRepo (repo * gaia.GitRepo ) error {
80
71
// 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
94
75
}
95
76
96
77
// Clone repo
97
- _ , err : = git .PlainClone (repo .LocalDest , false , & git.CloneOptions {
78
+ _ , err = git .PlainClone (repo .LocalDest , false , & git.CloneOptions {
98
79
Auth : auth ,
99
80
URL : repo .URL ,
100
81
RecurseSubmodules : git .DefaultSubmoduleRecursionDepth ,
@@ -131,9 +112,16 @@ func updateAllCurrentPipelines() {
131
112
}
132
113
gaia .Cfg .Logger .Debug ("checking pipeline: " , pipe .Name )
133
114
gaia .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
+ }
134
121
tree , _ := r .Worktree ()
135
122
err = tree .Pull (& git.PullOptions {
136
123
RemoteName : "origin" ,
124
+ Auth : auth ,
137
125
})
138
126
if err != nil {
139
127
// It's also an error if the repo is already up to date so we just move on.
@@ -152,3 +140,21 @@ func updateAllCurrentPipelines() {
152
140
}
153
141
wg .Wait ()
154
142
}
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
+ }
0 commit comments