This is an automated email from the ASF dual-hosted git repository.
klesh 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 a773ce78f fix(helper): update `ScopeRes` struct, fix empty time field
when deco… (#6230)
a773ce78f is described below
commit a773ce78f6871e7763b3e6602361ebfdb9356b12
Author: Lynwee <[email protected]>
AuthorDate: Thu Oct 12 16:15:25 2023 +0800
fix(helper): update `ScopeRes` struct, fix empty time field when deco…
(#6230)
* fix(helper): update `ScopeRes` struct, fix empty time field when decoding
by mapstructure
* fix(ci): fix ci error when checking apache license header
---
.github/workflows/grafana-dashboards-check.yml | 16 +++++++++++++++
.../pluginhelper/api/scope_generic_helper.go | 23 +++-------------------
backend/helpers/pluginhelper/api/scope_helper.go | 4 ++--
backend/server/services/remote/plugin/scope_api.go | 2 +-
4 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/.github/workflows/grafana-dashboards-check.yml
b/.github/workflows/grafana-dashboards-check.yml
index 5dfa33aec..83c428e8b 100644
--- a/.github/workflows/grafana-dashboards-check.yml
+++ b/.github/workflows/grafana-dashboards-check.yml
@@ -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:
diff --git a/backend/helpers/pluginhelper/api/scope_generic_helper.go
b/backend/helpers/pluginhelper/api/scope_generic_helper.go
index 4b6d71817..a12bd8ee7 100644
--- a/backend/helpers/pluginhelper/api/scope_generic_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_generic_helper.go
@@ -18,7 +18,6 @@ limitations under the License.
package api
import (
- "encoding/json"
"fmt"
"reflect"
"strconv"
@@ -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{}
@@ -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"`
@@ -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)
diff --git a/backend/helpers/pluginhelper/api/scope_helper.go
b/backend/helpers/pluginhelper/api/scope_helper.go
index 87df08fd3..6474c47fe 100644
--- a/backend/helpers/pluginhelper/api/scope_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_helper.go
@@ -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) {
diff --git a/backend/server/services/remote/plugin/scope_api.go
b/backend/server/services/remote/plugin/scope_api.go
index e934486c4..db22f0bc8 100644
--- a/backend/server/services/remote/plugin/scope_api.go
+++ b/backend/server/services/remote/plugin/scope_api.go
@@ -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
}