Skip to content

Commit 68f9c0b

Browse files
Merge remote-tracking branch 'origin/main' into get_cluster_name
2 parents 699e970 + 9260b40 commit 68f9c0b

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

api/bean/AppView.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ type AppEnvironmentContainer struct {
144144
type DeploymentDetailContainer struct {
145145
InstalledAppId int `json:"installedAppId,omitempty"`
146146
AppId int `json:"appId,omitempty"`
147+
CdPipelineId int `json:"cdPipelineId,omitempty"`
148+
TriggerType string `json:"triggerType,omitempty"`
149+
ParentEnvironmentName string `json:"parentEnvironmentName"`
147150
AppStoreInstalledAppVersionId int `json:"appStoreInstalledAppVersionId,omitempty"`
148151
AppStoreChartName string `json:"appStoreChartName,omitempty"`
149152
AppStoreChartId int `json:"appStoreChartId,omitempty"`
@@ -169,7 +172,7 @@ type DeploymentDetailContainer struct {
169172
ParentArtifactId int `json:"parentArtifactId"`
170173
ClusterId int `json:"clusterId"`
171174
DeploymentAppType string `json:"deploymentAppType"`
172-
CiPipelineId int `json:"-"`
175+
CiPipelineId int `json:"ciPipelineId,omitempty"`
173176
IsExternalCi bool `json:"externalCi"`
174177
ClusterName string `json:"clusterName,omitempty"`
175178
DockerRegistryId string `json:"dockerRegistryId,omitempty"`

internal/sql/repository/AppListingRepository.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"fmt"
2727
"github.com/devtron-labs/devtron/api/bean/gitOps"
2828
"github.com/devtron-labs/devtron/internal/middleware"
29+
appWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
2930
repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository"
3031
"go.opentelemetry.io/otel"
3132
"strings"
@@ -87,20 +88,22 @@ type AppListingRepositoryImpl struct {
8788
appListingRepositoryQueryBuilder helper.AppListingRepositoryQueryBuilder
8889
environmentRepository repository2.EnvironmentRepository
8990
gitOpsRepository GitOpsConfigRepository
91+
appWorkflowRepository appWorkflow2.AppWorkflowRepository
9092
}
9193

9294
func NewAppListingRepositoryImpl(
9395
Logger *zap.SugaredLogger,
9496
dbConnection *pg.DB,
9597
appListingRepositoryQueryBuilder helper.AppListingRepositoryQueryBuilder,
9698
environmentRepository repository2.EnvironmentRepository,
97-
gitOpsRepository GitOpsConfigRepository) *AppListingRepositoryImpl {
99+
gitOpsRepository GitOpsConfigRepository, appWorkflowRepository appWorkflow2.AppWorkflowRepository) *AppListingRepositoryImpl {
98100
return &AppListingRepositoryImpl{
99101
dbConnection: dbConnection,
100102
Logger: Logger,
101103
appListingRepositoryQueryBuilder: appListingRepositoryQueryBuilder,
102104
environmentRepository: environmentRepository,
103105
gitOpsRepository: gitOpsRepository,
106+
appWorkflowRepository: appWorkflowRepository,
104107
}
105108
}
106109

@@ -321,6 +324,20 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
321324
return appEnvArr, appsSize, nil
322325
}
323326

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+
324341
// DeploymentDetailsByAppIdAndEnvId It will return the deployment detail of any cd pipeline which is latest triggered for Environment of any App
325342
func (impl AppListingRepositoryImpl) deploymentDetailsByAppIdAndEnvId(ctx context.Context, appId int, envId int) (bean.DeploymentDetailContainer, error) {
326343
_, span := otel.Tracer("orchestrator").Start(ctx, "DeploymentDetailsByAppIdAndEnvId")
@@ -340,7 +357,10 @@ func (impl AppListingRepositoryImpl) deploymentDetailsByAppIdAndEnvId(ctx contex
340357
" cl.k8s_version," +
341358
" env.cluster_id," +
342359
" 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" +
344364
" FROM pipeline p" +
345365
" INNER JOIN pipeline_config_override pco on pco.pipeline_id=p.id" +
346366
" INNER JOIN environment env ON env.id=p.environment_id" +
@@ -423,6 +443,11 @@ func (impl AppListingRepositoryImpl) FetchAppDetail(ctx context.Context, appId i
423443
if err != nil {
424444
impl.Logger.Warn("unable to fetch deployment detail for app")
425445
}
446+
appWfMapping, _ := impl.appWorkflowRepository.FindWFCDMappingByCDPipelineId(deploymentDetail.CdPipelineId)
447+
if appWfMapping.ParentType == appWorkflow2.CDPIPELINE {
448+
parentEnvironmentName, _ := impl.getEnvironmentNameFromPipelineId(appWfMapping.ParentId)
449+
deploymentDetail.ParentEnvironmentName = parentEnvironmentName
450+
}
426451
appDetailContainer.DeploymentDetailContainer = deploymentDetail
427452
return appDetailContainer, nil
428453
}

wire_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)