diff --git a/backend/helpers/pluginhelper/api/ds_scope_api_helper.go b/backend/helpers/pluginhelper/api/ds_scope_api_helper.go index 75ea9088b77..3775f19e375 100644 --- a/backend/helpers/pluginhelper/api/ds_scope_api_helper.go +++ b/backend/helpers/pluginhelper/api/ds_scope_api_helper.go @@ -18,8 +18,11 @@ limitations under the License. package api import ( + "fmt" + "github.com/apache/incubator-devlake/core/context" "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/models/common" "github.com/apache/incubator-devlake/core/plugin" "github.com/apache/incubator-devlake/helpers/srvhelper" "github.com/apache/incubator-devlake/server/api/shared" @@ -112,7 +115,16 @@ func (scopeApi *DsScopeApiHelper[C, S, SC]) PutMultiple(input *plugin.ApiResourc } dict["connectionId"] = connectionId } - return scopeApi.ModelApiHelper.PutMultiple(input) + return scopeApi.ModelApiHelper.PutMultipleCb(input, func(m *S) errors.Error { + ok := setRawDataOrigin(m, common.RawDataOrigin{ + RawDataTable: fmt.Sprintf("_raw_%s_scopes", scopeApi.GetPluginName()), + RawDataParams: plugin.MarshalScopeParams((*m).ScopeParams()), + }) + if !ok { + panic("set raw data origin failed") + } + return nil + }) } func (scopeApi *DsScopeApiHelper[C, S, SC]) Delete(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { diff --git a/backend/helpers/pluginhelper/api/model_api_helper.go b/backend/helpers/pluginhelper/api/model_api_helper.go index 716a3694d6f..0dbc4ad9577 100644 --- a/backend/helpers/pluginhelper/api/model_api_helper.go +++ b/backend/helpers/pluginhelper/api/model_api_helper.go @@ -190,7 +190,7 @@ func (self *ModelApiHelper[M]) GetAll(input *plugin.ApiResourceInput) (*plugin.A }, err } -func (self *ModelApiHelper[M]) PutMultiple(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { +func (self *ModelApiHelper[M]) PutMultipleCb(input *plugin.ApiResourceInput, beforeSave func(*M) errors.Error) (*plugin.ApiResourceOutput, errors.Error) { var req struct { Data []*M `json:"data"` } @@ -199,6 +199,12 @@ func (self *ModelApiHelper[M]) PutMultiple(input *plugin.ApiResourceInput) (*plu return nil, err } for i, item := range req.Data { + if beforeSave != nil { + err := beforeSave(item) + if err != nil { + return nil, err + } + } err := self.dalHelper.CreateOrUpdate(item) if err != nil { return nil, errors.BadInput.Wrap(err, fmt.Sprintf("failed to save item %d", i)) diff --git a/backend/helpers/srvhelper/scope_service_helper.go b/backend/helpers/srvhelper/scope_service_helper.go index 4235bafa302..deda7c25e86 100644 --- a/backend/helpers/srvhelper/scope_service_helper.go +++ b/backend/helpers/srvhelper/scope_service_helper.go @@ -64,6 +64,10 @@ func NewScopeSrvHelper[ } } +func (scopeSrv *ScopeSrvHelper[C, S, SC]) GetPluginName() string { + return scopeSrv.pluginName +} + func (scopeSrv *ScopeSrvHelper[C, S, SC]) Validate(scope *S) errors.Error { connectionId := (*scope).ScopeConnectionId() connectionCount := errors.Must1(scopeSrv.db.Count(dal.From(new(SC)), dal.Where("id = ?", connectionId))) diff --git a/backend/plugins/bamboo/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go b/backend/plugins/bamboo/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go index edef3e8571d..7671bdedcc1 100644 --- a/backend/plugins/bamboo/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go +++ b/backend/plugins/bamboo/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go @@ -73,7 +73,8 @@ func (script *addRawParamTableForScope) Up(basicRes context.BasicRes) errors.Err } func (*addRawParamTableForScope) Version() uint64 { - return 20230630000002 + // return 20230630000002 + return 20240208000002 } func (script *addRawParamTableForScope) Name() string { diff --git a/backend/plugins/bitbucket/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go b/backend/plugins/bitbucket/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go index 3be3605193e..95a84b542f8 100644 --- a/backend/plugins/bitbucket/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go +++ b/backend/plugins/bitbucket/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go @@ -73,7 +73,8 @@ func (script *addRawParamTableForScope) Up(basicRes context.BasicRes) errors.Err } func (*addRawParamTableForScope) Version() uint64 { - return 20230630000002 + // return 20230630000002 + return 20240208000002 } func (script *addRawParamTableForScope) Name() string { diff --git a/backend/plugins/github/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go b/backend/plugins/github/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go index e8797176b4e..b9d42e5dec0 100644 --- a/backend/plugins/github/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go +++ b/backend/plugins/github/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go @@ -74,7 +74,8 @@ func (script *addRawParamTableForScope) Up(basicRes context.BasicRes) errors.Err } func (*addRawParamTableForScope) Version() uint64 { - return 20230630000002 + // return 20230630000002 + return 20240208000002 } func (script *addRawParamTableForScope) Name() string { diff --git a/backend/plugins/gitlab/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go b/backend/plugins/gitlab/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go index 4d4ee1abe10..37f1e8fac08 100644 --- a/backend/plugins/gitlab/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go +++ b/backend/plugins/gitlab/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go @@ -74,7 +74,8 @@ func (script *addRawParamTableForScope) Up(basicRes context.BasicRes) errors.Err } func (*addRawParamTableForScope) Version() uint64 { - return 20230630000002 + // return 20230630000002 + return 20240208000002 } func (script *addRawParamTableForScope) Name() string { diff --git a/backend/plugins/jira/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go b/backend/plugins/jira/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go index 10d27881adb..4a8c99dd20d 100644 --- a/backend/plugins/jira/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go +++ b/backend/plugins/jira/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go @@ -74,7 +74,8 @@ func (script *addRawParamTableForScope) Up(basicRes context.BasicRes) errors.Err } func (*addRawParamTableForScope) Version() uint64 { - return 20230630000002 + // return 20230630000002 + return 20240208000002 } func (script *addRawParamTableForScope) Name() string { diff --git a/backend/plugins/sonarqube/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go b/backend/plugins/sonarqube/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go index 511b7cbe42a..da9f22d2272 100644 --- a/backend/plugins/sonarqube/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go +++ b/backend/plugins/sonarqube/models/migrationscripts/20230630_add_raw_param_table_for_scopes.go @@ -73,7 +73,8 @@ func (script *addRawParamTableForScope) Up(basicRes context.BasicRes) errors.Err } func (*addRawParamTableForScope) Version() uint64 { - return 20230630000002 + // return 20230630000002 + return 20240208000002 } func (script *addRawParamTableForScope) Name() string {