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 88ca95f44 fix(sonarqube): fix scopes (#5045)
88ca95f44 is described below
commit 88ca95f444ad4e4761562c4a07f079f3a0bbc4e9
Author: Warren Chen <[email protected]>
AuthorDate: Thu Apr 27 12:43:55 2023 +0800
fix(sonarqube): fix scopes (#5045)
---
backend/helpers/pluginhelper/api/scope_helper.go | 8 +++++++-
backend/plugins/sonarqube/api/scope.go | 9 +++++++--
backend/plugins/sonarqube/models/sonarqube_project.go | 14 +++++++-------
3 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/scope_helper.go
b/backend/helpers/pluginhelper/api/scope_helper.go
index 2571517a9..d957862f8 100644
--- a/backend/helpers/pluginhelper/api/scope_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_helper.go
@@ -285,7 +285,13 @@ func (c *ScopeApiHelper[Conn, Scope, Tr])
addTransformationName(scopes []*Scope)
}
apiScopes := make([]ScopeRes[Scope], 0)
for _, scope := range scopes {
- apiScopes = append(apiScopes, ScopeRes[Scope]{*scope,
names[reflect.ValueOf(scope).Elem().FieldByName("TransformationRuleId").Uint()]})
+ field :=
reflect.ValueOf(scope).Elem().FieldByName("TransformationRuleId")
+ if field.IsValid() {
+ apiScopes = append(apiScopes, ScopeRes[Scope]{*scope,
names[field.Uint()]})
+ } else {
+ apiScopes = append(apiScopes, ScopeRes[Scope]{Scope:
*scope, TransformationRuleName: ""})
+ }
+
}
return apiScopes, nil
}
diff --git a/backend/plugins/sonarqube/api/scope.go
b/backend/plugins/sonarqube/api/scope.go
index 046a0d77f..3d46b2ef7 100644
--- a/backend/plugins/sonarqube/api/scope.go
+++ b/backend/plugins/sonarqube/api/scope.go
@@ -24,6 +24,11 @@ import (
"github.com/apache/incubator-devlake/plugins/sonarqube/models"
)
+type ScopeRes struct {
+ models.SonarqubeProject
+ TransformationRuleName string `json:"transformationRuleName,omitempty"`
+}
+
type ScopeReq api.ScopeReq[models.SonarqubeProject]
// PutScope create or update sonarqube project
@@ -62,7 +67,7 @@ func UpdateScope(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, err
// @Description get Sonarqube projects
// @Tags plugins/sonarqube
// @Param connectionId path int false "connection ID"
-// @Success 200 {object} []models.SonarqubeProject
+// @Success 200 {object} []ScopeRes
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/sonarqube/connections/{connectionId}/scopes/ [GET]
@@ -78,7 +83,7 @@ func GetScopeList(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, er
// @Param scopeId path string false "project key"
// @Param pageSize query int false "page size, default 50"
// @Param page query int false "page size, default 1"
-// @Success 200 {object} models.SonarqubeProject
+// @Success 200 {object} ScopeRes
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/sonarqube/connections/{connectionId}/scopes/{scopeId} [GET]
diff --git a/backend/plugins/sonarqube/models/sonarqube_project.go
b/backend/plugins/sonarqube/models/sonarqube_project.go
index 85bfa90b1..fa5322d0c 100644
--- a/backend/plugins/sonarqube/models/sonarqube_project.go
+++ b/backend/plugins/sonarqube/models/sonarqube_project.go
@@ -28,13 +28,13 @@ var _ plugin.ApiScope = (*SonarqubeApiProject)(nil)
type SonarqubeProject struct {
common.NoPKModel `json:"-" mapstructure:"-"`
- ConnectionId uint64 `json:"connectionId"
validate:"required" gorm:"primaryKey"`
- ProjectKey string `json:"projectKey"
validate:"required" gorm:"type:varchar(255);primaryKey"`
- Name string `json:"name" gorm:"type:varchar(255)"`
- Qualifier string `json:"qualifier"
gorm:"type:varchar(255)"`
- Visibility string `json:"visibility"
gorm:"type:varchar(64)"`
- LastAnalysisDate *api.Iso8601Time `json:"lastAnalysisDate"`
- Revision string `json:"revision"
gorm:"type:varchar(128)"`
+ ConnectionId uint64 `json:"connectionId"
validate:"required" gorm:"primaryKey" mapstructure:"connectionId"`
+ ProjectKey string `json:"projectKey"
validate:"required" gorm:"type:varchar(255);primaryKey"
mapstructure:"projectKey"`
+ Name string `json:"name" gorm:"type:varchar(255)"
mapstructure:"name"`
+ Qualifier string `json:"qualifier"
gorm:"type:varchar(255)" mapstructure:"qualifier"`
+ Visibility string `json:"visibility"
gorm:"type:varchar(64)" mapstructure:"visibility"`
+ LastAnalysisDate *api.Iso8601Time `json:"lastAnalysisDate"
mapstructure:"lastAnalysisDate"`
+ Revision string `json:"revision"
gorm:"type:varchar(128)" mapstructure:"revision"`
}
func (SonarqubeProject) TableName() string {