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 2022/12/06 07:47:55 UTC

[incubator-devlake] branch main updated: feat: add scope for cicd in webhook (#3856)

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 2b78b55d feat: add scope for cicd in webhook (#3856)
2b78b55d is described below

commit 2b78b55da2e6e9a5bd9ca8eb5a8ab9c5e7f4ca6f
Author: Likyh <ya...@meri.co>
AuthorDate: Tue Dec 6 15:47:50 2022 +0800

    feat: add scope for cicd in webhook (#3856)
    
    * feat: add scope for cicd in webhook
    
    * fix: fix for review
---
 plugins/webhook/api/blueprint_v200.go | 49 +++++++++++++++++++++++++++++++++++
 plugins/webhook/api/cicd_pipeline.go  |  3 +++
 plugins/webhook/impl/impl.go          |  4 +++
 3 files changed, 56 insertions(+)

diff --git a/plugins/webhook/api/blueprint_v200.go b/plugins/webhook/api/blueprint_v200.go
new file mode 100644
index 00000000..7f1986af
--- /dev/null
+++ b/plugins/webhook/api/blueprint_v200.go
@@ -0,0 +1,49 @@
+/*
+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 api
+
+import (
+	"fmt"
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/models/domainlayer"
+	"github.com/apache/incubator-devlake/models/domainlayer/devops"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/webhook/models"
+)
+
+func MakeDataSourcePipelinePlanV200(connectionId uint64) (core.PipelinePlan, []core.Scope, errors.Error) {
+	// get the connection info for url
+	connection := &models.WebhookConnection{}
+	err := connectionHelper.FirstById(connection, connectionId)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	scopes := make([]core.Scope, 0, 1)
+	// add cicd_scope to scopes
+	scopes[0] = &devops.CicdScope{
+		DomainEntity: domainlayer.DomainEntity{
+			Id: fmt.Sprintf("%s:%d", "webhook", connection.ID),
+		},
+		Name: connection.Name,
+	}
+	// NOTICE:
+	//if utils.StringsContains(bpScope.Entities, core.DOMAIN_TYPE_TICKET) {}
+	// issue board will be created when post issue
+	return nil, scopes, nil
+}
diff --git a/plugins/webhook/api/cicd_pipeline.go b/plugins/webhook/api/cicd_pipeline.go
index d8727746..266db427 100644
--- a/plugins/webhook/api/cicd_pipeline.go
+++ b/plugins/webhook/api/cicd_pipeline.go
@@ -299,6 +299,7 @@ func PostDeploymentCicdTask(input *core.ApiResourceInput) (*core.ApiResourceOutp
 
 	db := basicRes.GetDal()
 	urlHash16 := fmt.Sprintf("%x", md5.Sum([]byte(request.RepoUrl)))[:16]
+	scopeId := fmt.Sprintf("%s:%d", "webhook", connection.ID)
 	pipelineId := fmt.Sprintf("%s:%d:%s:%s:%s", "webhook", connection.ID, `pipeline`, urlHash16, request.CommitSha)
 
 	taskId := fmt.Sprintf("%s:%d:%s:%s", "webhook", connection.ID, urlHash16, request.CommitSha)
@@ -312,6 +313,7 @@ func PostDeploymentCicdTask(input *core.ApiResourceInput) (*core.ApiResourceOutp
 		Status:      devops.DONE,
 		Type:        devops.DEPLOYMENT,
 		Environment: request.Environment,
+		CicdScopeId: scopeId,
 	}
 	now := time.Now()
 	if request.StartedDate != nil {
@@ -341,6 +343,7 @@ func PostDeploymentCicdTask(input *core.ApiResourceInput) (*core.ApiResourceOutp
 		FinishedDate: domainCicdTask.FinishedDate,
 		DurationSec:  domainCicdTask.DurationSec,
 		Environment:  domainCicdTask.Environment,
+		CicdScopeId:  scopeId,
 	}
 
 	domainPipelineCommit := &devops.CiCDPipelineCommit{
diff --git a/plugins/webhook/impl/impl.go b/plugins/webhook/impl/impl.go
index 372c3453..5689d676 100644
--- a/plugins/webhook/impl/impl.go
+++ b/plugins/webhook/impl/impl.go
@@ -48,6 +48,10 @@ func (plugin Webhook) GetTablesInfo() []core.Tabler {
 	return []core.Tabler{}
 }
 
+func (plugin Webhook) MakeDataSourcePipelinePlanV200(connectionId uint64, _ []*core.BlueprintScopeV200) (pp core.PipelinePlan, sc []core.Scope, err errors.Error) {
+	return api.MakeDataSourcePipelinePlanV200(connectionId)
+}
+
 // PkgPath information lost when compiled as plugin(.so)
 func (plugin Webhook) RootPkgPath() string {
 	return "github.com/apache/incubator-devlake/plugins/webhook"