From 152525defe717d78b035537326951a05e049d194 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Wed, 18 Oct 2023 13:10:34 +0800 Subject: [PATCH] fix: pr should be connected to failed deployment commit --- backend/plugins/dora/e2e/calculate_change_lead_time_test.go | 2 +- backend/plugins/dora/e2e/change_lead_time/commits_diffs.csv | 3 ++- backend/plugins/dora/e2e/change_lead_time/project_mapping.csv | 3 ++- .../plugins/dora/e2e/change_lead_time/project_pr_metrics.csv | 1 + backend/plugins/dora/e2e/change_lead_time/pull_requests.csv | 2 +- backend/plugins/dora/tasks/change_lead_time_calculator.go | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/plugins/dora/e2e/calculate_change_lead_time_test.go b/backend/plugins/dora/e2e/calculate_change_lead_time_test.go index 41561d62e90..e37cd635b5f 100644 --- a/backend/plugins/dora/e2e/calculate_change_lead_time_test.go +++ b/backend/plugins/dora/e2e/calculate_change_lead_time_test.go @@ -47,7 +47,7 @@ func TestCalculateCLTimeDataFlow(t *testing.T) { dataflowTester.ImportCsvIntoTabler("./change_lead_time/cicd_scopes.csv", &devops.CicdScope{}) dataflowTester.ImportCsvIntoTabler("./change_lead_time/pull_requests.csv", &code.PullRequest{}) dataflowTester.ImportCsvIntoTabler("./change_lead_time/cicd_deployment_commits.csv", &devops.CicdDeploymentCommit{}) - dataflowTester.ImportCsvIntoTabler("./change_lead_time/commits_diffs.csv", &code.CommitsDiff{}) + dataflowTester.ImportNullableCsvIntoTabler("./change_lead_time/commits_diffs.csv", &code.CommitsDiff{}) dataflowTester.ImportCsvIntoTabler("./change_lead_time/pull_request_comments.csv", &code.PullRequestComment{}) dataflowTester.ImportCsvIntoTabler("./change_lead_time/pull_request_commits.csv", &code.PullRequestCommit{}) diff --git a/backend/plugins/dora/e2e/change_lead_time/commits_diffs.csv b/backend/plugins/dora/e2e/change_lead_time/commits_diffs.csv index 86ba5172691..7f74dccaeb7 100644 --- a/backend/plugins/dora/e2e/change_lead_time/commits_diffs.csv +++ b/backend/plugins/dora/e2e/change_lead_time/commits_diffs.csv @@ -2,4 +2,5 @@ old_commit_sha,new_commit_sha,commit_sha commit1,commit5,pr_merge_commit1 commit1,commit5,pr_merge_commit2 commit2,commit6,pr_merge_commit3 -commit7,commit8,pr_merge_commit4 \ No newline at end of file +commit7,commit8,pr_merge_commit4 +,commit11,pr_merge_commit5 \ No newline at end of file diff --git a/backend/plugins/dora/e2e/change_lead_time/project_mapping.csv b/backend/plugins/dora/e2e/change_lead_time/project_mapping.csv index d6bf7ba1ef9..ff4183398c4 100644 --- a/backend/plugins/dora/e2e/change_lead_time/project_mapping.csv +++ b/backend/plugins/dora/e2e/change_lead_time/project_mapping.csv @@ -3,4 +3,5 @@ project1,cicd_scopes,cicd1 project1,repos,repo1 project1,repos,repo2 project2,cicd_scopes,cicd3 -project2,repos,repo3 \ No newline at end of file +project2,repos,repo3 +project1,cicd_scopes,cicd2 \ No newline at end of file diff --git a/backend/plugins/dora/e2e/change_lead_time/project_pr_metrics.csv b/backend/plugins/dora/e2e/change_lead_time/project_pr_metrics.csv index 41fb7db928b..a86106a9b7a 100644 --- a/backend/plugins/dora/e2e/change_lead_time/project_pr_metrics.csv +++ b/backend/plugins/dora/e2e/change_lead_time/project_pr_metrics.csv @@ -3,3 +3,4 @@ pr1,project1,08d2f2b6de0fa8de4d0e2b55b4b9a2e244214029,1440,comment02,5,55,5,2978 pr2,project1,2537845559d8db99e9cda6190f32b50ec979c722,,comment04,1,60,5,1538,1598 pr3,project1,55f445997abbd5918da59d202d28762cd56fbd44,5883,comment07,,5760,6,, pr4,project1,5ad0c09c447c19338f1dfbb65d89a3728962b3b7,11704,comment10,1500,,,, +pr5,project1,62535543802631a0d3daf0b0b78c6a7e05e508fb,13144,comment12,,313068,,, diff --git a/backend/plugins/dora/e2e/change_lead_time/pull_requests.csv b/backend/plugins/dora/e2e/change_lead_time/pull_requests.csv index fb20fbd63d6..82aced07c55 100644 --- a/backend/plugins/dora/e2e/change_lead_time/pull_requests.csv +++ b/backend/plugins/dora/e2e/change_lead_time/pull_requests.csv @@ -3,5 +3,5 @@ pr1,repo1,a,pr_merge_commit1,2023-4-11 4:51:47,2023-4-11 5:51:47,deployment_comm pr2,repo1,a,pr_merge_commit2,2023-4-12 4:51:47,2023-4-12 5:51:47,deployment_commit 5,, pr3,repo1,a,pr_merge_commit3,2023-4-11 6:53:51,2023-4-14 6:53:51,deployment_commit 6,, pr4,repo1,,pr_merge_commit4,2023-4-13 7:55:01,2023-4-13 8:55:01,,, -pr5,repo1,,pr_merge_commit5,2023-4-13 7:55:01,,,, +pr5,repo1,,pr_merge_commit5,2023-4-13 7:55:01,2023-4-13 8:55:01,,, pr6,repo1,,pr_merge_commit6,2023-4-13 7:55:01,,,, \ No newline at end of file diff --git a/backend/plugins/dora/tasks/change_lead_time_calculator.go b/backend/plugins/dora/tasks/change_lead_time_calculator.go index 93879e390f7..5ebd51e8506 100644 --- a/backend/plugins/dora/tasks/change_lead_time_calculator.go +++ b/backend/plugins/dora/tasks/change_lead_time_calculator.go @@ -206,7 +206,7 @@ func getDeploymentCommit(mergeSha string, projectName string, db dal.Dal) (*devo dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 'cicd_scopes' AND pm.row_id = dc.cicd_scope_id)"), dal.Join("INNER JOIN commits_diffs cd ON (cd.new_commit_sha = dc.commit_sha AND cd.old_commit_sha = COALESCE (p.commit_sha, ''))"), dal.Where("dc.environment = 'PRODUCTION'"), // TODO: remove this when multi-environment is supported - dal.Where("pm.project_name = ? AND cd.commit_sha = ?", projectName, mergeSha), + dal.Where("pm.project_name = ? AND cd.commit_sha = ? AND dc.RESULT = ?", projectName, mergeSha, devops.RESULT_SUCCESS), dal.Orderby("dc.started_date, dc.id ASC"), dal.Limit(1), )