@@ -48,8 +48,11 @@ func (g *gitRepoFactory) parseSkipTLSFromRepo(ctx context.Context, repo *v1alpha
4848}
4949
5050func (g * gitRepoFactory ) parseAuthorFromSecret (ctx context.Context , secret * v1.Secret ) * object.Signature {
51- authorName := secret .Annotations [constants .GitAuthorNameAnnotationKey ]
52- authorEmail := secret .Annotations [constants .GitAuthorEmailAnnotationKey ]
51+ var authorName , authorEmail string
52+ if secret != nil {
53+ authorName = secret .Annotations [constants .GitAuthorNameAnnotationKey ]
54+ authorEmail = secret .Annotations [constants .GitAuthorEmailAnnotationKey ]
55+ }
5356 return & object.Signature {
5457 Name : authorName ,
5558 Email : authorEmail ,
@@ -62,25 +65,35 @@ func (g *gitRepoFactory) NewRepoService(ctx context.Context, user user.Info, rep
6265 return nil , err
6366 }
6467
68+ var token , tokenUser string
69+ var secret * v1.Secret
70+ var auth * http.BasicAuth
71+
6572 secretRef := gitRepo .Spec .Secret
66- secret , err := g .getSecret (ctx , secretRef )
67- if err != nil {
68- return nil , err
69- }
70- token , tokenUser , err := g .getTokenFromSecret (ctx , secret )
71- if err != nil {
72- return nil , err
73- }
74- if token == "" {
75- return nil , fmt .Errorf ("failed to get token" )
73+ // Note: public repo does not need a secret
74+ if secretRef != nil && secretRef .Name != "" && secretRef .Namespace != "" {
75+ secret , err = g .getSecret (ctx , secretRef )
76+ if err != nil {
77+ return nil , err
78+ }
79+ token , tokenUser , err = g .getTokenFromSecret (ctx , secret )
80+ if err != nil {
81+ return nil , err
82+ }
83+ if token == "" {
84+ return nil , fmt .Errorf ("failed to get token" )
85+ }
7686 }
87+
7788 if tokenUser == "" {
7889 tokenUser = user .GetName () // yes, this can be anything except an empty string
7990 }
8091
81- auth := & http.BasicAuth {
82- Username : tokenUser ,
83- Password : token ,
92+ if tokenUser != "" && token != "" {
93+ auth = & http.BasicAuth {
94+ Username : tokenUser ,
95+ Password : token ,
96+ }
8497 }
8598
8699 insecureSkipTLS := g .parseSkipTLSFromRepo (ctx , gitRepo )
0 commit comments