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

klesh 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 0cce351a0  GitHub plugin add deployments (#6151)
0cce351a0 is described below

commit 0cce351a03f1ad09a051fd2deebe4aded6a55925
Author: Lynwee <[email protected]>
AuthorDate: Sun Oct 8 11:11:41 2023 +0800

     GitHub plugin add deployments (#6151)
    
    * feat(github_graphql): add basic functions to collect deployments
    
    * docs(comments): rename PkgPath to RootPkgPath in comments
    
    * feat(github_graphql): add deployment entry
    
    * fix(github_graphql): fix ci errors
    
    * refactor(github): move GithubDeployment from github_graphql to github
    
    * feat(github): add cid_deployment_commits
    
    * refactor(github): move GithubDeployment to  migration's archived package
    
    * refactor(gitlab): remove files about deployment
---
 backend/plugins/bamboo/impl/impl.go                |   2 +-
 backend/plugins/dora/impl/impl.go                  |   2 +-
 backend/plugins/github/impl/impl.go                |   1 +
 backend/plugins/github/models/deployment.go        |  48 ++++++
 ...gister.go => 20230913_add_tool_demployments.go} |  39 ++---
 .../models/migrationscripts/archived/deployment.go |  48 ++++++
 .../github/models/migrationscripts/register.go     |   1 +
 backend/plugins/github_graphql/impl/impl.go        |  10 +-
 .../tasks/deployment_collector_extractor.go        | 173 +++++++++++++++++++++
 .../github_graphql/tasks/deployment_convertor.go   | 113 ++++++++++++++
 .../register.go => github_graphql/tasks/shared.go} |  37 ++---
 backend/plugins/icla/impl/impl.go                  |   2 +-
 backend/plugins/pagerduty/impl/impl.go             |   2 +-
 backend/plugins/refdiff/impl/impl.go               |   2 +-
 backend/plugins/sonarqube/impl/impl.go             |   2 +-
 backend/plugins/webhook/impl/impl.go               |   2 +-
 backend/plugins/zentao/impl/impl.go                |   2 +-
 17 files changed, 429 insertions(+), 57 deletions(-)

diff --git a/backend/plugins/bamboo/impl/impl.go 
b/backend/plugins/bamboo/impl/impl.go
index 529089a1e..88e2311d0 100644
--- a/backend/plugins/bamboo/impl/impl.go
+++ b/backend/plugins/bamboo/impl/impl.go
@@ -192,7 +192,7 @@ func (p Bamboo) PrepareTaskData(taskCtx plugin.TaskContext, 
options map[string]i
        }, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p Bamboo) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/bamboo"
 }
diff --git a/backend/plugins/dora/impl/impl.go 
b/backend/plugins/dora/impl/impl.go
index c456f13a4..c0d798143 100644
--- a/backend/plugins/dora/impl/impl.go
+++ b/backend/plugins/dora/impl/impl.go
@@ -107,7 +107,7 @@ func (p Dora) PrepareTaskData(taskCtx plugin.TaskContext, 
options map[string]int
        }, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p Dora) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/dora"
 }
diff --git a/backend/plugins/github/impl/impl.go 
b/backend/plugins/github/impl/impl.go
index f87dcc63c..77ac52f1d 100644
--- a/backend/plugins/github/impl/impl.go
+++ b/backend/plugins/github/impl/impl.go
@@ -103,6 +103,7 @@ func (p Github) GetTablesInfo() []dal.Tabler {
                &models.GithubRun{},
                &models.GithubIssueAssignee{},
                &models.GithubScopeConfig{},
+               &models.GithubDeployment{},
        }
 }
 
