You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2024/02/08 04:48:33 UTC
(incubator-devlake) branch main updated: fix: new dshelper does not set raw data origin properly (#6935)
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 ab7b94127 fix: new dshelper does not set raw data origin properly (#6935)
ab7b94127 is described below
commit ab7b94127c0ed0a139b2b7e19d00ffe8f4b3cdb1
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Thu Feb 8 12:48:25 2024 +0800
fix: new dshelper does not set raw data origin properly (#6935)
---
backend/helpers/pluginhelper/api/ds_scope_api_helper.go | 14 +++++++++++++-
backend/helpers/pluginhelper/api/model_api_helper.go | 8 +++++++-
backend/helpers/srvhelper/scope_service_helper.go | 4 ++++
.../20230630_add_raw_param_table_for_scopes.go | 3 ++-
.../20230630_add_raw_param_table_for_scopes.go | 3 ++-
.../20230630_add_raw_param_table_for_scopes.go | 3 ++-
.../20230630_add_raw_param_table_for_scopes.go | 3 ++-
.../20230630_add_raw_param_table_for_scopes.go | 3 ++-
.../20230630_add_raw_param_table_for_scopes.go | 3 ++-
9 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/ds_scope_api_helper.go b/backend/helpers/pluginhelper/api/ds_scope_api_helper.go
index 75ea9088b..3775f19e3 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 716a3694d..0dbc4ad95 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 4235bafa3..deda7c25e 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 edef3e857..7671bdedc 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 3be360519..95a84b542 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 e8797176b..b9d42e5de 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 4d4ee1abe..37f1e8fac 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 10d27881a..4a8c99dd2 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 511b7cbe4..da9f22d22 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 {