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

mintsweet 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 a44656bbf refactor: rename transformation rule to scope config - 
pagerduty (#5326)
a44656bbf is described below

commit a44656bbfe9bd51dd1d28f139d98026f66430b0d
Author: Klesh Wong <[email protected]>
AuthorDate: Wed May 31 15:18:52 2023 +0800

    refactor: rename transformation rule to scope config - pagerduty (#5326)
---
 .../helpers/pluginhelper/api/mapstructure_test.go  | 24 ++++++-
 .../pluginhelper/api/scope_config_helper.go        |  2 +-
 backend/helpers/pluginhelper/api/scope_helper.go   |  3 +-
 backend/plugins/pagerduty/api/blueprint.go         | 65 ------------------
 backend/plugins/pagerduty/api/blueprint_v200.go    | 24 ++++---
 backend/plugins/pagerduty/api/init.go              | 10 +--
 backend/plugins/pagerduty/api/remote.go            | 15 ++--
 backend/plugins/pagerduty/api/scope_config.go      | 79 ++++++++++++++++++++++
 .../transformation_rules.go => api/swagger.go}     | 20 +++---
 .../plugins/pagerduty/api/transformation_rules.go  | 79 ----------------------
 backend/plugins/pagerduty/e2e/incident_test.go     | 29 ++++----
 backend/plugins/pagerduty/impl/impl.go             | 18 ++---
 .../migrationscripts/20230531_scope_config.go      | 56 +++++++++++++++
 .../models/migrationscripts/archived/service.go    |  2 +-
 .../models/migrationscripts/archived/user.go       |  2 +-
 .../pagerduty/models/migrationscripts/register.go  |  1 +
 .../{transformation_rules.go => scope_config.go}   | 12 ++--
 backend/plugins/pagerduty/models/service.go        | 10 +--
 backend/plugins/pagerduty/models/user.go           |  2 +-
 backend/plugins/pagerduty/tasks/task_data.go       |  5 +-
 20 files changed, 240 insertions(+), 218 deletions(-)

diff --git a/backend/helpers/pluginhelper/api/mapstructure_test.go 
b/backend/helpers/pluginhelper/api/mapstructure_test.go
index ff02761a8..ac2f10668 100644
--- a/backend/helpers/pluginhelper/api/mapstructure_test.go
+++ b/backend/helpers/pluginhelper/api/mapstructure_test.go
@@ -20,9 +20,10 @@ package api
 import (
        "encoding/json"
        "fmt"
-       "github.com/apache/incubator-devlake/core/errors"
        "testing"
 
+       "github.com/apache/incubator-devlake/core/errors"
+
        "github.com/stretchr/testify/assert"
 )
 
@@ -57,3 +58,24 @@ func TestDecodeMapStructJsonRawMessage(t *testing.T) {
        assert.Equal(t, settings["version"], "1.0.0")
        assert.Equal(t, decoded.Existing, json.RawMessage(`{"hello", "world"}`))
 }
+
+type StringSliceField struct {
+       Entities []string `gorm:"type:json;serializer:json" 
mapstructure:"entities"`
+}
+
+func TestStringSliceFieldShouldBeOverwrited(t *testing.T) {
+       decoded := &StringSliceField{
+               Entities: []string{"hello", "world"},
+       }
+       input := map[string]interface{}{
+               "entities": []string{"foo"},
+       }
+       err := DecodeMapStruct(input, decoded, true)
+       assert.Nil(t, err)
+       assert.Equal(t, decoded.Entities, []string{"foo"})
+
+       input = map[string]interface{}{}
+       err = DecodeMapStruct(input, decoded, true)
+       assert.Nil(t, err)
+       assert.Equal(t, decoded.Entities, []string{"foo"})
+}
diff --git a/backend/helpers/pluginhelper/api/scope_config_helper.go 
b/backend/helpers/pluginhelper/api/scope_config_helper.go
index f2ad2d004..4425091ad 100644
--- a/backend/helpers/pluginhelper/api/scope_config_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_config_helper.go
@@ -90,7 +90,7 @@ func (t ScopeConfigHelper[Tr]) Update(input 
*plugin.ApiResourceInput) (*plugin.A
        if err != nil {
                return nil, errors.Default.Wrap(err, "error on saving 
ScopeConfig")
        }
-       err = DecodeMapStruct(input.Body, &old, false)
+       err = DecodeMapStruct(input.Body, &old, true)
        if err != nil {
                return nil, errors.Default.Wrap(err, "error decoding map into 
scopeConfig")
        }
diff --git a/backend/helpers/pluginhelper/api/scope_helper.go 
b/backend/helpers/pluginhelper/api/scope_helper.go
index d5f79a7d5..c26c661df 100644
--- a/backend/helpers/pluginhelper/api/scope_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_helper.go
@@ -18,11 +18,12 @@ limitations under the License.
 package api
 
 import (
+       "net/http"
+
        "github.com/apache/incubator-devlake/core/context"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/go-playground/validator/v10"
-       "net/http"
 )
 
 type (
diff --git a/backend/plugins/pagerduty/api/blueprint.go 
b/backend/plugins/pagerduty/api/blueprint.go
deleted file mode 100644
index a0235d70d..000000000
--- a/backend/plugins/pagerduty/api/blueprint.go
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-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 (
-       "encoding/json"
-       "github.com/apache/incubator-devlake/core/errors"
-       "github.com/apache/incubator-devlake/core/plugin"
-       "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
-       "github.com/apache/incubator-devlake/plugins/pagerduty/models"
-       "github.com/apache/incubator-devlake/plugins/pagerduty/tasks"
-)
-
-func MakePipelinePlan(subtaskMetas []plugin.SubTaskMeta, connectionId uint64, 
scope []*plugin.BlueprintScopeV100) (plugin.PipelinePlan, errors.Error) {
-       var err errors.Error
-       plan := make(plugin.PipelinePlan, len(scope))
-       for i, scopeElem := range scope {
-               taskOptions := make(map[string]interface{})
-               err = errors.Convert(json.Unmarshal(scopeElem.Options, 
&taskOptions))
-               if err != nil {
-                       return nil, errors.Default.Wrap(err, "error 
unmarshalling task options")
-               }
-               var transformationRules models.PagerdutyTransformationRule
-               if len(scopeElem.Transformation) > 0 {
-                       err = 
errors.Convert(json.Unmarshal(scopeElem.Transformation, &transformationRules))
-                       if err != nil {
-                               return nil, errors.Default.Wrap(err, "unable to 
unmarshal transformation rule")
-                       }
-               }
-               taskOptions["connectionId"] = connectionId
-               taskOptions["transformationRules"] = transformationRules
-               _, err = tasks.DecodeAndValidateTaskOptions(taskOptions)
-               if err != nil {
-                       return nil, err
-               }
-               // subtasks
-               subtasks, err := api.MakePipelinePlanSubtasks(subtaskMetas, 
scopeElem.Entities)
-               if err != nil {
-                       return nil, err
-               }
-               plan[i] = plugin.PipelineStage{
-                       {
-                               Plugin:   "pagerduty",
-                               Subtasks: subtasks,
-                               Options:  taskOptions,
-                       },
-               }
-       }
-       return plan, nil
-}
diff --git a/backend/plugins/pagerduty/api/blueprint_v200.go 
b/backend/plugins/pagerduty/api/blueprint_v200.go
index 8c257cb4d..f45f55109 100644
--- a/backend/plugins/pagerduty/api/blueprint_v200.go
+++ b/backend/plugins/pagerduty/api/blueprint_v200.go
@@ -19,6 +19,8 @@ package api
 
 import (
        "fmt"
+       "time"
+
        "github.com/apache/incubator-devlake/core/dal"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/models/domainlayer"
@@ -30,7 +32,6 @@ import (
        "github.com/apache/incubator-devlake/plugins/pagerduty/models"
        "github.com/apache/incubator-devlake/plugins/pagerduty/tasks"
        "github.com/go-playground/validator/v10"
-       "time"
 )
 
 func MakeDataSourcePipelinePlanV200(subtaskMetas []plugin.SubTaskMeta, 
connectionId uint64, bpScopes []*plugin.BlueprintScopeV200, syncPolicy 
*plugin.BlueprintSyncPolicy,
@@ -71,10 +72,10 @@ func makeDataSourcePipelinePlanV200(
                if err != nil {
                        return nil, errors.Default.Wrap(err, fmt.Sprintf("fail 
to find service %s", bpScope.Id))
                }
-               transformationRule := &models.PagerdutyTransformationRule{}
-               // get transformation rules from db
+               scopeConfig := &models.PagerdutyScopeConfig{}
+               // get scope configs from db
                db := basicRes.GetDal()
-               err = db.First(transformationRule, dal.Where(`id = ?`, 
service.TransformationRuleId))
+               err = db.First(scopeConfig, dal.Where(`id = ?`, 
service.ScopeConfigId))
                if err != nil && !db.IsErrorNotFound(err) {
                        return nil, err
                }
@@ -93,7 +94,7 @@ func makeDataSourcePipelinePlanV200(
                        return nil, err
                }
                var subtasks []string
-               subtasks, err = api.MakePipelinePlanSubtasks(subtaskMetas, 
bpScope.Entities)
+               subtasks, err = api.MakePipelinePlanSubtasks(subtaskMetas, 
scopeConfig.Entities)
                if err != nil {
                        return nil, err
                }
@@ -112,14 +113,21 @@ func makeDataSourcePipelinePlanV200(
 func makeScopesV200(bpScopes []*plugin.BlueprintScopeV200, connection 
*models.PagerDutyConnection) ([]plugin.Scope, errors.Error) {
        scopes := make([]plugin.Scope, 0)
        for _, bpScope := range bpScopes {
-               service := &models.Service{}
+               db := basicRes.GetDal()
                // get service from db
-               err := basicRes.GetDal().First(service, 
dal.Where(`connection_id = ? AND id = ?`, connection.ID, bpScope.Id))
+               service := &models.Service{}
+               err := db.First(service, dal.Where(`connection_id = ? AND id = 
?`, connection.ID, bpScope.Id))
                if err != nil {
                        return nil, errors.Default.Wrap(err, 
fmt.Sprintf("failed to find service: %s", bpScope.Id))
                }
+               // get scope configs from db
+               scopeConfig := &models.PagerdutyScopeConfig{}
+               err = db.First(scopeConfig, dal.Where(`id = ?`, 
service.ScopeConfigId))
+               if err != nil && !db.IsErrorNotFound(err) {
+                       return nil, err
+               }
                // add board to scopes
-               if utils.StringsContains(bpScope.Entities, 
plugin.DOMAIN_TYPE_TICKET) {
+               if utils.StringsContains(scopeConfig.Entities, 
plugin.DOMAIN_TYPE_TICKET) {
                        scopeTicket := &ticket.Board{
                                DomainEntity: domainlayer.DomainEntity{
                                        Id: 
didgen.NewDomainIdGenerator(&models.Service{}).Generate(connection.ID, 
service.Id),
diff --git a/backend/plugins/pagerduty/api/init.go 
b/backend/plugins/pagerduty/api/init.go
index 84729850c..18b66be6d 100644
--- a/backend/plugins/pagerduty/api/init.go
+++ b/backend/plugins/pagerduty/api/init.go
@@ -27,9 +27,9 @@ import (
 var vld *validator.Validate
 var connectionHelper *api.ConnectionApiHelper
 
-var scopeHelper *api.ScopeApiHelper[models.PagerDutyConnection, 
models.Service, models.PagerdutyTransformationRule]
+var scopeHelper *api.ScopeApiHelper[models.PagerDutyConnection, 
models.Service, models.PagerdutyScopeConfig]
 
-var trHelper *api.TransformationRuleHelper[models.PagerdutyTransformationRule]
+var scHelper *api.ScopeConfigHelper[models.PagerdutyScopeConfig]
 var basicRes context.BasicRes
 
 func Init(br context.BasicRes) {
@@ -44,16 +44,16 @@ func Init(br context.BasicRes) {
                ScopeIdColumnName: "id",
                RawScopeParamName: "ScopeId",
        }
-       scopeHelper = api.NewScopeHelper[models.PagerDutyConnection, 
models.Service, models.PagerdutyTransformationRule](
+       scopeHelper = api.NewScopeHelper[models.PagerDutyConnection, 
models.Service, models.PagerdutyScopeConfig](
                basicRes,
                vld,
                connectionHelper,
-               api.NewScopeDatabaseHelperImpl[models.PagerDutyConnection, 
models.Service, models.PagerdutyTransformationRule](
+               api.NewScopeDatabaseHelperImpl[models.PagerDutyConnection, 
models.Service, models.PagerdutyScopeConfig](
                        basicRes, connectionHelper, params),
                params,
                &api.ScopeHelperOptions{},
        )
-       trHelper = 
api.NewTransformationRuleHelper[models.PagerdutyTransformationRule](
+       scHelper = api.NewScopeConfigHelper[models.PagerdutyScopeConfig](
                basicRes,
                vld,
        )
diff --git a/backend/plugins/pagerduty/api/remote.go 
b/backend/plugins/pagerduty/api/remote.go
index ea2ceefad..f592bda2e 100644
--- a/backend/plugins/pagerduty/api/remote.go
+++ b/backend/plugins/pagerduty/api/remote.go
@@ -22,14 +22,15 @@ import (
        "encoding/base64"
        "encoding/json"
        "fmt"
+       "net/http"
+       "net/url"
+       "strconv"
+
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
        "github.com/apache/incubator-devlake/plugins/pagerduty/models"
        "github.com/apache/incubator-devlake/plugins/pagerduty/models/raw"
-       "net/http"
-       "net/url"
-       "strconv"
 )
 
 type RemoteScopesChild struct {
@@ -130,10 +131,10 @@ func RemoteScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, er
                        Id:   service.Id,
                        Name: service.Name,
                        Data: models.Service{
-                               Url:                  service.HtmlUrl,
-                               Id:                   service.Id,
-                               TransformationRuleId: 0, // this is not 
determined here
-                               Name:                 service.Name,
+                               Url:           service.HtmlUrl,
+                               Id:            service.Id,
+                               ScopeConfigId: 0, // this is not determined here
+                               Name:          service.Name,
                        },
                }
                outputBody.Children = append(outputBody.Children, child)
diff --git a/backend/plugins/pagerduty/api/scope_config.go 
b/backend/plugins/pagerduty/api/scope_config.go
new file mode 100644
index 000000000..2d91e074e
--- /dev/null
+++ b/backend/plugins/pagerduty/api/scope_config.go
@@ -0,0 +1,79 @@
+/*
+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 (
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+)
+
+// CreateScopeConfig create scope config for PagerDuty
+// @Summary create scope config for PagerDuty
+// @Description create scope config for PagerDuty
+// @Tags plugins/pagerduty
+// @Accept application/json
+// @Param scopeConfig body models.PagerdutyScopeConfig true "scope config"
+// @Success 200  {object} models.PagerdutyScopeConfig
+// @Failure 400  {object} shared.ApiBody "Bad Request"
+// @Failure 500  {object} shared.ApiBody "Internal Error"
+// @Router /plugins/pagerduty/connections/:connectionId/scope_configs [POST]
+func CreateScopeConfig(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       return scHelper.Create(input)
+}
+
+// UpdateScopeConfig update scope config for Github
+// @Summary update scope config for Github
+// @Description update scope config for Github
+// @Tags plugins/pagerduty
+// @Accept application/json
+// @Param id path int true "id"
+// @Param scopeConfig body models.PagerdutyScopeConfig true "scope config"
+// @Success 200  {object} models.PagerdutyScopeConfig
+// @Failure 400  {object} shared.ApiBody "Bad Request"
+// @Failure 500  {object} shared.ApiBody "Internal Error"
+// @Router /plugins/pagerduty/connections/:connectionId/scope_configs/{id} 
[PATCH]
+func UpdateScopeConfig(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       return scHelper.Update(input)
+}
+
+// GetScopeConfig return one scope config
+// @Summary return one scope config
+// @Description return one scope config
+// @Tags plugins/pagerduty
+// @Param id path int true "id"
+// @Success 200  {object} models.PagerdutyScopeConfig
+// @Failure 400  {object} shared.ApiBody "Bad Request"
+// @Failure 500  {object} shared.ApiBody "Internal Error"
+// @Router /plugins/pagerduty/connections/:connectionId/scope_configs/{id} 
[GET]
+func GetScopeConfig(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       return scHelper.Get(input)
+}
+
+// GetScopeConfigList return all scope configs
+// @Summary return all scope configs
+// @Description return all scope configs
+// @Tags plugins/pagerduty
+// @Param pageSize query int false "page size, default 50"
+// @Param page query int false "page size, default 1"
+// @Success 200  {object} []models.PagerdutyScopeConfig
+// @Failure 400  {object} shared.ApiBody "Bad Request"
+// @Failure 500  {object} shared.ApiBody "Internal Error"
+// @Router /plugins/pagerduty/connections/:connectionId/scope_configs [GET]
+func GetScopeConfigList(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       return scHelper.List(input)
+}
diff --git a/backend/plugins/pagerduty/models/transformation_rules.go 
b/backend/plugins/pagerduty/api/swagger.go
similarity index 63%
copy from backend/plugins/pagerduty/models/transformation_rules.go
copy to backend/plugins/pagerduty/api/swagger.go
index 6d83916ac..3d8f2a554 100644
--- a/backend/plugins/pagerduty/models/transformation_rules.go
+++ b/backend/plugins/pagerduty/api/swagger.go
@@ -15,18 +15,18 @@ See the License for the specific language governing 
permissions and
 limitations under the License.
 */
 
-package models
+package api
 
 import (
-       "github.com/apache/incubator-devlake/core/models/common"
+       "github.com/apache/incubator-devlake/plugins/pagerduty/tasks"
 )
 
-type PagerdutyTransformationRule struct {
-       common.Model `mapstructure:"-"`
-       Name         string `mapstructure:"name" json:"name" 
gorm:"type:varchar(255);index:idx_name_github,unique" validate:"required"`
-       ConnectionId uint64
-}
+type PagerdutyTaskOptions tasks.PagerDutyOptions
 
-func (PagerdutyTransformationRule) TableName() string {
-       return "_tool_pagerduty_transformation_rules"
-}
+// @Summary pagerduty task options for pipelines
+// @Description This is a dummy API to demonstrate the available task options 
for pagerduty pipelines
+// @Tags plugins/pagerduty
+// @Accept application/json
+// @Param pipeline body PagerDutyTaskOptions true "json"
+// @Router /pipelines/pagerduty/pipeline-task [post]
+func _() {}
diff --git a/backend/plugins/pagerduty/api/transformation_rules.go 
b/backend/plugins/pagerduty/api/transformation_rules.go
deleted file mode 100644
index 860f0c490..000000000
--- a/backend/plugins/pagerduty/api/transformation_rules.go
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
-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 (
-       "github.com/apache/incubator-devlake/core/errors"
-       "github.com/apache/incubator-devlake/core/plugin"
-)
-
-// CreateTransformationRule create transformation rule for PagerDuty
-// @Summary create transformation rule for PagerDuty
-// @Description create transformation rule for PagerDuty
-// @Tags plugins/pagerduty
-// @Accept application/json
-// @Param transformationRule body models.PagerdutyTransformationRule true 
"transformation rule"
-// @Success 200  {object} models.PagerdutyTransformationRule
-// @Failure 400  {object} shared.ApiBody "Bad Request"
-// @Failure 500  {object} shared.ApiBody "Internal Error"
-// @Router /plugins/pagerduty/connections/:connectionId/transformation_rules 
[POST]
-func CreateTransformationRule(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
-       return trHelper.Create(input)
-}
-
-// UpdateTransformationRule update transformation rule for Github
-// @Summary update transformation rule for Github
-// @Description update transformation rule for Github
-// @Tags plugins/pagerduty
-// @Accept application/json
-// @Param id path int true "id"
-// @Param transformationRule body models.PagerdutyTransformationRule true 
"transformation rule"
-// @Success 200  {object} models.PagerdutyTransformationRule
-// @Failure 400  {object} shared.ApiBody "Bad Request"
-// @Failure 500  {object} shared.ApiBody "Internal Error"
-// @Router 
/plugins/pagerduty/connections/:connectionId/transformation_rules/{id} [PATCH]
-func UpdateTransformationRule(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
-       return trHelper.Update(input)
-}
-
-// GetTransformationRule return one transformation rule
-// @Summary return one transformation rule
-// @Description return one transformation rule
-// @Tags plugins/pagerduty
-// @Param id path int true "id"
-// @Success 200  {object} models.PagerdutyTransformationRule
-// @Failure 400  {object} shared.ApiBody "Bad Request"
-// @Failure 500  {object} shared.ApiBody "Internal Error"
-// @Router 
/plugins/pagerduty/connections/:connectionId/transformation_rules/{id} [GET]
-func GetTransformationRule(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
-       return trHelper.Get(input)
-}
-
-// GetTransformationRuleList return all transformation rules
-// @Summary return all transformation rules
-// @Description return all transformation rules
-// @Tags plugins/pagerduty
-// @Param pageSize query int false "page size, default 50"
-// @Param page query int false "page size, default 1"
-// @Success 200  {object} []models.PagerdutyTransformationRule
-// @Failure 400  {object} shared.ApiBody "Bad Request"
-// @Failure 500  {object} shared.ApiBody "Internal Error"
-// @Router /plugins/pagerduty/connections/:connectionId/transformation_rules 
[GET]
-func GetTransformationRuleList(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
-       return trHelper.List(input)
-}
diff --git a/backend/plugins/pagerduty/e2e/incident_test.go 
b/backend/plugins/pagerduty/e2e/incident_test.go
index 1a77bd268..6076b8a0b 100644
--- a/backend/plugins/pagerduty/e2e/incident_test.go
+++ b/backend/plugins/pagerduty/e2e/incident_test.go
@@ -19,6 +19,8 @@ package e2e
 
 import (
        "fmt"
+       "testing"
+
        "github.com/apache/incubator-devlake/core/models/common"
        "github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
        "github.com/apache/incubator-devlake/helpers/e2ehelper"
@@ -26,36 +28,35 @@ import (
        "github.com/apache/incubator-devlake/plugins/pagerduty/models"
        "github.com/apache/incubator-devlake/plugins/pagerduty/tasks"
        "github.com/stretchr/testify/require"
-       "testing"
 )
 
 func TestIncidentDataFlow(t *testing.T) {
        var plugin impl.PagerDuty
        dataflowTester := e2ehelper.NewDataFlowTester(t, "pagerduty", plugin)
-       rule := models.PagerdutyTransformationRule{
+       scopeConfig := models.PagerdutyScopeConfig{
                Name: "rule1",
        }
        options := tasks.PagerDutyOptions{
-               ConnectionId:                1,
-               ServiceId:                   "PIKL83L",
-               ServiceName:                 "DevService",
-               Tasks:                       nil,
-               PagerdutyTransformationRule: &rule,
+               ConnectionId:         1,
+               ServiceId:            "PIKL83L",
+               ServiceName:          "DevService",
+               Tasks:                nil,
+               PagerdutyScopeConfig: &scopeConfig,
        }
        taskData := &tasks.PagerDutyTaskData{
                Options: &options,
        }
 
-       dataflowTester.FlushTabler(&models.PagerdutyTransformationRule{})
+       dataflowTester.FlushTabler(&models.PagerdutyScopeConfig{})
        dataflowTester.FlushTabler(&models.Service{})
        // tx-rule
-       require.NoError(t, dataflowTester.Dal.CreateOrUpdate(&rule))
+       require.NoError(t, dataflowTester.Dal.CreateOrUpdate(&scopeConfig))
        service := models.Service{
-               ConnectionId:         options.ConnectionId,
-               Url:                  
fmt.Sprintf("https://keon-test.pagerduty.com/service-directory/%s";, 
options.ServiceId),
-               Id:                   options.ServiceId,
-               TransformationRuleId: rule.ID,
-               Name:                 options.ServiceName,
+               ConnectionId:  options.ConnectionId,
+               Url:           
fmt.Sprintf("https://keon-test.pagerduty.com/service-directory/%s";, 
options.ServiceId),
+               Id:            options.ServiceId,
+               ScopeConfigId: scopeConfig.ID,
+               Name:          options.ServiceName,
        }
        // scope
        require.NoError(t, dataflowTester.Dal.CreateOrUpdate(&service))
diff --git a/backend/plugins/pagerduty/impl/impl.go 
b/backend/plugins/pagerduty/impl/impl.go
index 35a1cd828..b3f1da041 100644
--- a/backend/plugins/pagerduty/impl/impl.go
+++ b/backend/plugins/pagerduty/impl/impl.go
@@ -39,7 +39,7 @@ var _ plugin.PluginTask = (*PagerDuty)(nil)
 var _ plugin.PluginApi = (*PagerDuty)(nil)
 
 var _ plugin.PluginModel = (*PagerDuty)(nil)
-var _ plugin.PluginBlueprintV100 = (*PagerDuty)(nil)
+var _ plugin.DataSourcePluginBlueprintV200 = (*PagerDuty)(nil)
 var _ plugin.CloseablePluginTask = (*PagerDuty)(nil)
 
 type PagerDuty struct{}
@@ -148,21 +148,17 @@ func (p PagerDuty) ApiResources() 
map[string]map[string]plugin.ApiResourceHandle
                        "PATCH":  api.UpdateScope,
                        "DELETE": api.DeleteScope,
                },
-               "connections/:connectionId/transformation_rules": {
-                       "POST": api.CreateTransformationRule,
-                       "GET":  api.GetTransformationRuleList,
+               "connections/:connectionId/scope_configs": {
+                       "POST": api.CreateScopeConfig,
+                       "GET":  api.GetScopeConfigList,
                },
-               "connections/:connectionId/transformation_rules/:id": {
-                       "PATCH": api.UpdateTransformationRule,
-                       "GET":   api.GetTransformationRule,
+               "connections/:connectionId/scope_configs/:id": {
+                       "PATCH": api.UpdateScopeConfig,
+                       "GET":   api.GetScopeConfig,
                },
        }
 }
 
-func (p PagerDuty) MakePipelinePlan(connectionId uint64, scope 
[]*plugin.BlueprintScopeV100) (plugin.PipelinePlan, errors.Error) {
-       return api.MakePipelinePlan(p.SubTaskMetas(), connectionId, scope)
-}
-
 func (p PagerDuty) MakeDataSourcePipelinePlanV200(connectionId uint64, scopes 
[]*plugin.BlueprintScopeV200, syncPolicy plugin.BlueprintSyncPolicy,
 ) (plugin.PipelinePlan, []plugin.Scope, errors.Error) {
        return api.MakeDataSourcePipelinePlanV200(p.SubTaskMetas(), 
connectionId, scopes, &syncPolicy)
diff --git 
a/backend/plugins/pagerduty/models/migrationscripts/20230531_scope_config.go 
b/backend/plugins/pagerduty/models/migrationscripts/20230531_scope_config.go
new file mode 100644
index 000000000..ad39e0708
--- /dev/null
+++ b/backend/plugins/pagerduty/models/migrationscripts/20230531_scope_config.go
@@ -0,0 +1,56 @@
+/*
+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 migrationscripts
+
+import (
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+type renameTr2ScopeConfig struct {
+}
+
+type scopeConfig20230531 struct {
+       Entities []string `gorm:"type:json" json:"entities"`
+}
+
+func (scopeConfig20230531) TableName() string {
+       return "_tool_pagerduty_scope_configs"
+}
+
+func (u *renameTr2ScopeConfig) Up(baseRes context.BasicRes) errors.Error {
+       db := baseRes.GetDal()
+       err := db.RenameColumn("_tool_pagerduty_services", 
"transformation_rule_id", "scope_config_id")
+       if err != nil {
+               return err
+       }
+       err = db.RenameTable("_tool_pagerduty_transformation_rules", 
"_tool_pagerduty_scope_configs")
+       if err != nil {
+               return err
+       }
+       return migrationhelper.AutoMigrateTables(baseRes, 
&scopeConfig20230531{})
+}
+
+func (*renameTr2ScopeConfig) Version() uint64 {
+       return 20230531130109
+}
+
+func (*renameTr2ScopeConfig) Name() string {
+       return "rename transformation rule to scope config for pagerduty"
+}
diff --git 
a/backend/plugins/pagerduty/models/migrationscripts/archived/service.go 
b/backend/plugins/pagerduty/models/migrationscripts/archived/service.go
index 36d404d4d..065aab1e4 100644
--- a/backend/plugins/pagerduty/models/migrationscripts/archived/service.go
+++ b/backend/plugins/pagerduty/models/migrationscripts/archived/service.go
@@ -25,7 +25,7 @@ type (
        Service struct {
                common.NoPKModel
                ConnectionId uint64 `gorm:"primaryKey"`
-               Id           string `gorm:"primaryKey"`
+               Id           string `gorm:"primaryKey;autoIncremental:false"`
                Url          string
                Name         string
        }
diff --git a/backend/plugins/pagerduty/models/migrationscripts/archived/user.go 
b/backend/plugins/pagerduty/models/migrationscripts/archived/user.go
index 0d7eb72e1..af8033f83 100644
--- a/backend/plugins/pagerduty/models/migrationscripts/archived/user.go
+++ b/backend/plugins/pagerduty/models/migrationscripts/archived/user.go
@@ -24,7 +24,7 @@ import (
 type User struct {
        common.NoPKModel
        ConnectionId uint64 `gorm:"primaryKey"`
-       Id           string `gorm:"primaryKey"`
+       Id           string `gorm:"primaryKey;autoIncremental:false"`
        Url          string
        Name         string
 }
diff --git a/backend/plugins/pagerduty/models/migrationscripts/register.go 
b/backend/plugins/pagerduty/models/migrationscripts/register.go
index 75aa89265..a52ffebd4 100644
--- a/backend/plugins/pagerduty/models/migrationscripts/register.go
+++ b/backend/plugins/pagerduty/models/migrationscripts/register.go
@@ -28,5 +28,6 @@ func All() []plugin.MigrationScript {
                new(addEndpointAndProxyToConnection),
                new(addPagerdutyConnectionFields20230123),
                new(addTransformationRulesToService20230303),
+               new(renameTr2ScopeConfig),
        }
 }
diff --git a/backend/plugins/pagerduty/models/transformation_rules.go 
b/backend/plugins/pagerduty/models/scope_config.go
similarity index 70%
rename from backend/plugins/pagerduty/models/transformation_rules.go
rename to backend/plugins/pagerduty/models/scope_config.go
index 6d83916ac..93c403cfb 100644
--- a/backend/plugins/pagerduty/models/transformation_rules.go
+++ b/backend/plugins/pagerduty/models/scope_config.go
@@ -21,12 +21,12 @@ import (
        "github.com/apache/incubator-devlake/core/models/common"
 )
 
-type PagerdutyTransformationRule struct {
-       common.Model `mapstructure:"-"`
-       Name         string `mapstructure:"name" json:"name" 
gorm:"type:varchar(255);index:idx_name_github,unique" validate:"required"`
-       ConnectionId uint64
+type PagerdutyScopeConfig struct {
+       common.ScopeConfig `mapstructure:",squash" json:",inline" 
gorm:"embedded"`
+       Name               string `mapstructure:"name" json:"name" 
gorm:"type:varchar(255);index:idx_name_github,unique" validate:"required"`
+       ConnectionId       uint64
 }
 
-func (PagerdutyTransformationRule) TableName() string {
-       return "_tool_pagerduty_transformation_rules"
+func (PagerdutyScopeConfig) TableName() string {
+       return "_tool_pagerduty_scope_configs"
 }
diff --git a/backend/plugins/pagerduty/models/service.go 
b/backend/plugins/pagerduty/models/service.go
index 6c5cfb3ee..114a6ac62 100644
--- a/backend/plugins/pagerduty/models/service.go
+++ b/backend/plugins/pagerduty/models/service.go
@@ -23,11 +23,11 @@ import (
 
 type Service struct {
        common.NoPKModel
-       ConnectionId         uint64 `json:"connection_id" 
mapstructure:"connectionId,omitempty" gorm:"primaryKey" `
-       Url                  string `json:"url" mapstructure:"url"`
-       Id                   string `json:"id" mapstructure:"id" 
gorm:"primaryKey" `
-       TransformationRuleId uint64 `json:"transformation_rule_id" 
mapstructure:"transformation_rule_id,omitempty"` //keys to 
PagerdutyTransformationRules.ID
-       Name                 string `json:"name" mapstructure:"name"`
+       ConnectionId  uint64 `json:"connection_id" 
mapstructure:"connectionId,omitempty" gorm:"primaryKey" `
+       Id            string `json:"id" mapstructure:"id" 
gorm:"primaryKey;autoIncrement:false" `
+       Url           string `json:"url" mapstructure:"url"`
+       ScopeConfigId uint64 `json:"scopeConfigId" 
mapstructure:"scopeConfigId,omitempty"` //keys to PagerdutyScopeConfigs.ID
+       Name          string `json:"name" mapstructure:"name"`
 }
 
 func (Service) TableName() string {
diff --git a/backend/plugins/pagerduty/models/user.go 
b/backend/plugins/pagerduty/models/user.go
index 130b0d913..36799dff6 100644
--- a/backend/plugins/pagerduty/models/user.go
+++ b/backend/plugins/pagerduty/models/user.go
@@ -24,7 +24,7 @@ import (
 type User struct {
        common.NoPKModel
        ConnectionId uint64 `gorm:"primaryKey"`
-       Id           string `gorm:"primaryKey"`
+       Id           string `gorm:"primaryKey;autoIncrement:false"`
        Url          string
        Name         string
 }
diff --git a/backend/plugins/pagerduty/tasks/task_data.go 
b/backend/plugins/pagerduty/tasks/task_data.go
index b223a167e..b1a42c211 100644
--- a/backend/plugins/pagerduty/tasks/task_data.go
+++ b/backend/plugins/pagerduty/tasks/task_data.go
@@ -18,10 +18,11 @@ limitations under the License.
 package tasks
 
 import (
+       "time"
+
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
        "github.com/apache/incubator-devlake/plugins/pagerduty/models"
-       "time"
 )
 
 type PagerDutyOptions struct {
@@ -30,7 +31,7 @@ type PagerDutyOptions struct {
        ServiceId    string   `json:"service_id,omitempty"`
        ServiceName  string   `json:"service_name,omitempty"`
        Tasks        []string `json:"tasks,omitempty"`
-       *models.PagerdutyTransformationRule
+       *models.PagerdutyScopeConfig
 }
 
 type PagerDutyTaskData struct {

Reply via email to