diff --git a/backend/plugins/github/models/deployment.go 
b/backend/plugins/github/models/deployment.go
new file mode 100644
index 000000000..aca83b1b6
--- /dev/null
+++ b/backend/plugins/github/models/deployment.go
@@ -0,0 +1,48 @@
+/*
+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 models
+
+import (
+       "github.com/apache/incubator-devlake/core/models/common"
+       "time"
+)
+
+type GithubDeployment struct {
+       common.NoPKModel  `json:"-" mapstructure:"-"`
+       ConnectionId      uint64    `json:"connection_id" gorm:"primaryKey"`
+       GithubId          int       `json:"github_id" gorm:"type:varchar(255)"`
+       Id                string    `json:"id" 
gorm:"type:varchar(255);primaryKey"`
+       DatabaseId        uint      `json:"database_id"`
+       CommitOid         string    `json:"commit_oid" gorm:"type:varchar(255)"`
+       Description       string    `json:"description" 
gorm:"type:varchar(255)"`
+       Environment       string    `json:"environment" 
gorm:"type:varchar(255)"`
+       State             string    `json:"state" gorm:"type:varchar(255)"`
+       LatestStatusState string    `json:"latest_status_state" 
gorm:"type:varchar(255)"`
+       LatestUpdatedDate time.Time `json:"latest_status_update_date"`
+       RepositoryID      string    `json:"repository_id" 
gorm:"type:varchar(255)"`
+       RepositoryName    string    `json:"repository_name" 
gorm:"type:varchar(255)"`
+       RepositoryUrl     string    `json:"repository_url" 
gorm:"type:varchar(255)"`
+       RefName           string    `json:"ref_name" gorm:"type:varchar(255)"`
+       Payload           string    `json:"payload" gorm:"type:text"`
+       CreatedDate       time.Time `json:"created_at"`
+       UpdatedDate       time.Time `json:"updated_at"`
+}
+
+func (GithubDeployment) TableName() string {
+       return "_tool_github_deployments"
+}
diff --git a/backend/plugins/github/models/migrationscripts/register.go 
b/backend/plugins/github/models/migrationscripts/20230913_add_tool_demployments.go
similarity index 51%
copy from backend/plugins/github/models/migrationscripts/register.go
copy to 
backend/plugins/github/models/migrationscripts/20230913_add_tool_demployments.go
index f574e72e8..82bc4c796 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ 
b/backend/plugins/github/models/migrationscripts/20230913_add_tool_demployments.go
@@ -18,30 +18,21 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       
"github.com/apache/incubator-devlake/plugins/github/models/migrationscripts/archived"
 )
 
-// All return all the migration scripts
-func All() []plugin.MigrationScript {
-       return []plugin.MigrationScript{
-               new(addInitTables),
-               new(addGithubRunsTable),
-               new(addGithubJobsTable),
-               new(addGithubPipelineTable),
-               new(deleteGithubPipelineTable),
-               new(addHeadRepoIdFieldInGithubPr),
-               new(addEnableGraphqlForConnection),
-               new(addTransformationRule20221124),
-               new(concatOwnerAndName),
-               new(addStdTypeToIssue221230),
-               new(addConnectionIdToTransformationRule),
-               new(addEnvToRunAndJob),
-               new(addGithubCommitAuthorInfo),
-               new(fixRunNameToText),
-               new(addGithubMultiAuth),
-               new(renameTr2ScopeConfig),
-               new(addGithubIssueAssignee),
-               new(addFullName),
-               new(addRawParamTableForScope),
-       }
+type addDeploymentTable struct {
+}
+
+func (*addDeploymentTable) Up(basicRes context.BasicRes) errors.Error {
+       return basicRes.GetDal().AutoMigrate(&archived.GithubDeployment{})
+}
+
+func (*addDeploymentTable) Version() uint64 {
+       return 20230913170100
+}
+func (*addDeploymentTable) Name() string {
+       return "add github deployment table"
 }
diff --git 
a/backend/plugins/github/models/migrationscripts/archived/deployment.go 
b/backend/plugins/github/models/migrationscripts/archived/deployment.go
new file mode 100644
index 000000000..a0b4f06ed
--- /dev/null
+++ b/backend/plugins/github/models/migrationscripts/archived/deployment.go
@@ -0,0 +1,48 @@
+/*
+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 archived
+
+import (
+       
"github.com/apache/incubator-devlake/core/models/migrationscripts/archived"
+       "time"
+)
+
+type GithubDeployment struct {
+       archived.NoPKModel `json:"-" mapstructure:"-"`
+       ConnectionId       uint64    `json:"connection_id" gorm:"primaryKey"`
+       GithubId           int       `json:"github_id" gorm:"type:varchar(255)"`
+       Id                 string    `json:"id" 
gorm:"type:varchar(255);primaryKey"`
+       DatabaseId         uint      `json:"database_id"`
+       CommitOid          string    `json:"commit_oid" 
gorm:"type:varchar(255)"`
+       Description        string    `json:"description" 
gorm:"type:varchar(255)"`
+       Environment        string    `json:"environment" 
gorm:"type:varchar(255)"`
+       State              string    `json:"state" gorm:"type:varchar(255)"`
+       LatestStatusState  string    `json:"latest_status_state" 
gorm:"type:varchar(255)"`
+       LatestUpdatedDate  time.Time `json:"latest_status_update_date"`
+       RepositoryID       string    `json:"repository_id" 
gorm:"type:varchar(255)"`
+       RepositoryName     string    `json:"repository_name" 
gorm:"type:varchar(255)"`
+       RepositoryUrl      string    `json:"repository_url" 
gorm:"type:varchar(255)"`
+       RefName            string    `json:"ref_name" gorm:"type:varchar(255)"`
+       Payload            string    `json:"payload" gorm:"type:text"`
+       CreatedDate        time.Time `json:"created_at"`
+       UpdatedDate        time.Time `json:"updated_at"`
+}
+
+func (GithubDeployment) TableName() string {
+       return "_tool_github_deployments"
+}
diff --git a/backend/plugins/github/models/migrationscripts/register.go 
b/backend/plugins/github/models/migrationscripts/register.go
index f574e72e8..e8dc5b0df 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ b/backend/plugins/github/models/migrationscripts/register.go
@@ -43,5 +43,6 @@ func All() []plugin.MigrationScript {
                new(addGithubIssueAssignee),
                new(addFullName),
                new(addRawParamTableForScope),
+               new(addDeploymentTable),
        }
 }
diff --git a/backend/plugins/github_graphql/impl/impl.go 
b/backend/plugins/github_graphql/impl/impl.go
index cf39093a3..a1c46d626 100644
--- a/backend/plugins/github_graphql/impl/impl.go
+++ b/backend/plugins/github_graphql/impl/impl.go
@@ -74,7 +74,9 @@ func (p GithubGraphql) Name() string {
 }
 
 func (p GithubGraphql) GetTablesInfo() []dal.Tabler {
-       return []dal.Tabler{}
+       return []dal.Tabler{
+               &models.GithubDeployment{},
+       }
 }
 
 func (p GithubGraphql) SubTaskMetas() []plugin.SubTaskMeta {
@@ -123,6 +125,10 @@ func (p GithubGraphql) SubTaskMetas() []plugin.SubTaskMeta 
{
                githubTasks.ConvertPullRequestCommentsMeta,
                githubTasks.ConvertMilestonesMeta,
                githubTasks.ConvertAccountsMeta,
+
+               // deployment
+               tasks.CollectAndExtractDeploymentMeta,
+               tasks.ConvertDeploymentMeta,
        }
 }
 
@@ -236,7 +242,7 @@ func (p GithubGraphql) PrepareTaskData(taskCtx 
plugin.TaskContext, options map[s
        return taskData, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p GithubGraphql) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/githubGraphql"
 }
diff --git 
a/backend/plugins/github_graphql/tasks/deployment_collector_extractor.go 
b/backend/plugins/github_graphql/tasks/deployment_collector_extractor.go
new file mode 100644
index 000000000..4d1bd0dec
--- /dev/null
+++ b/backend/plugins/github_graphql/tasks/deployment_collector_extractor.go
@@ -0,0 +1,173 @@
+/*
+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 (
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/models/common"
+       "github.com/apache/incubator-devlake/core/plugin"
+       helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+       githubModels "github.com/apache/incubator-devlake/plugins/github/models"
+       githubTasks "github.com/apache/incubator-devlake/plugins/github/tasks"
+       "github.com/merico-dev/graphql"
+       "strings"
+       "time"
+)
+
+var _ plugin.SubTaskEntryPoint = CollectAndExtractDeployment
+
+const (
+       RAW_DEPLOYMENT = "github_deployment"
+)
+
+var CollectAndExtractDeploymentMeta = plugin.SubTaskMeta{
+       Name:             "CollectAndExtractDeployment",
+       EntryPoint:       CollectAndExtractDeployment,
+       EnabledByDefault: true,
+       Description:      "collect and extract github deployments to raw and 
tool layer",
+       DomainTypes:      []string{plugin.DOMAIN_TYPE_CICD},
+}
+
+type GraphqlQueryDeploymentWrapper struct {
+       RateLimit struct {
+               Cost int `graphql:"cost"`
+       } `graphql:"rateLimit"`
+       Repository struct {
+               Deployments struct {
+                       TotalCount  graphql.Int                        
`graphql:"totalCount"`
+                       PageInfo    *helper.GraphqlQueryPageInfo       
`graphql:"pageInfo"`
+                       Deployments []GraphqlQueryDeploymentDeployment 
`graphql:"nodes"`
+               } `graphql:"deployments(first: $pageSize, after: $skipCursor, 
orderBy: {field: CREATED_AT, direction: DESC})"`
+       } `graphql:"repository(owner: $owner, name: $name)"`
+}
+
+type GraphqlQueryDeploymentDeployment struct {
+       Task        string `graphql:"task"` // is value always "deploy"? not 
sure.
+       Id          string `graphql:"id"`
+       CommitOid   string `graphql:"commitOid"`
+       Environment string `graphql:"environment"`
+       State       string `graphql:"state"`
+       DatabaseId  uint   `graphql:"databaseId"`
+       Description string `graphql:"description"`
+       Payload     string `graphql:"payload"`
+       Ref         *struct {
+               ID     string `graphql:"id"`
+               Name   string `graphql:"name"`
+               Prefix string `graphql:"prefix"`
+       } `graphql:"ref"`
+       LatestStatus struct {
+               Id        string    `graphql:"id"`
+               State     string    `graphql:"state"`
+               UpdatedAt time.Time `json:"updatedAt"`
+       } `graphql:"latestStatus"`
+       Repository struct {
+               Id   string `graphql:"id"`
+               Name string `graphql:"name"`
+               Url  string `graphql:"url"`
+       } `graphql:"repository"`
+       CreatedAt time.Time
+       UpdatedAt time.Time
+}
+
+// CollectAndExtractDeployment will request github api via graphql and store 
the result into raw layer by default
+// ResponseParser's return will be stored to tool layer. So it's called 
CollectorAndExtractor.
+func CollectAndExtractDeployment(taskCtx plugin.SubTaskContext) errors.Error {
+
+       data := taskCtx.GetData().(*githubTasks.GithubTaskData)
+
+       collectorWithState, err := 
helper.NewStatefulApiCollector(helper.RawDataSubTaskArgs{
+               Ctx: taskCtx,
+               Params: githubTasks.GithubApiParams{
+                       ConnectionId: data.Options.ConnectionId,
+                       Name:         data.Options.Name,
+               },
+               Table: RAW_DEPLOYMENT,
+       })
+       if err != nil {
+               return err
+       }
+
+       err = 
collectorWithState.InitGraphQLCollector(helper.GraphqlCollectorArgs{
+               GraphqlClient: data.GraphqlClient,
+               PageSize:      100,
+               BuildQuery: func(reqData *helper.GraphqlRequestData) 
(interface{}, map[string]interface{}, error) {
+                       query := &GraphqlQueryDeploymentWrapper{}
+                       variables := make(map[string]interface{})
+                       if reqData == nil {
+                               return query, variables, nil
+                       }
+                       ownerName := strings.Split(data.Options.Name, "/")
+                       variables = map[string]interface{}{
+                               "pageSize":   graphql.Int(reqData.Pager.Size),
+                               "skipCursor": 
(*graphql.String)(reqData.Pager.SkipCursor),
+                               "owner":      graphql.String(ownerName[0]),
+                               "name":       graphql.String(ownerName[1]),
+                       }
+                       return query, variables, nil
+               },
+               GetPageInfo: func(iQuery interface{}, args 
*helper.GraphqlCollectorArgs) (*helper.GraphqlQueryPageInfo, error) {
+                       query := iQuery.(*GraphqlQueryDeploymentWrapper)
+                       return query.Repository.Deployments.PageInfo, nil
+               },
+               ResponseParser: func(iQuery interface{}, variables 
map[string]interface{}) ([]interface{}, error) {
+                       query := iQuery.(*GraphqlQueryDeploymentWrapper)
+                       deployments := query.Repository.Deployments.Deployments
+                       var results []interface{}
+                       for _, deployment := range deployments {
+                               githubDeployment, err := 
convertGithubDeployment(deployment, data.Options.ConnectionId, 
data.Options.GithubId)
+                               if err != nil {
+                                       return nil, err
+                               }
+                               results = append(results, githubDeployment)
+                       }
+
+                       return results, nil
+               },
+       })
+       if err != nil {
+               return err
+       }
+
+       return collectorWithState.Execute()
+}
+
+func convertGithubDeployment(deployment GraphqlQueryDeploymentDeployment, 
connectionId uint64, githubId int) (*githubModels.GithubDeployment, error) {
+       ret := &githubModels.GithubDeployment{
+               ConnectionId:      connectionId,
+               GithubId:          githubId,
+               NoPKModel:         common.NewNoPKModel(),
+               Id:                deployment.Id,
+               DatabaseId:        deployment.DatabaseId,
+               Payload:           deployment.Payload,
+               Description:       deployment.Description,
+               CommitOid:         deployment.CommitOid,
+               Environment:       deployment.Environment,
+               State:             deployment.State,
+               RepositoryID:      deployment.Repository.Id,
+               RepositoryName:    deployment.Repository.Name,
+               RepositoryUrl:     deployment.Repository.Url,
+               CreatedDate:       deployment.CreatedAt,
+               UpdatedDate:       deployment.UpdatedAt,
+               LatestStatusState: deployment.LatestStatus.State,
+               LatestUpdatedDate: deployment.LatestStatus.UpdatedAt,
+       }
+       if deployment.Ref != nil {
+               ret.RefName = deployment.Ref.Name
+       }
+       return ret, nil
+}
diff --git a/backend/plugins/github_graphql/tasks/deployment_convertor.go 
b/backend/plugins/github_graphql/tasks/deployment_convertor.go
new file mode 100644
index 000000000..68be29d71
--- /dev/null
+++ b/backend/plugins/github_graphql/tasks/deployment_convertor.go
@@ -0,0 +1,113 @@
+/*
+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"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/models/domainlayer"
+       "github.com/apache/incubator-devlake/core/models/domainlayer/devops"
+       "github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+       githubModels "github.com/apache/incubator-devlake/plugins/github/models"
+       "reflect"
+)
+
+var _ plugin.SubTaskEntryPoint = ConvertDeployment
+
+var ConvertDeploymentMeta = plugin.SubTaskMeta{
+       Name:             "ConvertDeployment",
+       EntryPoint:       ConvertDeployment,
+       EnabledByDefault: true,
+       Description:      "Convert github deployment from tool layer to domain 
layer",
+       DomainTypes:      []string{plugin.DOMAIN_TYPE_CICD},
+}
+
+func ConvertDeployment(taskCtx plugin.SubTaskContext) errors.Error {
+       db := taskCtx.GetDal()
+       rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, 
RAW_DEPLOYMENT)
+       cursor, err := db.Cursor(
+               dal.From(&githubModels.GithubDeployment{}),
+               dal.Where("connection_id = ? and github_id = ?", 
data.Options.ConnectionId, data.Options.GithubId),
+       )
+       if err != nil {
+               return err
+       }
+       defer cursor.Close()
+
+       jobBuildIdGen := 
didgen.NewDomainIdGenerator(&githubModels.GithubDeployment{})
+
+       converter, err := api.NewDataConverter(api.DataConverterArgs{
+               InputRowType:       
reflect.TypeOf(githubModels.GithubDeployment{}),
+               Input:              cursor,
+               RawDataSubTaskArgs: *rawDataSubTaskArgs,
+               Convert: func(inputRow interface{}) ([]interface{}, 
errors.Error) {
+                       githubDeployment := 
inputRow.(*githubModels.GithubDeployment)
+                       deploymentCommit := &devops.CicdDeploymentCommit{
+                               DomainEntity: domainlayer.DomainEntity{
+                                       Id: 
jobBuildIdGen.Generate(githubDeployment.ConnectionId, githubDeployment.Id),
+                               },
+                               CicdScopeId: fmt.Sprintf("%d:%d", 
githubDeployment.ConnectionId, githubDeployment.GithubId),
+                               Name:        fmt.Sprintf("%s:%d", 
githubDeployment.RepositoryName, githubDeployment.DatabaseId), // fixme where 
does the deploy name field exist?
+                               Result: devops.GetResult(&devops.ResultRule{
+                                       Success: []string{"SUCCESS"},
+                                       Failed:  []string{"ERROR", "FAILURE"},
+                                       Abort:   []string{"QUEUED", 
"ABANDONED", "DESTROYED", "INACTIVE"},
+                                       Manual:  []string{"WAITING", "PENDING", 
"ACTIVE", "IN_PROGRESS"},
+                                       Skipped: []string{},
+                                       Default: 
githubDeployment.LatestStatusState,
+                               }, githubDeployment.State),
+                               Status: 
devops.GetStatus(&devops.StatusRule[string]{
+                                       InProgress: []string{"ACTIVE", 
"QUEUED", "IN_PROGRESS", "ABANDONED", "DESTROYED", "FAILURE", "INACTIVE"},
+                                       NotStarted: []string{"PENDING"},
+                                       Done:       []string{"SUCCESS"},
+                                       Manual:     []string{"ERROR", 
"WAITING"},
+                                       Default:    githubDeployment.State,
+                               }, githubDeployment.State),
+                               Environment:  githubDeployment.Environment,
+                               CreatedDate:  githubDeployment.CreatedDate,
+                               StartedDate:  &githubDeployment.CreatedDate, // 
fixme there is no such field
+                               FinishedDate: &githubDeployment.UpdatedDate, // 
fixme there is no such field
+                               CommitSha:    githubDeployment.CommitOid,
+                               RefName:      githubDeployment.RefName,
+                               RepoId:       githubDeployment.RepositoryID,
+                               RepoUrl:      githubDeployment.RepositoryUrl,
+                       }
+
+                       durationSec := 
uint64(githubDeployment.UpdatedDate.Sub(githubDeployment.CreatedDate).Seconds())
+                       deploymentCommit.DurationSec = &durationSec
+
+                       if data.RegexEnricher != nil {
+                               deploymentCommit.Environment = 
data.RegexEnricher.ReturnNameIfMatched(devops.PRODUCTION, 
githubDeployment.Environment)
+                       }
+
+                       return []interface{}{
+                               deploymentCommit,
+                               deploymentCommit.ToDeployment(),
+                       }, nil
+               },
+       })
+
+       if err != nil {
+               return err
+       }
+
+       return converter.Execute()
+}
diff --git a/backend/plugins/github/models/migrationscripts/register.go 
b/backend/plugins/github_graphql/tasks/shared.go
similarity index 53%
copy from backend/plugins/github/models/migrationscripts/register.go
copy to backend/plugins/github_graphql/tasks/shared.go
index f574e72e8..2c263ff62 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ b/backend/plugins/github_graphql/tasks/shared.go
@@ -15,33 +15,24 @@ See the License for the specific language governing 
permissions and
 limitations under the License.
 */
 
