Skip to content

Commit

Permalink
fix(helper): update ScopeRes struct, fix empty time field when deco… (
Browse files Browse the repository at this point in the history
apache#6230)

* fix(helper): update `ScopeRes` struct, fix empty time field when decoding by mapstructure

* fix(ci): fix ci error when checking apache license header
  • Loading branch information
d4x1 committed Oct 12, 2023
1 parent d21b68d commit a773ce7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/grafana-dashboards-check.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#
# 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.

name: check-grafana-dashboards

on:
Expand Down
23 changes: 3 additions & 20 deletions backend/helpers/pluginhelper/api/scope_generic_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package api

import (
"encoding/json"
"fmt"
"reflect"
"strconv"
Expand All @@ -36,7 +35,6 @@ import (
"github.com/apache/incubator-devlake/helpers/dbhelper"
serviceHelper "github.com/apache/incubator-devlake/helpers/pluginhelper/services"
"github.com/go-playground/validator/v10"
"github.com/mitchellh/mapstructure"
)

type NoScopeConfig struct{}
Expand Down Expand Up @@ -64,8 +62,9 @@ type (
// Alias, for swagger purposes
ScopeRefDoc = serviceHelper.BlueprintProjectPairs
ScopeRes[Scope plugin.ToolLayerScope, ScopeConfig any] struct {
Scope Scope `mapstructure:",squash"` // ideally we need this field to be embedded in the struct
ScopeResDoc[ScopeConfig] `mapstructure:",squash"` // however, only this type of embeding is supported as of golang 1.20
Scope Scope `mapstructure:"scope,omitempty" json:"scope,omitempty"`
ScopeConfig *ScopeConfig `mapstructure:"scopeConfig,omitempty" json:"scopeConfig,omitempty"`
Blueprints []*models.Blueprint `mapstructure:"blueprints,omitempty" json:"blueprints,omitempty"`
}
ScopeListRes[Scope plugin.ToolLayerScope, ScopeConfig any] struct {
Scopes []*ScopeRes[Scope, ScopeConfig] `mapstructure:"scopes" json:"scopes"`
Expand Down Expand Up @@ -601,22 +600,6 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) transactionalDelete(t
return nil
}

// Implement MarshalJSON method to flatten all fields
func (sr *ScopeRes[T, Y]) MarshalJSON() ([]byte, error) {
var flatMap map[string]interface{}
err := mapstructure.Decode(sr, &flatMap)
if err != nil {
return nil, err
}
// Encode the flattened map to JSON
result, err := json.Marshal(flatMap)
if err != nil {
return nil, err
}

return result, nil
}

func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) getAffectedTables(pluginName string) ([]string, errors.Error) {
var tables []string
meta, err := plugin.GetPlugin(pluginName)
Expand Down
4 changes: 2 additions & 2 deletions backend/helpers/pluginhelper/api/scope_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func (c *ScopeApiHelper[Conn, Scope, Tr]) GetScopeList(input *plugin.ApiResource
}

func (c *ScopeApiHelper[Conn, Scope, Tr]) GetScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
scopeRes, err := c.GenericScopeApiHelper.GetScope(input)
scope, err := c.GenericScopeApiHelper.GetScope(input)
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: scopeRes.Scope, Status: http.StatusOK}, nil
return &plugin.ApiResourceOutput{Body: scope, Status: http.StatusOK}, nil
}

func (c *ScopeApiHelper[Conn, Scope, Tr]) Delete(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
Expand Down
2 changes: 1 addition & 1 deletion backend/server/services/remote/plugin/scope_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func convertScopeResponse(scopes ...*api.ScopeRes[models.DynamicScopeModel, mode
responses := make([]map[string]any, len(scopes))
for i, scope := range scopes {
resMap := map[string]any{}
err := models.MapTo(scope.ScopeResDoc, &resMap)
err := models.MapTo(scope, &resMap)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a773ce7

Please sign in to comment.