@@ -26,6 +26,7 @@ import (
26
26
"fmt"
27
27
"github.com/devtron-labs/devtron/api/bean/gitOps"
28
28
"github.com/devtron-labs/devtron/internal/middleware"
29
+ appWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
29
30
repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository"
30
31
"go.opentelemetry.io/otel"
31
32
"strings"
@@ -87,20 +88,22 @@ type AppListingRepositoryImpl struct {
87
88
appListingRepositoryQueryBuilder helper.AppListingRepositoryQueryBuilder
88
89
environmentRepository repository2.EnvironmentRepository
89
90
gitOpsRepository GitOpsConfigRepository
91
+ appWorkflowRepository appWorkflow2.AppWorkflowRepository
90
92
}
91
93
92
94
func NewAppListingRepositoryImpl (
93
95
Logger * zap.SugaredLogger ,
94
96
dbConnection * pg.DB ,
95
97
appListingRepositoryQueryBuilder helper.AppListingRepositoryQueryBuilder ,
96
98
environmentRepository repository2.EnvironmentRepository ,
97
- gitOpsRepository GitOpsConfigRepository ) * AppListingRepositoryImpl {
99
+ gitOpsRepository GitOpsConfigRepository , appWorkflowRepository appWorkflow2. AppWorkflowRepository ) * AppListingRepositoryImpl {
98
100
return & AppListingRepositoryImpl {
99
101
dbConnection : dbConnection ,
100
102
Logger : Logger ,
101
103
appListingRepositoryQueryBuilder : appListingRepositoryQueryBuilder ,
102
104
environmentRepository : environmentRepository ,
103
105
gitOpsRepository : gitOpsRepository ,
106
+ appWorkflowRepository : appWorkflowRepository ,
104
107
}
105
108
}
106
109
@@ -321,6 +324,20 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
321
324
return appEnvArr , appsSize , nil
322
325
}
323
326
327
+ func (impl AppListingRepositoryImpl ) getEnvironmentNameFromPipelineId (pipelineID int ) (string , error ) {
328
+ var environmentName string
329
+ query := "SELECT e.environment_name " +
330
+ "FROM pipeline p " +
331
+ "JOIN environment e ON p.environment_id = e.id WHERE p.id = ?"
332
+
333
+ _ , err := impl .dbConnection .Query (& environmentName , query , pipelineID )
334
+ if err != nil {
335
+ impl .Logger .Errorw ("error in finding environment" , "err" , err , "pipelineID" , pipelineID )
336
+ return "" , err
337
+ }
338
+ return environmentName , nil
339
+ }
340
+
324
341
// DeploymentDetailsByAppIdAndEnvId It will return the deployment detail of any cd pipeline which is latest triggered for Environment of any App
325
342
func (impl AppListingRepositoryImpl ) deploymentDetailsByAppIdAndEnvId (ctx context.Context , appId int , envId int ) (bean.DeploymentDetailContainer , error ) {
326
343
_ , span := otel .Tracer ("orchestrator" ).Start (ctx , "DeploymentDetailsByAppIdAndEnvId" )
@@ -340,7 +357,10 @@ func (impl AppListingRepositoryImpl) deploymentDetailsByAppIdAndEnvId(ctx contex
340
357
" cl.k8s_version," +
341
358
" env.cluster_id," +
342
359
" env.is_virtual_environment," +
343
- " cl.cluster_name" +
360
+ " cl.cluster_name," +
361
+ " p.id as cd_pipeline_id," +
362
+ " p.ci_pipeline_id," +
363
+ " p.trigger_type" +
344
364
" FROM pipeline p" +
345
365
" INNER JOIN pipeline_config_override pco on pco.pipeline_id=p.id" +
346
366
" INNER JOIN environment env ON env.id=p.environment_id" +
@@ -423,6 +443,11 @@ func (impl AppListingRepositoryImpl) FetchAppDetail(ctx context.Context, appId i
423
443
if err != nil {
424
444
impl .Logger .Warn ("unable to fetch deployment detail for app" )
425
445
}
446
+ appWfMapping , _ := impl .appWorkflowRepository .FindWFCDMappingByCDPipelineId (deploymentDetail .CdPipelineId )
447
+ if appWfMapping .ParentType == appWorkflow2 .CDPIPELINE {
448
+ parentEnvironmentName , _ := impl .getEnvironmentNameFromPipelineId (appWfMapping .ParentId )
449
+ deploymentDetail .ParentEnvironmentName = parentEnvironmentName
450
+ }
426
451
appDetailContainer .DeploymentDetailContainer = deploymentDetail
427
452
return appDetailContainer , nil
428
453
}
0 commit comments