You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/08/04 14:39:30 UTC

[GitHub] [incubator-devlake] mappjzc opened a new pull request, #2681: feat: gitlab pipeline convert

mappjzc opened a new pull request, #2681:
URL: https://github.com/apache/incubator-devlake/pull/2681

   # Summary
   Add gitlab ConvertPipelines.
   
   <!--
   Thanks for submitting a pull request!
   
   We appreciate you spending the time to work on these changes.
   Please fill out as many sections below as possible.
   -->
   
   ### Does this close any open issues?
   #2583 
   
   ### Screenshots
   ![image](https://user-images.githubusercontent.com/2921251/182874623-c996699c-3115-4830-a890-a71d9f7f8f28.png)
   ![image](https://user-images.githubusercontent.com/2921251/182874911-e1d01d1f-a28a-4e46-a358-4f28e5617235.png)
   
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mappjzc commented on pull request #2681: feat: gitlab pipeline convert

Posted by GitBox <gi...@apache.org>.
mappjzc commented on PR #2681:
URL: https://github.com/apache/incubator-devlake/pull/2681#issuecomment-1206552859

   closed because it code move to #2682 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mappjzc closed pull request #2681: feat: gitlab pipeline convert

Posted by GitBox <gi...@apache.org>.
mappjzc closed pull request #2681: feat: gitlab pipeline convert
URL: https://github.com/apache/incubator-devlake/pull/2681


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] warren830 commented on a diff in pull request #2681: feat: gitlab pipeline convert

Posted by GitBox <gi...@apache.org>.
warren830 commented on code in PR #2681:
URL: https://github.com/apache/incubator-devlake/pull/2681#discussion_r938382781


##########
plugins/gitlab/tasks/pipeline_convertor.go:
##########
@@ -0,0 +1,107 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"fmt"
+	"reflect"
+	"time"
+
+	"github.com/apache/incubator-devlake/models/domainlayer"
+	"github.com/apache/incubator-devlake/models/domainlayer/devops"
+	"github.com/apache/incubator-devlake/models/domainlayer/didgen"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	gitlabModels "github.com/apache/incubator-devlake/plugins/gitlab/models"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ConvertPipelineMeta = core.SubTaskMeta{
+	Name:             "convertPipelines",
+	EntryPoint:       ConvertPipelines,
+	EnabledByDefault: true,
+	Description:      "Convert tool layer table gitlab_pipeline into domain layer table pipeline",
+	DomainTypes:      []string{core.DOMAIN_TYPE_CROSS},
+}
+
+func ConvertPipelines(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*GitlabTaskData)
+
+	cursor, err := db.Cursor(dal.From(gitlabModels.GitlabPipeline{}))
+	if err != nil {
+		return err
+	}
+	defer cursor.Close()
+
+	pipelineIdGen := didgen.NewDomainIdGenerator(&gitlabModels.GitlabPipeline{})
+
+	converter, err := helper.NewDataConverter(helper.DataConverterArgs{
+		InputRowType: reflect.TypeOf(gitlabModels.GitlabPipeline{}),
+		Input:        cursor,
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: GitlabApiParams{
+				ConnectionId: data.Options.ConnectionId,
+				ProjectId:    data.Options.ProjectId,
+			},
+			Table: RAW_USER_TABLE,
+		},
+		Convert: func(inputRow interface{}) ([]interface{}, error) {
+			gitlabPipeline := inputRow.(*gitlabModels.GitlabPipeline)
+
+			createdAt := time.Now()
+			if gitlabPipeline.GitlabCreatedAt != nil {
+				createdAt = *gitlabPipeline.GitlabCreatedAt
+			}
+			finishedAt := time.Now()
+			if gitlabPipeline.Status == "success" && gitlabPipeline.GitlabUpdatedAt != nil {
+				finishedAt = *gitlabPipeline.GitlabUpdatedAt
+			}
+
+			durationTime := finishedAt.Sub(createdAt)
+			domainPipeline := &devops.CICDPipeline{
+				DomainEntity: domainlayer.DomainEntity{
+					Id: pipelineIdGen.Generate(data.Options.ConnectionId, gitlabPipeline.GitlabId),
+				},
+
+				Name:      fmt.Sprintf("%d", gitlabPipeline.GitlabId),
+				CommitSha: gitlabPipeline.Sha,
+				Branch:    gitlabPipeline.Ref,
+				Repo:      fmt.Sprintf("%d", gitlabPipeline.ProjectId),
+				Result:    gitlabPipeline.Status,

Review Comment:
   after pr #2683 get merged, please modify Result and Status, these two values should be enum



##########
plugins/gitlab/tasks/pipeline_convertor.go:
##########
@@ -0,0 +1,107 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"fmt"
+	"reflect"
+	"time"
+
+	"github.com/apache/incubator-devlake/models/domainlayer"
+	"github.com/apache/incubator-devlake/models/domainlayer/devops"
+	"github.com/apache/incubator-devlake/models/domainlayer/didgen"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	gitlabModels "github.com/apache/incubator-devlake/plugins/gitlab/models"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ConvertPipelineMeta = core.SubTaskMeta{
+	Name:             "convertPipelines",
+	EntryPoint:       ConvertPipelines,
+	EnabledByDefault: true,
+	Description:      "Convert tool layer table gitlab_pipeline into domain layer table pipeline",
+	DomainTypes:      []string{core.DOMAIN_TYPE_CROSS},
+}
+
+func ConvertPipelines(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*GitlabTaskData)
+
+	cursor, err := db.Cursor(dal.From(gitlabModels.GitlabPipeline{}))
+	if err != nil {
+		return err
+	}
+	defer cursor.Close()
+
+	pipelineIdGen := didgen.NewDomainIdGenerator(&gitlabModels.GitlabPipeline{})
+
+	converter, err := helper.NewDataConverter(helper.DataConverterArgs{
+		InputRowType: reflect.TypeOf(gitlabModels.GitlabPipeline{}),
+		Input:        cursor,
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: GitlabApiParams{
+				ConnectionId: data.Options.ConnectionId,
+				ProjectId:    data.Options.ProjectId,
+			},
+			Table: RAW_USER_TABLE,
+		},
+		Convert: func(inputRow interface{}) ([]interface{}, error) {
+			gitlabPipeline := inputRow.(*gitlabModels.GitlabPipeline)
+
+			createdAt := time.Now()
+			if gitlabPipeline.GitlabCreatedAt != nil {
+				createdAt = *gitlabPipeline.GitlabCreatedAt
+			}
+			finishedAt := time.Now()

Review Comment:
   what if finishedAt should be nil?



##########
plugins/gitlab/tasks/pipeline_convertor.go:
##########
@@ -0,0 +1,107 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"fmt"
+	"reflect"
+	"time"
+
+	"github.com/apache/incubator-devlake/models/domainlayer"
+	"github.com/apache/incubator-devlake/models/domainlayer/devops"
+	"github.com/apache/incubator-devlake/models/domainlayer/didgen"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+	gitlabModels "github.com/apache/incubator-devlake/plugins/gitlab/models"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ConvertPipelineMeta = core.SubTaskMeta{
+	Name:             "convertPipelines",
+	EntryPoint:       ConvertPipelines,
+	EnabledByDefault: true,
+	Description:      "Convert tool layer table gitlab_pipeline into domain layer table pipeline",
+	DomainTypes:      []string{core.DOMAIN_TYPE_CROSS},
+}
+
+func ConvertPipelines(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDal()
+	data := taskCtx.GetData().(*GitlabTaskData)
+
+	cursor, err := db.Cursor(dal.From(gitlabModels.GitlabPipeline{}))
+	if err != nil {
+		return err
+	}
+	defer cursor.Close()
+
+	pipelineIdGen := didgen.NewDomainIdGenerator(&gitlabModels.GitlabPipeline{})
+
+	converter, err := helper.NewDataConverter(helper.DataConverterArgs{
+		InputRowType: reflect.TypeOf(gitlabModels.GitlabPipeline{}),
+		Input:        cursor,
+		RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+			Ctx: taskCtx,
+			Params: GitlabApiParams{
+				ConnectionId: data.Options.ConnectionId,
+				ProjectId:    data.Options.ProjectId,
+			},
+			Table: RAW_USER_TABLE,
+		},
+		Convert: func(inputRow interface{}) ([]interface{}, error) {
+			gitlabPipeline := inputRow.(*gitlabModels.GitlabPipeline)
+
+			createdAt := time.Now()

Review Comment:
   why not use createdDate?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org