@@ -32,6 +32,12 @@ import (
32
32
33
33
// Options is the main structure for configuring a fast forward.
34
34
type Options struct {
35
+ // GitHubOrg is the GitHub Organization to be used do the initial clone.
36
+ GitHubOrg string
37
+
38
+ // GitHubRepo is the GitHub Repository to be used do the initial clone.
39
+ GitHubRepo string
40
+
35
41
// Branch is the release branch to be fast forwarded.
36
42
Branch string
37
43
@@ -91,7 +97,7 @@ func (f *FastForward) Run() (err error) {
91
97
return f .Submit (options )
92
98
}
93
99
94
- repo , err := f .prepareKubernetesRepo ()
100
+ repo , err := f .prepareFastForwardRepo ()
95
101
if err != nil {
96
102
return fmt .Errorf ("prepare repository: %w" , err )
97
103
}
@@ -236,7 +242,7 @@ func (f *FastForward) Run() (err error) {
236
242
return fmt .Errorf ("get HEAD rev: %w" , err )
237
243
}
238
244
239
- prepushMessage (f .RepoDir (repo ), branch , f .options .MainRef , releaseRev , headRev )
245
+ prepushMessage (f .RepoDir (repo ), f . options . GitHubOrg , f . options . GitHubRepo , branch , f .options .MainRef , releaseRev , headRev )
240
246
241
247
pushUpstream := false
242
248
if f .options .NonInteractive {
@@ -258,7 +264,7 @@ func (f *FastForward) Run() (err error) {
258
264
return nil
259
265
}
260
266
261
- func prepushMessage (gitRoot , branch , ref , releaseRev , headRev string ) {
267
+ func prepushMessage (gitRoot , org , repo , branch , ref , releaseRev , headRev string ) {
262
268
fmt .Printf (`Go look around in %s to make sure things look okay before pushing…
263
269
264
270
Check for files left uncommitted using:
@@ -281,8 +287,8 @@ func prepushMessage(gitRoot, branch, ref, releaseRev, headRev string) {
281
287
gitRoot ,
282
288
git .Remotify (branch ),
283
289
ref ,
284
- git . DefaultGithubOrg ,
285
- git . DefaultGithubRepo ,
290
+ org ,
291
+ repo ,
286
292
releaseRev ,
287
293
headRev ,
288
294
)
@@ -303,41 +309,40 @@ func (f *FastForward) branchToVersion(branch string) string {
303
309
return fmt .Sprintf ("v%s.0" , strings .TrimPrefix (branch , "release-" ))
304
310
}
305
311
306
- func (f * FastForward ) prepareKubernetesRepo () (* git.Repo , error ) {
307
- logrus .Infof ("Preparing to fast-forward from %s" , f .options .MainRef )
312
+ func (f * FastForward ) prepareFastForwardRepo () (* git.Repo , error ) {
313
+ logrus .Infof ("Preparing to %s/%s fast-forward from %s" , f . options . GitHubOrg , f . options . GitHubRepo , f .options .MainRef )
308
314
309
315
token := f .EnvDefault (github .TokenEnvKey , "" )
316
+
317
+ useSSH := true
318
+ stringMsg := "using SSH"
310
319
if token != "" {
311
- logrus . Info ( "Found GitHub token, using it for repository interactions" )
312
- k8sOrg := release . GetK8sOrg ()
313
- k8sRepo := release . GetK8sRepo ()
320
+ useSSH = false
321
+ stringMsg = "using HTTPs"
322
+ }
314
323
315
- logrus .Info ("Cloning repository by using HTTPs" )
316
- repo , err := f .CloneOrOpenGitHubRepo (f .options .RepoPath , k8sOrg , k8sRepo , false )
317
- if err != nil {
318
- return nil , fmt .Errorf ("clone or open k/k GitHub repository: %w" , err )
319
- }
324
+ logrus .Infof ("Cloning repository %s/%s %s" , f .options .GitHubOrg , f .options .GitHubRepo , stringMsg )
325
+ repo , err := f .CloneOrOpenGitHubRepo (f .options .RepoPath , f .options .GitHubOrg , f .options .GitHubRepo , useSSH )
326
+ if err != nil {
327
+ return nil , fmt .Errorf ("clone or open %s/%s GitHub repository: %w" ,
328
+ f .options .GitHubOrg , f .options .GitHubRepo , err ,
329
+ )
330
+ }
320
331
332
+ if token != "" {
333
+ logrus .Info ("Found GitHub token, using it for repository interactions" )
321
334
if f .IsDefaultK8sUpstream () {
322
335
if err := f .RepoSetURL (repo , git .DefaultRemote , (& url.URL {
323
336
Scheme : "https" ,
324
337
User : url .UserPassword ("git" , token ),
325
338
Host : "github.com" ,
326
- Path : filepath .Join (git . DefaultGithubOrg , git . DefaultGithubRepo ),
339
+ Path : filepath .Join (f . options . GitHubOrg , f . options . GitHubRepo ),
327
340
}).String ()); err != nil {
328
341
return nil , fmt .Errorf ("changing git remote of repository: %w" , err )
329
342
}
330
343
} else {
331
344
logrus .Info ("Using non-default k8s upstream, doing no git modifications" )
332
345
}
333
-
334
- return repo , nil
335
- }
336
-
337
- logrus .Info ("Cloning repository by using SSH" )
338
- repo , err := f .CloneOrOpenDefaultGitHubRepoSSH (f .options .RepoPath )
339
- if err != nil {
340
- return nil , fmt .Errorf ("clone or open k/k GitHub repository: %w" , err )
341
346
}
342
347
343
348
return repo , nil
@@ -368,5 +373,6 @@ func (f *FastForward) prepareToolRepo() error {
368
373
if err := f .Chdir (tmpPath ); err != nil {
369
374
return fmt .Errorf ("change directory: %w" , err )
370
375
}
376
+
371
377
return nil
372
378
}
0 commit comments