-package migrationscripts
+package tasks
 
 import (
        "github.com/apache/incubator-devlake/core/plugin"
+       helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+       "github.com/apache/incubator-devlake/plugins/github/models"
+       githubTasks "github.com/apache/incubator-devlake/plugins/github/tasks"
 )
 
-// All return all the migration scripts
-func All() []plugin.MigrationScript {
-       return []plugin.MigrationScript{
-               new(addInitTables),
-               new(addGithubRunsTable),
-               new(addGithubJobsTable),
-               new(addGithubPipelineTable),
-               new(deleteGithubPipelineTable),
-               new(addHeadRepoIdFieldInGithubPr),
-               new(addEnableGraphqlForConnection),
-               new(addTransformationRule20221124),
-               new(concatOwnerAndName),
-               new(addStdTypeToIssue221230),
-               new(addConnectionIdToTransformationRule),
-               new(addEnvToRunAndJob),
-               new(addGithubCommitAuthorInfo),
-               new(fixRunNameToText),
-               new(addGithubMultiAuth),
-               new(renameTr2ScopeConfig),
-               new(addGithubIssueAssignee),
-               new(addFullName),
-               new(addRawParamTableForScope),
+func CreateRawDataSubTaskArgs(taskCtx plugin.SubTaskContext, table string) 
(*helper.RawDataSubTaskArgs, *githubTasks.GithubTaskData) {
+       data := taskCtx.GetData().(*githubTasks.GithubTaskData)
+       RawDataSubTaskArgs := &helper.RawDataSubTaskArgs{
+               Ctx: taskCtx,
+               Params: models.GithubApiParams{
+                       Name:         data.Options.Name,
+                       ConnectionId: data.Options.ConnectionId,
+               },
+               Table: table,
        }
+       return RawDataSubTaskArgs, data
 }
diff --git a/backend/plugins/icla/impl/impl.go 
b/backend/plugins/icla/impl/impl.go
index 3043d8cb5..1ebd1ea2d 100644
--- a/backend/plugins/icla/impl/impl.go
+++ b/backend/plugins/icla/impl/impl.go
@@ -82,7 +82,7 @@ func (p Icla) PrepareTaskData(taskCtx plugin.TaskContext, 
options map[string]int
        }, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p Icla) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/icla"
 }
