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
The following commit(s) were added to refs/heads/main by this push:
new 80e532f58 fix: fix gitlab missing transformation rules (#4105)
80e532f58 is described below
commit 80e532f58cb0e398c8460ea5982b6b830b4ba2a6
Author: mindlesscloud <[email protected]>
AuthorDate: Thu Jan 5 20:33:02 2023 +0800
fix: fix gitlab missing transformation rules (#4105)
---
plugins/gitlab/api/blueprint_V200_test.go | 5 +++--
plugins/gitlab/api/blueprint_v200.go | 7 ++++++-
plugins/gitlab/impl/impl.go | 18 +++++++++---------
plugins/gitlab/tasks/issue_extractor.go | 5 ++---
plugins/gitlab/tasks/task_data.go | 8 ++++----
5 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/plugins/gitlab/api/blueprint_V200_test.go
b/plugins/gitlab/api/blueprint_V200_test.go
index 8511cdadc..122ba3ba1 100644
--- a/plugins/gitlab/api/blueprint_V200_test.go
+++ b/plugins/gitlab/api/blueprint_V200_test.go
@@ -128,8 +128,9 @@ func TestMakeDataSourcePipelinePlanV200(t *testing.T) {
tasks.ExtractApiPipelinesMeta.Name,
},
Options: map[string]interface{}{
- "connectionId": uint64(1),
- "projectId": testID,
+ "connectionId": uint64(1),
+ "projectId": testID,
+ "transformationRuleId":
testTransformationRuleId,
},
},
{
diff --git a/plugins/gitlab/api/blueprint_v200.go
b/plugins/gitlab/api/blueprint_v200.go
index 1ec1078d4..bbbd38de1 100644
--- a/plugins/gitlab/api/blueprint_v200.go
+++ b/plugins/gitlab/api/blueprint_v200.go
@@ -132,6 +132,7 @@ func makePipelinePlanV200(subtaskMetas []core.SubTaskMeta,
scopes []*core.Bluepr
options := make(map[string]interface{})
options["connectionId"] = connection.ID
options["projectId"] = intScopeId
+ options["transformationRuleId"] = transformationRules.ID
if syncPolicy.CreatedDateAfter != nil {
options["createdDateAfter"] =
syncPolicy.CreatedDateAfter.Format(time.RFC3339)
}
@@ -181,9 +182,13 @@ func makePipelinePlanV200(subtaskMetas []core.SubTaskMeta,
scopes []*core.Bluepr
// GetRepoByConnectionIdAndscopeId get tbe repo by the connectionId and the
scopeId
func GetRepoByConnectionIdAndscopeId(connectionId uint64, scopeId string)
(*models.GitlabProject, errors.Error) {
+ gitlabId, e := strconv.Atoi(scopeId)
+ if e != nil {
+ return nil, errors.Default.Wrap(e, fmt.Sprintf("scopeId %s is
not integer", scopeId))
+ }
repo := &models.GitlabProject{}
db := basicRes.GetDal()
- err := db.First(repo, dal.Where("connection_id = ? AND gitlab_id = ?",
connectionId, scopeId))
+ err := db.First(repo, dal.Where("connection_id = ? AND gitlab_id = ?",
connectionId, gitlabId))
if err != nil {
if db.IsErrorNotFound(err) {
return nil, errors.Default.Wrap(err, fmt.Sprintf("can
not find repo by connection [%d] scope [%s]", connectionId, scopeId))
diff --git a/plugins/gitlab/impl/impl.go b/plugins/gitlab/impl/impl.go
index 9f32f8d9b..d6b9b3b15 100644
--- a/plugins/gitlab/impl/impl.go
+++ b/plugins/gitlab/impl/impl.go
@@ -19,7 +19,6 @@ package impl
import (
"fmt"
- "strconv"
"time"
"github.com/apache/incubator-devlake/errors"
@@ -185,16 +184,17 @@ func (plugin Gitlab) PrepareTaskData(taskCtx
core.TaskContext, options map[strin
}
}
- if op.GitlabTransformationRule == nil && op.ProjectId != 0 {
- repo, err :=
api.GetRepoByConnectionIdAndscopeId(op.ConnectionId, strconv.Itoa(op.ProjectId))
- if err != nil {
- return nil, err
- }
- transformationRule, err := api.GetTransformationRuleByRepo(repo)
+ if op.GitlabTransformationRule == nil && op.TransformationRuleId != 0 {
+ var transformationRule models.GitlabTransformationRule
+ db := taskCtx.GetDal()
+ err = db.First(&transformationRule, dal.Where("id = ?",
op.TransformationRuleId))
if err != nil {
- return nil, err
+ if db.IsErrorNotFound(err) {
+ return nil, errors.Default.Wrap(err,
fmt.Sprintf("can not find transformationRules by transformationRuleId [%d]",
op.TransformationRuleId))
+ }
+ return nil, errors.Default.Wrap(err, fmt.Sprintf("fail
to find transformationRules by transformationRuleId [%d]",
op.TransformationRuleId))
}
- op.GitlabTransformationRule = transformationRule
+ op.GitlabTransformationRule = &transformationRule
}
taskData := tasks.GitlabTaskData{
diff --git a/plugins/gitlab/tasks/issue_extractor.go
b/plugins/gitlab/tasks/issue_extractor.go
index a8cc0d7ae..01ee2e0ac 100644
--- a/plugins/gitlab/tasks/issue_extractor.go
+++ b/plugins/gitlab/tasks/issue_extractor.go
@@ -19,12 +19,11 @@ package tasks
import (
"encoding/json"
- "github.com/apache/incubator-devlake/errors"
- "github.com/apache/incubator-devlake/models/domainlayer/ticket"
"regexp"
+ "github.com/apache/incubator-devlake/errors"
+ "github.com/apache/incubator-devlake/models/domainlayer/ticket"
"github.com/apache/incubator-devlake/plugins/core"
-
"github.com/apache/incubator-devlake/plugins/gitlab/models"
"github.com/apache/incubator-devlake/plugins/helper"
)
diff --git a/plugins/gitlab/tasks/task_data.go
b/plugins/gitlab/tasks/task_data.go
index 649bc1070..35a975bf2 100644
--- a/plugins/gitlab/tasks/task_data.go
+++ b/plugins/gitlab/tasks/task_data.go
@@ -26,10 +26,10 @@ import (
)
type GitlabOptions struct {
- ConnectionId uint64 `json:"connectionId"`
- ProjectId int `json:"projectId"`
- TransformationRuleId uint64 `json:"transformationRuleId"`
- Tasks []string `json:"tasks,omitempty"`
+ ConnectionId uint64 `mapstructure:"connectionId"
json:"connectionId"`
+ ProjectId int `mapstructure:"projectId"
json:"projectId"`
+ TransformationRuleId uint64
`mapstructure:"transformationRuleId" json:"transformationRuleId"`
+ Tasks []string `mapstructure:"tasks"
json:"tasks,omitempty"`
CreatedDateAfter string
*models.GitlabTransformationRule `mapstructure:"transformationRules"
json:"transformationRules"`
}