From 43359fb0957272a398bf72ee0ba26fe5ad63f020 Mon Sep 17 00:00:00 2001 From: Cameron Braid Date: Sat, 30 Apr 2022 18:43:10 +1000 Subject: [PATCH] fix: use currect Git Server URL and auth details for lighthouse as for scm provider --- pkg/cmd/start/start.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/start/start.go b/pkg/cmd/start/start.go index 697e9e3c..3e65485c 100644 --- a/pkg/cmd/start/start.go +++ b/pkg/cmd/start/start.go @@ -3,6 +3,7 @@ package start import ( "context" "fmt" + "net/url" "sort" "strings" "time" @@ -438,7 +439,32 @@ func (o *Options) createLighthouseJob(jobName string, cfg *config.Config) error }, } - configureOpts := func(opts *gitv2.ClientFactoryOpts) {} + // use the same git server information for lighthouse as the scmClient uses + var gitServerURLParsed *url.URL + gitServerURLParsed, err = url.Parse(gitServerURL) + if err != nil { + return errors.Wrapf(err, "failed to parse git URL %s", gitServerURLParsed) + } + + // o.FindGitToken uses o.GitServerURL so set it + o.GitServerURL = sr.Spec.Provider + o.FindGitToken() + + configureOpts := func(opts *gitv2.ClientFactoryOpts) { + opts.Token = func() []byte { + return []byte(o.ResolverOptions.Factory.GitToken) + } + opts.GitUser = func() (name, email string, err error) { + name = o.ResolverOptions.Factory.GitUsername + return + } + opts.Username = func() (login string, err error) { + login = o.ResolverOptions.Factory.GitUsername + return + } + opts.Host = gitServerURLParsed.Host + opts.Scheme = gitServerURLParsed.Scheme + } gitFactory, err := gitv2.NewClientFactory(configureOpts) if err != nil { return errors.Wrapf(err, "failed to create git factory")