diff --git a/backend/plugins/pagerduty/impl/impl.go 
b/backend/plugins/pagerduty/impl/impl.go
index b234b296a..ef15eb9c1 100644
--- a/backend/plugins/pagerduty/impl/impl.go
+++ b/backend/plugins/pagerduty/impl/impl.go
@@ -123,7 +123,7 @@ func (p PagerDuty) PrepareTaskData(taskCtx 
plugin.TaskContext, options map[strin
        }, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p PagerDuty) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/pagerduty"
 }
diff --git a/backend/plugins/refdiff/impl/impl.go 
b/backend/plugins/refdiff/impl/impl.go
index 77dc0d55d..b5572f643 100644
--- a/backend/plugins/refdiff/impl/impl.go
+++ b/backend/plugins/refdiff/impl/impl.go
@@ -102,7 +102,7 @@ func (p RefDiff) PrepareTaskData(taskCtx 
plugin.TaskContext, options map[string]
        }, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p RefDiff) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/refdiff"
 }
diff --git a/backend/plugins/sonarqube/impl/impl.go 
b/backend/plugins/sonarqube/impl/impl.go
index 28496b180..3bf4894ae 100644
--- a/backend/plugins/sonarqube/impl/impl.go
+++ b/backend/plugins/sonarqube/impl/impl.go
@@ -153,7 +153,7 @@ func (p Sonarqube) PrepareTaskData(taskCtx 
plugin.TaskContext, options map[strin
        return taskData, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p Sonarqube) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/sonarqube"
 }
diff --git a/backend/plugins/webhook/impl/impl.go 
b/backend/plugins/webhook/impl/impl.go
index fd56f3160..9278da606 100644
--- a/backend/plugins/webhook/impl/impl.go
+++ b/backend/plugins/webhook/impl/impl.go
@@ -67,7 +67,7 @@ func (p Webhook) MakeDataSourcePipelinePlanV200(
        return api.MakeDataSourcePipelinePlanV200(connectionId)
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p Webhook) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/webhook"
 }
diff --git a/backend/plugins/zentao/impl/impl.go 
b/backend/plugins/zentao/impl/impl.go
index 9f2f760cf..9d8f0a6b6 100644
--- a/backend/plugins/zentao/impl/impl.go
+++ b/backend/plugins/zentao/impl/impl.go
@@ -230,7 +230,7 @@ func (p Zentao) PrepareTaskData(taskCtx plugin.TaskContext, 
options map[string]i
        return data, nil
 }
 
-// PkgPath information lost when compiled as plugin(.so)
+// RootPkgPath information lost when compiled as plugin(.so)
 func (p Zentao) RootPkgPath() string {
        return "github.com/apache/incubator-devlake/plugins/zentao"
 }

Reply via email to