Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dora): Add ScopeId to DoraOptions, to support run dora task on specific scope #6965

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions backend/plugins/dora/tasks/deployment_commits_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func GenerateDeploymentCommits(taskCtx plugin.SubTaskContext) errors.Error {
// select all cicd_pipeline_commits from all "Deployments" in the project
// Note that failed records shall be included as well
noneSkippedResult := []string{devops.RESULT_FAILURE, devops.RESULT_SUCCESS}
cursor, err := db.Cursor(
var clauses = []dal.Clause{
dal.Select(
`
pc.*,
Expand All @@ -77,35 +77,37 @@ func GenerateDeploymentCommits(taskCtx plugin.SubTaskContext) errors.Error {
p.cicd_scope_id,
p.original_status,
p.original_result,
EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?)
as has_testing_tasks,
EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?)
as has_staging_tasks,
EXISTS( SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?)
as has_production_tasks
EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?) as has_testing_tasks,
EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?) as has_staging_tasks,
EXISTS( SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?) as has_production_tasks
`,
devops.TESTING, noneSkippedResult,
devops.STAGING, noneSkippedResult,
devops.PRODUCTION, noneSkippedResult,
),
dal.From("cicd_pipeline_commits pc"),
dal.Join("LEFT JOIN cicd_pipelines p ON (p.id = pc.pipeline_id)"),
dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = p.cicd_scope_id)"),
dal.Where(
`
pm.project_name = ? AND (
p.type = ? OR EXISTS(
SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.type = ? AND t.result IN ?
)
) AND p.result IN ?
p.result IN ? AND (
p.type = ? OR EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.type = ? AND t.result IN ?)
)
`,
data.Options.ProjectName,
noneSkippedResult,
devops.DEPLOYMENT,
devops.DEPLOYMENT,
noneSkippedResult,
noneSkippedResult,
),
)
}
if data.Options.ScopeId != nil {
clauses = append(clauses, dal.Where(`p.cicd_scope_id = ?`, data.Options.ScopeId))
} else {
clauses = append(clauses,
dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = p.cicd_scope_id)"),
dal.Where(`pm.project_name = ?`, data.Options.ProjectName),
)
}
cursor, err := db.Cursor(clauses...)
if err != nil {
return err
}
Expand Down
33 changes: 19 additions & 14 deletions backend/plugins/dora/tasks/deployment_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,43 @@ func GenerateDeployment(taskCtx plugin.SubTaskContext) errors.Error {
data := taskCtx.GetData().(*DoraTaskData)
// Note that failed records shall be included as well
noneSkippedResult := []string{devops.RESULT_FAILURE, devops.RESULT_SUCCESS}
cursor, err := db.Cursor(
var clauses = []dal.Clause{
dal.Select(
`
p.*,
EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?)
as has_testing_tasks,
EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?)
as has_staging_tasks,
EXISTS( SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?)
EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.environment = ? AND t.result IN ?)
as has_production_tasks
`,
devops.TESTING, noneSkippedResult,
devops.STAGING, noneSkippedResult,
devops.PRODUCTION, noneSkippedResult,
),
dal.From("cicd_pipelines p"),
dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = p.cicd_scope_id)"),
dal.Where(
`
pm.project_name = ? AND (
p.type = ? OR EXISTS(
SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.type = ? AND t.result IN ?
)
) AND p.result IN ?
`,
data.Options.ProjectName,
dal.Where(`
p.result IN ? AND (
p.type = ? OR EXISTS(SELECT 1 FROM cicd_tasks t WHERE t.pipeline_id = p.id AND t.type = ? AND t.result IN ?)
)`,
noneSkippedResult,
devops.DEPLOYMENT,
devops.DEPLOYMENT,
noneSkippedResult,
noneSkippedResult,
),
)
}
if data.Options.ScopeId != nil {
clauses = append(clauses,
dal.Where("p.cicd_scope_id = ?", data.Options.ScopeId),
)
} else {
clauses = append(clauses,
dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = p.cicd_scope_id)"),
dal.Where("pm.project_name = ?", data.Options.ProjectName),
)
}
cursor, err := db.Cursor(clauses...)
if err != nil {
return err
}
Expand Down
33 changes: 23 additions & 10 deletions backend/plugins/dora/tasks/prev_deployment_commit_enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,34 @@ func EnrichPrevSuccessDeploymentCommit(taskCtx plugin.SubTaskContext) errors.Err
data := taskCtx.GetData().(*DoraTaskData)
// step 1. select all successful deployments in the project and sort them by cicd_scope_id, repo_url, env
// and finished_date
cursor, err := db.Cursor(
var clauses = []dal.Clause{
dal.Select("dc.*"),
dal.From("cicd_deployment_commits dc"),
dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = dc.cicd_scope_id)"),
dal.Where(
`
dal.Where(`
dc.finished_date IS NOT NULL
AND dc.environment IS NOT NULL AND dc.environment != ''
AND dc.repo_url IS NOT NULL AND dc.repo_url != ''
AND pm.project_name = ? AND dc.result = ?
AND dc.environment IS NOT NULL
AND dc.environment != ''
AND dc.repo_url IS NOT NULL
AND dc.repo_url != ''
AND dc.result = ?
`,
data.Options.ProjectName, devops.RESULT_SUCCESS,
devops.RESULT_SUCCESS,
),
dal.Orderby(`dc.cicd_scope_id, dc.repo_url, dc.environment, dc.finished_date`),
)
}
if data.Options.ScopeId != nil {
clauses = append(clauses,
dal.Where("dc.cicd_scope_id = ?", data.Options.ScopeId),
dal.Orderby("dc.repo_url, dc.environment, dc.finished_date"),
)
} else {
clauses = append(clauses,
dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = dc.cicd_scope_id)"),
dal.Where("pm.project_name = ?", data.Options.ProjectName),
dal.Orderby("dc.cicd_scope_id, dc.repo_url, dc.environment, dc.finished_date"),
)
}

cursor, err := db.Cursor(clauses...)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion backend/plugins/dora/tasks/task_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type DoraApiParams struct {
type DoraOptions struct {
Tasks []string `json:"tasks,omitempty"`
Since string
ProjectName string `json:"projectName"`
ProjectName string `json:"projectName"`
ScopeId *string `json:"scopeId,omitempty"`
}

type DoraTaskData struct {
Expand Down
Loading