Skip to content

Commit

Permalink
fix: new dshelper does not set raw data origin properly (#6935) (#6936)
Browse files Browse the repository at this point in the history
Co-authored-by: Klesh Wong <zhenmian.huang@merico.dev>
  • Loading branch information
github-actions[bot] and klesh authored Feb 8, 2024
1 parent dcc8d20 commit 1ba3b88
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 8 deletions.
14 changes: 13 additions & 1 deletion backend/helpers/pluginhelper/api/ds_scope_api_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion backend/helpers/pluginhelper/api/model_api_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions backend/helpers/srvhelper/scope_service_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1ba3b88

Please sign in to comment.