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 a6e2a04c6 fix: add name to transformation rules (#3827)
a6e2a04c6 is described below

commit a6e2a04c6dde57ea3a6de1e27d515afe0f0cd362
Author: mindlesscloud <[email protected]>
AuthorDate: Thu Dec 1 11:54:52 2022 +0800

    fix: add name to transformation rules (#3827)
    
    * fix: add name to transformation rules
    
    * fix: fix jenkins router
    
    * fix: fix unit test
---
 plugins/github/api/blueprint_V200_test.go                 |  2 ++
 .../migrationscripts/archived/transformation_rules.go     |  1 +
 plugins/github/models/transformation_rule.go              |  1 +
 .../migrationscripts/archived/transformation_rules.go     |  1 +
 plugins/gitlab/models/transformation_rule.go              |  1 +
 plugins/jenkins/impl/impl.go                              |  2 +-
 .../migrationscripts/archived/transformation_rules.go     |  1 +
 plugins/jenkins/models/transformation_rule.go             |  1 +
 plugins/jira/api/transformation_rule.go                   | 15 +--------------
 .../migrationscripts/archived/transformation_rules.go     |  1 +
 plugins/jira/models/transformation_rules.go               |  1 +
 plugins/jira/tasks/task_data.go                           |  4 ++++
 12 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/plugins/github/api/blueprint_V200_test.go 
b/plugins/github/api/blueprint_V200_test.go
index 2798599fd..dfe9ea1c0 100644
--- a/plugins/github/api/blueprint_V200_test.go
+++ b/plugins/github/api/blueprint_V200_test.go
@@ -92,6 +92,7 @@ func TestMakeDataSourcePipelinePlanV200(t *testing.T) {
                        Model: common.Model{
                                ID: 1,
                        },
+                       Name:    "github transformation rule",
                        PrType:  "hey,man,wasup",
                        Refdiff: json.RawMessage(`{"tagsPattern": "pattern", 
"tagsLimit": 10, "tagsOrder": "reverse semver"}`),
                }
@@ -112,6 +113,7 @@ func TestMakeDataSourcePipelinePlanV200(t *testing.T) {
                                        "owner":        "test",
                                        "repo":         "testRepo",
                                        "transformationRules": 
map[string]interface{}{
+                                               "name":    "github 
transformation rule",
                                                "prType":  "hey,man,wasup",
                                                "refdiff": 
json.RawMessage(`{"tagsPattern": "pattern", "tagsLimit": 10, "tagsOrder": 
"reverse semver"}`),
                                        },
diff --git 
a/plugins/github/models/migrationscripts/archived/transformation_rules.go 
b/plugins/github/models/migrationscripts/archived/transformation_rules.go
index e6f12875b..d2b137628 100644
--- a/plugins/github/models/migrationscripts/archived/transformation_rules.go
+++ b/plugins/github/models/migrationscripts/archived/transformation_rules.go
@@ -25,6 +25,7 @@ import (
 
 type TransformationRules struct {
        archived.Model
+       Name                 string          `mapstructure:"name" json:"name" 
gorm:"type:varchar(255)"`
        PrType               string          `mapstructure:"prType" 
json:"prType" gorm:"type:varchar(255)"`
        PrComponent          string          `mapstructure:"prComponent" 
json:"prComponent" gorm:"type:varchar(255)"`
        PrBodyClosePattern   string          `mapstructure:"prBodyClosePattern" 
json:"prBodyClosePattern" gorm:"type:varchar(255)"`
diff --git a/plugins/github/models/transformation_rule.go 
b/plugins/github/models/transformation_rule.go
index c218e4a66..5862556d3 100644
--- a/plugins/github/models/transformation_rule.go
+++ b/plugins/github/models/transformation_rule.go
@@ -25,6 +25,7 @@ import (
 
 type TransformationRules struct {
        common.Model         `mapstructure:"-"`
+       Name                 string          `mapstructure:"name" json:"name" 
gorm:"type:varchar(255)"`
        PrType               string          `mapstructure:"prType,omitempty" 
json:"prType" gorm:"type:varchar(255)"`
        PrComponent          string          
`mapstructure:"prComponent,omitempty" json:"prComponent" 
gorm:"type:varchar(255)"`
        PrBodyClosePattern   string          
`mapstructure:"prBodyClosePattern,omitempty" json:"prBodyClosePattern" 
gorm:"type:varchar(255)"`
diff --git 
a/plugins/gitlab/models/migrationscripts/archived/transformation_rules.go 
b/plugins/gitlab/models/migrationscripts/archived/transformation_rules.go
index aa0616697..1c6d3e6d1 100644
--- a/plugins/gitlab/models/migrationscripts/archived/transformation_rules.go
+++ b/plugins/gitlab/models/migrationscripts/archived/transformation_rules.go
@@ -23,6 +23,7 @@ import (
 
 type TransformationRules struct {
        archived.Model
+       Name                 string `gorm:"type:varchar(255)"`
        PrType               string `mapstructure:"prType" json:"prType" 
gorm:"type:varchar(255)"`
        PrComponent          string `mapstructure:"prComponent" 
json:"prComponent" gorm:"type:varchar(255)"`
        PrBodyClosePattern   string `mapstructure:"prBodyClosePattern" 
json:"prBodyClosePattern" gorm:"type:varchar(255)"`
diff --git a/plugins/gitlab/models/transformation_rule.go 
b/plugins/gitlab/models/transformation_rule.go
index b65706079..58f09633e 100644
--- a/plugins/gitlab/models/transformation_rule.go
+++ b/plugins/gitlab/models/transformation_rule.go
@@ -21,6 +21,7 @@ import "github.com/apache/incubator-devlake/models/common"
 
 type TransformationRules struct {
        common.Model
+       Name                 string `gorm:"type:varchar(255)"`
        PrType               string `mapstructure:"prType" json:"prType"`
        PrComponent          string `mapstructure:"prComponent" 
json:"prComponent"`
        PrBodyClosePattern   string `mapstructure:"prBodyClosePattern" 
json:"prBodyClosePattern"`
diff --git a/plugins/jenkins/impl/impl.go b/plugins/jenkins/impl/impl.go
index 5a1dca84b..b442a1302 100644
--- a/plugins/jenkins/impl/impl.go
+++ b/plugins/jenkins/impl/impl.go
@@ -164,7 +164,7 @@ func (plugin Jenkins) ApiResources() 
map[string]map[string]core.ApiResourceHandl
                        "DELETE": api.DeleteConnection,
                        "GET":    api.GetConnection,
                },
-               "connections/:connectionId/scopes/*fullName": {
+               "connections/:connectionId/scopes/:fullName": {
                        "GET":   api.GetScope,
                        "PUT":   api.PutScope,
                        "PATCH": api.UpdateScope,
diff --git 
a/plugins/jenkins/models/migrationscripts/archived/transformation_rules.go 
b/plugins/jenkins/models/migrationscripts/archived/transformation_rules.go
index 689723d53..9818e3dc7 100644
--- a/plugins/jenkins/models/migrationscripts/archived/transformation_rules.go
+++ b/plugins/jenkins/models/migrationscripts/archived/transformation_rules.go
@@ -23,6 +23,7 @@ import (
 
 type TransformationRules struct {
        archived.Model
+       Name              string `gorm:"type:varchar(255)"`
        DeploymentPattern string `gorm:"type:varchar(255)" 
mapstructure:"deploymentPattern" json:"deploymentPattern"`
 }
 
diff --git a/plugins/jenkins/models/transformation_rule.go 
b/plugins/jenkins/models/transformation_rule.go
index aa99f458a..18f83466a 100644
--- a/plugins/jenkins/models/transformation_rule.go
+++ b/plugins/jenkins/models/transformation_rule.go
@@ -21,6 +21,7 @@ import "github.com/apache/incubator-devlake/models/common"
 
 type TransformationRules struct {
        common.Model
+       Name              string `gorm:"type:varchar(255)"`
        DeploymentPattern string `gorm:"type:varchar(255)" 
mapstructure:"deploymentPattern" json:"deploymentPattern"`
 }
 
diff --git a/plugins/jira/api/transformation_rule.go 
b/plugins/jira/api/transformation_rule.go
index 013d5098e..65a51f0ef 100644
--- a/plugins/jira/api/transformation_rule.go
+++ b/plugins/jira/api/transformation_rule.go
@@ -18,7 +18,6 @@ limitations under the License.
 package api
 
 import (
-       "encoding/json"
        "net/http"
        "strconv"
 
@@ -92,19 +91,7 @@ func makeDbTransformationRuleFromInput(input 
*core.ApiResourceInput) (*models.Ji
        if err != nil {
                return nil, errors.Default.Wrap(err, "error decoding map into 
transformationRule")
        }
-       return makeDbTransformationRule(&req)
-}
-func makeDbTransformationRule(rule *tasks.TransformationRules) 
(*models.JiraTransformationRule, errors.Error) {
-       blob, err := json.Marshal(rule.TypeMappings)
-       if err != nil {
-               return nil, errors.Default.Wrap(err, "error marshaling 
TypeMappings")
-       }
-       return &models.JiraTransformationRule{
-               EpicKeyField:               rule.EpicKeyField,
-               StoryPointField:            rule.StoryPointField,
-               RemotelinkCommitShaPattern: rule.RemotelinkCommitShaPattern,
-               TypeMappings:               blob,
-       }, nil
+       return req.ToDb()
 }
 
 // GetTransformationRule return one transformation rule
diff --git 
a/plugins/jira/models/migrationscripts/archived/transformation_rules.go 
b/plugins/jira/models/migrationscripts/archived/transformation_rules.go
index c0d59d75a..fab95a991 100644
--- a/plugins/jira/models/migrationscripts/archived/transformation_rules.go
+++ b/plugins/jira/models/migrationscripts/archived/transformation_rules.go
@@ -25,6 +25,7 @@ import (
 
 type JiraTransformationRule struct {
        archived.Model
+       Name                       string          `gorm:"type:varchar(255)"`
        EpicKeyField               string          `json:"epicKeyField" 
gorm:"type:varchar(255)"`
        StoryPointField            string          `json:"storyPointField" 
gorm:"type:varchar(255)"`
        RemotelinkCommitShaPattern string          
`json:"remotelinkCommitShaPattern" gorm:"type:varchar(255)"`
diff --git a/plugins/jira/models/transformation_rules.go 
b/plugins/jira/models/transformation_rules.go
index 998290e82..0c10f5df2 100644
--- a/plugins/jira/models/transformation_rules.go
+++ b/plugins/jira/models/transformation_rules.go
@@ -25,6 +25,7 @@ import (
 
 type JiraTransformationRule struct {
        common.Model
+       Name                       string          `gorm:"type:varchar(255)"`
        EpicKeyField               string          `json:"epicKeyField" 
gorm:"type:varchar(255)"`
        StoryPointField            string          `json:"storyPointField" 
gorm:"type:varchar(255)"`
        RemotelinkCommitShaPattern string          
`json:"remotelinkCommitShaPattern" gorm:"type:varchar(255)"`
diff --git a/plugins/jira/tasks/task_data.go b/plugins/jira/tasks/task_data.go
index 4ee28ffbd..d1dec33b5 100644
--- a/plugins/jira/tasks/task_data.go
+++ b/plugins/jira/tasks/task_data.go
@@ -41,6 +41,7 @@ type TypeMapping struct {
 type TypeMappings map[string]TypeMapping
 
 type TransformationRules struct {
+       Name                       string       `gorm:"type:varchar(255)"`
        EpicKeyField               string       `json:"epicKeyField"`
        StoryPointField            string       `json:"storyPointField"`
        RemotelinkCommitShaPattern string       
`json:"remotelinkCommitShaPattern"`
@@ -53,6 +54,7 @@ func (r *TransformationRules) ToDb() (rule 
*models.JiraTransformationRule, error
                return nil, errors.Default.Wrap(err, "error marshaling 
TypeMappings")
        }
        return &models.JiraTransformationRule{
+               Name:                       r.Name,
                EpicKeyField:               r.EpicKeyField,
                StoryPointField:            r.StoryPointField,
                RemotelinkCommitShaPattern: r.RemotelinkCommitShaPattern,
@@ -65,6 +67,7 @@ func (r *TransformationRules) FromDb(rule 
*models.JiraTransformationRule) (*Tran
        if err != nil {
                return nil, errors.Default.Wrap(err, "error marshaling 
TypeMappings")
        }
+       r.Name = rule.Name
        r.EpicKeyField = rule.EpicKeyField
        r.StoryPointField = rule.StoryPointField
        r.RemotelinkCommitShaPattern = rule.RemotelinkCommitShaPattern
@@ -79,6 +82,7 @@ func MakeTransformationRules(rule 
models.JiraTransformationRule) (*Transformatio
                return nil, errors.Default.Wrap(err, "unable to unmarshal the 
typeMapping")
        }
        result := &TransformationRules{
+               Name:                       rule.Name,
                EpicKeyField:               rule.EpicKeyField,
                StoryPointField:            rule.StoryPointField,
                RemotelinkCommitShaPattern: rule.RemotelinkCommitShaPattern,

Reply via email to