You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2022/08/05 11:36:16 UTC

[incubator-devlake] 02/03: feat: github cicd convertor

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

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

commit af27f01a30213c0ad6a3e392eaaeb190e1b85e3a
Author: abeizn <zi...@merico.dev>
AuthorDate: Fri Aug 5 19:11:53 2022 +0800

    feat: github cicd convertor
---
 plugins/github/tasks/cicd_job_convertor.go      | 17 +++++++++--------
 plugins/github/tasks/cicd_pipeline_convertor.go | 12 +++++++-----
 plugins/github/tasks/cicd_run_enricher.go       |  2 --
 3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/plugins/github/tasks/cicd_job_convertor.go b/plugins/github/tasks/cicd_job_convertor.go
index b5318959..034a2ca7 100644
--- a/plugins/github/tasks/cicd_job_convertor.go
+++ b/plugins/github/tasks/cicd_job_convertor.go
@@ -89,7 +89,6 @@ func ConvertTasks(taskCtx core.SubTaskContext) error {
 			domainjob := &devops.CICDTask{
 				DomainEntity: domainlayer.DomainEntity{Id: jobIdGen.Generate(data.Options.ConnectionId, repoId, line.ID)},
 				Name:         line.Name,
-				Status:       line.Status,
 				Type:         line.Type,
 				StatedDate:   *line.StartedAt,
 				FinishedDate: line.CompletedAt,
@@ -97,18 +96,20 @@ func ConvertTasks(taskCtx core.SubTaskContext) error {
 			if len(tmp) > 0 {
 				domainjob.PipelineId = fmt.Sprintf("%s:%s:%d:%d:%s:%s", "github", "GithubPipeline", data.Options.ConnectionId, repoId, tmp[0].HeadBranch, line.HeadSha)
 			}
-			if line.Status == "completed" {
-				domainjob.DurationSec = uint64(line.CompletedAt.Sub(*line.StartedAt).Seconds())
-			}
+
 			if line.Conclusion == "success" {
 				domainjob.Result = devops.SUCCESS
-			} else if line.Conclusion == "cancelled" {
-				domainjob.Result = devops.ABORT
-			} else {
+			} else if line.Conclusion == "failure" || line.Conclusion == "startup_failure" {
 				domainjob.Result = devops.FAILURE
+			} else {
+				domainjob.Result = devops.ABORT
 			}
+
 			if line.Status != "completed" {
-				domainjob.Result = devops.IN_PROGRESS
+				domainjob.Status = devops.IN_PROGRESS
+			} else {
+				domainjob.Status = devops.DONE
+				domainjob.DurationSec = uint64(line.CompletedAt.Sub(*line.StartedAt).Seconds())
 			}
 
 			return []interface{}{
diff --git a/plugins/github/tasks/cicd_pipeline_convertor.go b/plugins/github/tasks/cicd_pipeline_convertor.go
index eb28abed..85b8d8bb 100644
--- a/plugins/github/tasks/cicd_pipeline_convertor.go
+++ b/plugins/github/tasks/cicd_pipeline_convertor.go
@@ -75,7 +75,6 @@ func ConvertPipelines(taskCtx core.SubTaskContext) error {
 				CommitSha:    line.Commit,
 				Branch:       line.Branch,
 				Repo:         strconv.Itoa(repoId),
-				Status:       line.Status,
 				Type:         line.Type,
 				DurationSec:  uint64(line.Duration),
 				CreatedDate:  *line.StartedDate,
@@ -83,13 +82,16 @@ func ConvertPipelines(taskCtx core.SubTaskContext) error {
 			}
 			if line.Result == "success" {
 				domainPipeline.Result = devops.SUCCESS
-			} else if line.Result == "cancelled" {
-				domainPipeline.Result = devops.ABORT
-			} else {
+			} else if line.Result == "failure" || line.Result == "startup_failure" {
 				domainPipeline.Result = devops.FAILURE
+			} else {
+				domainPipeline.Result = devops.ABORT
 			}
+
 			if line.Status != "completed" {
-				domainPipeline.Result = devops.IN_PROGRESS
+				domainPipeline.Status = devops.IN_PROGRESS
+			} else {
+				domainPipeline.Status = devops.DONE
 			}
 
 			return []interface{}{
diff --git a/plugins/github/tasks/cicd_run_enricher.go b/plugins/github/tasks/cicd_run_enricher.go
index ccd330f6..21054aaa 100644
--- a/plugins/github/tasks/cicd_run_enricher.go
+++ b/plugins/github/tasks/cicd_run_enricher.go
@@ -25,8 +25,6 @@ import (
 	githubModels "github.com/apache/incubator-devlake/plugins/github/models"
 )
 
-const TOOL_PIPELINE_TABLE = "_tool_github_pipelines"
-
 var EnrichPipelinesMeta = core.SubTaskMeta{
 	Name:             "enrichPipelines",
 	EntryPoint:       EnrichPipelines,