Skip to content

Commit

Permalink
feat: added fields in app details api (#4937)
Browse files Browse the repository at this point in the history
* added fields cdPipelinId,  deploymentAppType, triggerType, ciPipelineId and parentEnvironmentName in app details api

* code cleaning

* code cleaning

* code review comments incorporated
  • Loading branch information
ShashwatDadhich authored Apr 19, 2024
1 parent 131d16f commit 9260b40
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
5 changes: 4 additions & 1 deletion api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type AppEnvironmentContainer struct {
type DeploymentDetailContainer struct {
InstalledAppId int `json:"installedAppId,omitempty"`
AppId int `json:"appId,omitempty"`
CdPipelineId int `json:"cdPipelineId,omitempty"`
TriggerType string `json:"triggerType,omitempty"`
ParentEnvironmentName string `json:"parentEnvironmentName"`
AppStoreInstalledAppVersionId int `json:"appStoreInstalledAppVersionId,omitempty"`
AppStoreChartName string `json:"appStoreChartName,omitempty"`
AppStoreChartId int `json:"appStoreChartId,omitempty"`
Expand All @@ -169,7 +172,7 @@ type DeploymentDetailContainer struct {
ParentArtifactId int `json:"parentArtifactId"`
ClusterId int `json:"clusterId"`
DeploymentAppType string `json:"deploymentAppType"`
CiPipelineId int `json:"-"`
CiPipelineId int `json:"ciPipelineId,omitempty"`
IsExternalCi bool `json:"externalCi"`
ClusterName string `json:"clusterName,omitempty"`
DockerRegistryId string `json:"dockerRegistryId,omitempty"`
Expand Down
29 changes: 27 additions & 2 deletions internal/sql/repository/AppListingRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"fmt"
"github.com/devtron-labs/devtron/api/bean/gitOps"
"github.com/devtron-labs/devtron/internal/middleware"
appWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository"
"go.opentelemetry.io/otel"
"strings"
Expand Down Expand Up @@ -87,20 +88,22 @@ type AppListingRepositoryImpl struct {
appListingRepositoryQueryBuilder helper.AppListingRepositoryQueryBuilder
environmentRepository repository2.EnvironmentRepository
gitOpsRepository GitOpsConfigRepository
appWorkflowRepository appWorkflow2.AppWorkflowRepository
}

func NewAppListingRepositoryImpl(
Logger *zap.SugaredLogger,
dbConnection *pg.DB,
appListingRepositoryQueryBuilder helper.AppListingRepositoryQueryBuilder,
environmentRepository repository2.EnvironmentRepository,
gitOpsRepository GitOpsConfigRepository) *AppListingRepositoryImpl {
gitOpsRepository GitOpsConfigRepository, appWorkflowRepository appWorkflow2.AppWorkflowRepository) *AppListingRepositoryImpl {
return &AppListingRepositoryImpl{
dbConnection: dbConnection,
Logger: Logger,
appListingRepositoryQueryBuilder: appListingRepositoryQueryBuilder,
environmentRepository: environmentRepository,
gitOpsRepository: gitOpsRepository,
appWorkflowRepository: appWorkflowRepository,
}
}

Expand Down Expand Up @@ -321,6 +324,20 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
return appEnvArr, appsSize, nil
}

func (impl AppListingRepositoryImpl) getEnvironmentNameFromPipelineId(pipelineID int) (string, error) {
var environmentName string
query := "SELECT e.environment_name " +
"FROM pipeline p " +
"JOIN environment e ON p.environment_id = e.id WHERE p.id = ?"

_, err := impl.dbConnection.Query(&environmentName, query, pipelineID)
if err != nil {
impl.Logger.Errorw("error in finding environment", "err", err, "pipelineID", pipelineID)
return "", err
}
return environmentName, nil
}

// DeploymentDetailsByAppIdAndEnvId It will return the deployment detail of any cd pipeline which is latest triggered for Environment of any App
func (impl AppListingRepositoryImpl) deploymentDetailsByAppIdAndEnvId(ctx context.Context, appId int, envId int) (bean.DeploymentDetailContainer, error) {
_, span := otel.Tracer("orchestrator").Start(ctx, "DeploymentDetailsByAppIdAndEnvId")
Expand All @@ -340,7 +357,10 @@ func (impl AppListingRepositoryImpl) deploymentDetailsByAppIdAndEnvId(ctx contex
" cl.k8s_version," +
" env.cluster_id," +
" env.is_virtual_environment," +
" cl.cluster_name" +
" cl.cluster_name," +
" p.id as cd_pipeline_id," +
" p.ci_pipeline_id," +
" p.trigger_type" +
" FROM pipeline p" +
" INNER JOIN pipeline_config_override pco on pco.pipeline_id=p.id" +
" INNER JOIN environment env ON env.id=p.environment_id" +
Expand Down Expand Up @@ -423,6 +443,11 @@ func (impl AppListingRepositoryImpl) FetchAppDetail(ctx context.Context, appId i
if err != nil {
impl.Logger.Warn("unable to fetch deployment detail for app")
}
appWfMapping, _ := impl.appWorkflowRepository.FindWFCDMappingByCDPipelineId(deploymentDetail.CdPipelineId)
if appWfMapping.ParentType == appWorkflow2.CDPIPELINE {
parentEnvironmentName, _ := impl.getEnvironmentNameFromPipelineId(appWfMapping.ParentId)
deploymentDetail.ParentEnvironmentName = parentEnvironmentName
}
appDetailContainer.DeploymentDetailContainer = deploymentDetail
return appDetailContainer, nil
}
Expand Down
4 changes: 2 additions & 2 deletions wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9260b40

Please sign in to comment.