@@ -65,6 +65,7 @@ type RepoManagerImpl struct {
6565 webhookEventDataMappingRepository sql.WebhookEventDataMappingRepository
6666 webhookEventDataMappingFilterResultRepository sql.WebhookEventDataMappingFilterResultRepository
6767 webhookEventBeanConverter git.WebhookEventBeanConverter
68+ configuration * internal.Configuration
6869}
6970
7071func NewRepoManagerImpl (
@@ -79,6 +80,7 @@ func NewRepoManagerImpl(
7980 webhookEventDataMappingRepository sql.WebhookEventDataMappingRepository ,
8081 webhookEventDataMappingFilterResultRepository sql.WebhookEventDataMappingFilterResultRepository ,
8182 webhookEventBeanConverter git.WebhookEventBeanConverter ,
83+ configuration * internal.Configuration ,
8284) * RepoManagerImpl {
8385 return & RepoManagerImpl {
8486 logger : logger ,
@@ -93,6 +95,7 @@ func NewRepoManagerImpl(
9395 webhookEventDataMappingRepository : webhookEventDataMappingRepository ,
9496 webhookEventDataMappingFilterResultRepository : webhookEventDataMappingFilterResultRepository ,
9597 webhookEventBeanConverter : webhookEventBeanConverter ,
98+ configuration : configuration ,
9699 }
97100}
98101
@@ -187,7 +190,7 @@ func (impl RepoManagerImpl) updatePipelineMaterialCommit(materials []*sql.CiPipe
187190 continue
188191 }
189192
190- commits , err := impl .repositoryManager .ChangesSince (material .CheckoutLocation , pipelineMaterial .Value , "" , "" , 0 )
193+ commits , err := impl .repositoryManager .ChangesSince (material .CheckoutLocation , pipelineMaterial .Value , "" , "" , impl . configuration . GitHistoryCount )
191194 //commits, err := impl.FetchChanges(pipelineMaterial.Id, "", "", 0)
192195 if err == nil {
193196 impl .logger .Infow ("commits found" , "commit" , commits )
@@ -341,7 +344,11 @@ func (impl RepoManagerImpl) checkoutMaterial(material *sql.GitMaterial) (*sql.Gi
341344 if err != nil {
342345 return material , err
343346 }
344- err = impl .repositoryManager .Add (material .GitProviderId , checkoutPath , material .Url , userName , password , gitProvider .AuthMode , gitProvider .SshPrivateKey )
347+ gitContext := & git.GitContext {
348+ Username : userName ,
349+ Password : password ,
350+ }
351+ err = impl .repositoryManager .Add (material .GitProviderId , checkoutPath , material .Url , gitContext , gitProvider .AuthMode , gitProvider .SshPrivateKey )
345352 if err == nil {
346353 material .CheckoutLocation = checkoutPath
347354 material .CheckoutStatus = true
@@ -617,17 +624,38 @@ func (impl RepoManagerImpl) GetLatestCommitForBranch(pipelineMaterialId int, bra
617624 }()
618625
619626 userName , password , err := git .GetUserNamePassword (gitMaterial .GitProvider )
620- updated , repo , err := impl .repositoryManager .Fetch (userName , password , gitMaterial .Url , gitMaterial .CheckoutLocation )
627+ gitContext := & git.GitContext {
628+ Username : userName ,
629+ Password : password ,
630+ }
631+ updated , repo , err := impl .repositoryManager .Fetch (gitContext , gitMaterial .Url , gitMaterial .CheckoutLocation , gitMaterial )
632+ if ! updated {
633+ impl .logger .Warn ("repository is up to date" )
634+ }
635+ if err == nil {
636+ gitMaterial .CheckoutStatus = true
637+ } else {
638+ gitMaterial .CheckoutStatus = false
639+ gitMaterial .CheckoutMsgAny = err .Error ()
640+ gitMaterial .FetchErrorMessage = err .Error ()
641+
642+ impl .logger .Errorw ("error in fetching the repository " , "gitMaterial" , gitMaterial , "err" , err )
643+ return nil , err
644+ }
621645
646+ err = impl .materialRepository .Update (gitMaterial )
622647 if err != nil {
623- impl .logger .Errorw ("error in fetching the repository " , "err" , err )
648+ impl .logger .Errorw ("error in updating material repo " , "err" , err , "material" , gitMaterial )
624649 return nil , err
625650 }
626- if ! updated {
627- impl .logger .Warn ("repository is up to date" )
651+ ciPipelineMaterial , err := impl .ciPipelineMaterialRepository .FindByGitMaterialId (gitMaterial .Id )
652+ if err != nil {
653+ impl .logger .Errorw ("unable to load material" , "err" , err , "ciPipelineMaterial" , ciPipelineMaterial )
654+ return nil , err
628655 }
656+ err = impl .updatePipelineMaterialCommit (ciPipelineMaterial )
629657 if err != nil {
630- impl .logger .Errorw ("error in fetching the repository " , "err" , err )
658+ impl .logger .Errorw ("error in updating pipeline material " , "err" , err )
631659 return nil , err
632660 }
633661
0 commit comments