@@ -143,6 +143,7 @@ type AppListingServiceImpl struct {
143
143
dockerRegistryIpsConfigService dockerRegistry.DockerRegistryIpsConfigService
144
144
userRepository userrepository.UserRepository
145
145
deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService
146
+ ciArtifactRepository repository.CiArtifactRepository
146
147
}
147
148
148
149
func NewAppListingServiceImpl (Logger * zap.SugaredLogger , appListingRepository repository.AppListingRepository ,
@@ -153,7 +154,7 @@ func NewAppListingServiceImpl(Logger *zap.SugaredLogger, appListingRepository re
153
154
argoUserService argo.ArgoUserService , envOverrideRepository chartConfig.EnvConfigOverrideRepository ,
154
155
chartRepository chartRepoRepository.ChartRepository , ciPipelineRepository pipelineConfig.CiPipelineRepository ,
155
156
dockerRegistryIpsConfigService dockerRegistry.DockerRegistryIpsConfigService , userRepository userrepository.UserRepository ,
156
- deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService ) * AppListingServiceImpl {
157
+ deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService , ciArtifactRepository repository. CiArtifactRepository ) * AppListingServiceImpl {
157
158
serviceImpl := & AppListingServiceImpl {
158
159
Logger : Logger ,
159
160
appListingRepository : appListingRepository ,
@@ -172,6 +173,7 @@ func NewAppListingServiceImpl(Logger *zap.SugaredLogger, appListingRepository re
172
173
dockerRegistryIpsConfigService : dockerRegistryIpsConfigService ,
173
174
userRepository : userRepository ,
174
175
deployedAppMetricsService : deployedAppMetricsService ,
176
+ ciArtifactRepository : ciArtifactRepository ,
175
177
}
176
178
return serviceImpl
177
179
}
@@ -234,6 +236,8 @@ func (impl AppListingServiceImpl) FetchOverviewAppsByEnvironment(envId, limit, o
234
236
impl .Logger .Errorw ("failed to fetch environment containers" , "err" , err , "envId" , envId )
235
237
return resp , err
236
238
}
239
+
240
+ artifactIds := make ([]int , 0 )
237
241
for _ , envContainer := range envContainers {
238
242
lastDeployed , err := impl .appListingRepository .FetchLastDeployedImage (envContainer .AppId , envId )
239
243
if err != nil {
@@ -243,12 +247,44 @@ func (impl AppListingServiceImpl) FetchOverviewAppsByEnvironment(envId, limit, o
243
247
if lastDeployed != nil {
244
248
envContainer .LastDeployedImage = lastDeployed .LastDeployedImage
245
249
envContainer .LastDeployedBy = lastDeployed .LastDeployedBy
250
+ envContainer .CiArtifactId = lastDeployed .CiArtifactId
251
+ artifactIds = append (artifactIds , lastDeployed .CiArtifactId )
252
+ }
253
+ }
254
+ uniqueArtifacts := getUniqueArtifacts (artifactIds )
255
+
256
+ artifactWithGitCommit , err := impl .generateArtifactIDCommitMap (uniqueArtifacts )
257
+ if err != nil {
258
+ impl .Logger .Errorw ("failed to fetch Artifacts to git Triggers " , "envId" , envId , "err" , err )
259
+ return resp , err
260
+ }
261
+ for _ , envContainer := range envContainers {
262
+ envContainer .Commits = []string {}
263
+ if envContainer .CiArtifactId > 0 {
264
+ if commits , ok := artifactWithGitCommit [envContainer .CiArtifactId ]; ok && commits != nil {
265
+ envContainer .Commits = commits
266
+ }
246
267
}
247
268
}
248
269
resp .Apps = envContainers
249
270
return resp , err
250
271
}
251
272
273
+ func getUniqueArtifacts (artifactIds []int ) (uniqueArtifactIds []int ) {
274
+ uniqueArtifactIds = make ([]int , 0 )
275
+
276
+ uniqueArtifactMap := make (map [int ]bool )
277
+
278
+ for _ , artifactId := range artifactIds {
279
+ if ok := uniqueArtifactMap [artifactId ]; ! ok {
280
+ uniqueArtifactIds = append (uniqueArtifactIds , artifactId )
281
+ uniqueArtifactMap [artifactId ] = true
282
+ }
283
+ }
284
+
285
+ return uniqueArtifactIds
286
+ }
287
+
252
288
func (impl AppListingServiceImpl ) FetchAllDevtronManagedApps () ([]AppNameTypeIdContainer , error ) {
253
289
impl .Logger .Debug ("reached at FetchAllDevtronManagedApps:" )
254
290
apps := make ([]AppNameTypeIdContainer , 0 )
@@ -770,6 +806,49 @@ func (impl AppListingServiceImpl) FetchAppStageStatus(appId int, appType int) ([
770
806
return appStageStatuses , err
771
807
}
772
808
809
+ func (impl AppListingServiceImpl ) generateArtifactIDCommitMap (artifactIds []int ) (ciArtifactAndGitCommitsMap map [int ][]string , err error ) {
810
+
811
+ if len (artifactIds ) == 0 {
812
+ impl .Logger .Errorw ("error in getting the ArtifactIds" , "ArtifactIds" , artifactIds , "err" , err )
813
+ return make (map [int ][]string ), err
814
+ }
815
+
816
+ artifacts , err := impl .ciArtifactRepository .GetByIds (artifactIds )
817
+ if err != nil {
818
+ return make (map [int ][]string ), err
819
+ }
820
+
821
+ ciArtifactAndGitCommitsMap = make (map [int ][]string )
822
+ ciArtifactWithModificationMap := make (map [int ][]repository.Modification )
823
+
824
+ for _ , artifact := range artifacts {
825
+ materialInfo , err := repository .GetCiMaterialInfo (artifact .MaterialInfo , artifact .DataSource )
826
+ if err != nil {
827
+ impl .Logger .Errorw ("error in getting the MaterialInfo" , "ArtifactId" , artifact .Id , "err" , err )
828
+ return make (map [int ][]string ), err
829
+ }
830
+ if len (materialInfo ) == 0 {
831
+ continue
832
+ }
833
+ for _ , material := range materialInfo {
834
+ ciArtifactWithModificationMap [artifact .Id ] = append (ciArtifactWithModificationMap [artifact .Id ], material .Modifications ... )
835
+ }
836
+ }
837
+
838
+ for artifactId , modifications := range ciArtifactWithModificationMap {
839
+
840
+ gitCommits := make ([]string , 0 )
841
+
842
+ for _ , modification := range modifications {
843
+ gitCommits = append (gitCommits , modification .Revision )
844
+ }
845
+
846
+ ciArtifactAndGitCommitsMap [artifactId ] = gitCommits
847
+ }
848
+
849
+ return ciArtifactAndGitCommitsMap , nil
850
+ }
851
+
773
852
func (impl AppListingServiceImpl ) FetchOtherEnvironment (ctx context.Context , appId int ) ([]* bean.Environment , error ) {
774
853
newCtx , span := otel .Tracer ("appListingRepository" ).Start (ctx , "FetchOtherEnvironment" )
775
854
envs , err := impl .appListingRepository .FetchOtherEnvironment (appId )
@@ -793,6 +872,19 @@ func (impl AppListingServiceImpl) FetchOtherEnvironment(ctx context.Context, app
793
872
impl .Logger .Errorw ("error in fetching latest chart" , "err" , err )
794
873
return envs , err
795
874
}
875
+
876
+ ciArtifacts := make ([]int , 0 )
877
+ for _ , env := range envs {
878
+ ciArtifacts = append (ciArtifacts , env .CiArtifactId )
879
+ }
880
+
881
+ uniqueArtifacts := getUniqueArtifacts (ciArtifacts )
882
+
883
+ gitCommitsWithArtifacts , err := impl .generateArtifactIDCommitMap (uniqueArtifacts )
884
+ if err != nil {
885
+ impl .Logger .Errorw ("Error in fetching the git commits of the ciArtifacts" , "err" , err , "ciArtifacts" , ciArtifacts )
886
+ return envs , err
887
+ }
796
888
for _ , env := range envs {
797
889
newCtx , span = otel .Tracer ("envOverrideRepository" ).Start (newCtx , "FindLatestChartForAppByAppIdAndEnvId" )
798
890
envOverride , err := impl .envOverrideRepository .FindLatestChartForAppByAppIdAndEnvId (appId , env .EnvironmentId )
@@ -809,6 +901,12 @@ func (impl AppListingServiceImpl) FetchOtherEnvironment(ctx context.Context, app
809
901
if env .AppMetrics == nil {
810
902
env .AppMetrics = & appLevelAppMetrics
811
903
}
904
+
905
+ if _ , ok := gitCommitsWithArtifacts [env .CiArtifactId ]; ok {
906
+ env .Commits = gitCommitsWithArtifacts [env .CiArtifactId ]
907
+ } else {
908
+ env .Commits = make ([]string , 0 )
909
+ }
812
910
env .InfraMetrics = & appLevelInfraMetrics //using default value, discarding value got from query
813
911
}
814
912
return envs , nil
0 commit comments