You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by li...@apache.org on 2023/03/02 12:08:07 UTC

[incubator-devlake] branch main updated: fix: combined PrPickupTime + PrReviewTime when cal PrCycleTime (#4562)

This is an automated email from the ASF dual-hosted git repository.

likyh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 37ce39d05 fix: combined PrPickupTime + PrReviewTime when cal PrCycleTime (#4562)
37ce39d05 is described below

commit 37ce39d05ddcddcbf55366f86e502aaf0b3aa433
Author: Likyh <ya...@meri.co>
AuthorDate: Thu Mar 2 20:08:02 2023 +0800

    fix: combined PrPickupTime + PrReviewTime when cal PrCycleTime (#4562)
    
    * fix: combined PrPickupTime + PrReviewTime when cal PrCycleTime
    
    * fix: update for e2e test
---
 .../plugins/dora/e2e/snapshot_tables/project_pr_metrics.csv  | 12 ++++++------
 backend/plugins/dora/tasks/change_lead_time_calculator.go    | 11 +++++------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/backend/plugins/dora/e2e/snapshot_tables/project_pr_metrics.csv b/backend/plugins/dora/e2e/snapshot_tables/project_pr_metrics.csv
index 39eeb5648..eb02a5df1 100644
--- a/backend/plugins/dora/e2e/snapshot_tables/project_pr_metrics.csv
+++ b/backend/plugins/dora/e2e/snapshot_tables/project_pr_metrics.csv
@@ -1,7 +1,7 @@
 id,project_name,first_commit_sha,pr_coding_time,first_review_id,pr_pickup_time,pr_review_time,deployment_id,pr_deploy_time,pr_cycle_time
-github:GithubPullRequest:1:1043463302,project1,75ab753225b5b8acf3bc6e40e463b54b6800e7ed,,github:GithubPrComment:1:964527893,8558,2859,task11,93134,104551
-github:GithubPullRequest:1:1048233599,project1,4f8cdefc9a9d53af16dd482c61623312eb9e9b5e,,github:GithubPrComment:1:1239007576,194,4033,task12,76605,80832
-github:GithubPullRequest:1:1049191985,project1,4b71faf666833c0c7b915a512811e2c5e746d3de,1,github:GithubPrComment:1:965369774,156,1712,task13,115026,116895
-github:GithubPullRequest:1:1051112182,project1,,,,,,task14,98341,98341
-github:GithubPullRequest:1:1051574863,project1,,,,,,,,
-github:GithubPullRequest:1:1051637383,project1,9d53fb594958e65456793caa1bfa8d07a7614291,1,github:GithubPrReview:1:1102479199,45,13,,,59
+github:GithubPullRequest:1:1043463302,project1,75ab753225b5b8acf3bc6e40e463b54b6800e7ed,,github:GithubPrComment:1:964527893,8558,2859,task11,93134,104552
+github:GithubPullRequest:1:1048233599,project1,4f8cdefc9a9d53af16dd482c61623312eb9e9b5e,,github:GithubPrComment:1:1239007576,194,4033,task12,76605,80833
+github:GithubPullRequest:1:1049191985,project1,4b71faf666833c0c7b915a512811e2c5e746d3de,1,github:GithubPrComment:1:965369774,156,1712,task13,115026,116896
+github:GithubPullRequest:1:1051112182,project1,,,,,,task14,98341,98398
+github:GithubPullRequest:1:1051574863,project1,,,,,,,,108
+github:GithubPullRequest:1:1051637383,project1,9d53fb594958e65456793caa1bfa8d07a7614291,1,github:GithubPrReview:1:1102479199,45,13,,,60
diff --git a/backend/plugins/dora/tasks/change_lead_time_calculator.go b/backend/plugins/dora/tasks/change_lead_time_calculator.go
index a6d9b7d9b..09eaff9a0 100644
--- a/backend/plugins/dora/tasks/change_lead_time_calculator.go
+++ b/backend/plugins/dora/tasks/change_lead_time_calculator.go
@@ -35,7 +35,7 @@ func CalculateChangeLeadTime(taskCtx plugin.SubTaskContext) errors.Error {
 	data := taskCtx.GetData().(*DoraTaskData)
 	// construct a list of tuple[task, oldPipelineCommitSha, newPipelineCommitSha, taskFinishedDate]
 	deploymentClause := []dal.Clause{
-		dal.Select(`ct.id as task_id, cpc.commit_sha as new_deploy_commit_sha, 
+		dal.Select(`ct.id as task_id, cpc.commit_sha as new_deploy_commit_sha,
 			ct.finished_date as task_finished_date, cpc.repo_id as repo_id`),
 		dal.From(`cicd_tasks ct`),
 		dal.Join(`left join cicd_pipeline_commits cpc on ct.pipeline_id = cpc.pipeline_id`),
@@ -111,6 +111,8 @@ func CalculateChangeLeadTime(taskCtx plugin.SubTaskContext) errors.Error {
 			if err != nil {
 				return nil, err
 			}
+			// clauses filter by merged_date IS NOT NULL, so MergedDate must be not nil.
+			prDuring := processNegativeValue(int64(pr.MergedDate.Sub(pr.CreatedDate).Minutes()))
 			if firstReview != nil {
 				projectPrMetric.PrPickupTime = processNegativeValue(int64(firstReview.CreatedDate.Sub(pr.CreatedDate).Minutes()))
 				projectPrMetric.PrReviewTime = processNegativeValue(int64(pr.MergedDate.Sub(firstReview.CreatedDate).Minutes()))
@@ -132,11 +134,8 @@ func CalculateChangeLeadTime(taskCtx plugin.SubTaskContext) errors.Error {
 			if projectPrMetric.PrCodingTime != nil {
 				result += *projectPrMetric.PrCodingTime
 			}
-			if projectPrMetric.PrPickupTime != nil {
-				result += *projectPrMetric.PrPickupTime
-			}
-			if projectPrMetric.PrReviewTime != nil {
-				result += *projectPrMetric.PrReviewTime
+			if prDuring != nil {
+				result += *prDuring
 			}
 			if projectPrMetric.PrDeployTime != nil {
 				result += *projectPrMetric.PrDeployTime