This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch fix#7075
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/fix#7075 by this push:
new 183e104bd fix: sonarqube connection delete on no scope config
183e104bd is described below
commit 183e104bd39d1d4770cebef49d9bb6426161dd31
Author: abeizn <[email protected]>
AuthorDate: Mon Mar 4 15:05:40 2024 +0800
fix: sonarqube connection delete on no scope config
---
.../helpers/srvhelper/connection_service_helper.go | 6 ++-
backend/plugins/sonarqube/api/blueprint_v200.go | 54 ++++++++++------------
backend/plugins/sonarqube/api/init.go | 5 +-
3 files changed, 32 insertions(+), 33 deletions(-)
diff --git a/backend/helpers/srvhelper/connection_service_helper.go
b/backend/helpers/srvhelper/connection_service_helper.go
index 7244e2724..991f1a5bc 100644
--- a/backend/helpers/srvhelper/connection_service_helper.go
+++ b/backend/helpers/srvhelper/connection_service_helper.go
@@ -18,6 +18,7 @@ limitations under the License.
package srvhelper
import (
+ "fmt"
"reflect"
"github.com/apache/incubator-devlake/core/context"
@@ -61,7 +62,10 @@ func (connSrv *ConnectionSrvHelper[C, S, SC])
DeleteConnection(connection *C) (r
return errors.Conflict.New("Please delete all data
scope(s) before you delete this Data Connection.")
}
errors.Must(tx.Delete(connection))
- if reflect.TypeOf(new(SC)) !=
reflect.TypeOf(new(NoScopeConfig)) {
+ scType := reflect.TypeOf(new(SC))
+ _, ok := scType.Elem().FieldByName("ConnectionId")
+ fmt.Println("scType---------:", scType, ok)
+ if scType != reflect.TypeOf(new(NoScopeConfig)) && ok {
errors.Must(connSrv.db.Delete(new(SC),
dal.Where("connection_id = ?", connectionId)))
}
return nil
diff --git a/backend/plugins/sonarqube/api/blueprint_v200.go
b/backend/plugins/sonarqube/api/blueprint_v200.go
index cd396541b..250b1bf1d 100644
--- a/backend/plugins/sonarqube/api/blueprint_v200.go
+++ b/backend/plugins/sonarqube/api/blueprint_v200.go
@@ -29,7 +29,6 @@ import (
"github.com/apache/incubator-devlake/core/models/domainlayer/codequality"
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
"github.com/apache/incubator-devlake/core/plugin"
- "github.com/apache/incubator-devlake/core/utils"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/plugins/sonarqube/models"
@@ -72,7 +71,7 @@ func MakeDataSourcePipelinePlanV200(
func makeDataSourcePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
- scopeDetails []*srvhelper.ScopeDetail[models.SonarqubeProject,
models.SonarqubeScopeConfig],
+ scopeDetails []*srvhelper.ScopeDetail[models.SonarqubeProject,
srvhelper.NoScopeConfig],
connection *models.SonarqubeConnection,
) (coreModels.PipelinePlan, errors.Error) {
plan := make(coreModels.PipelinePlan, len(scopeDetails))
@@ -81,48 +80,43 @@ func makeDataSourcePipelinePlanV200(
if stage == nil {
stage = coreModels.PipelineStage{}
}
-
- scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
+ scope := scopeDetail.Scope
// construct task options
- if utils.StringsContains(scopeConfig.Entities,
plugin.DOMAIN_TYPE_CODE_QUALITY) {
- task, err := helper.MakePipelinePlanTask(
- "sonarqube",
- subtaskMetas,
- nil,
- tasks.SonarqubeOptions{
- ConnectionId: scope.ConnectionId,
- ProjectKey: scope.ProjectKey,
- },
- )
- if err != nil {
- return nil, err
- }
-
- stage = append(stage, task)
- plan[i] = stage
+ task, err := helper.MakePipelinePlanTask(
+ "sonarqube",
+ subtaskMetas,
+ nil,
+ tasks.SonarqubeOptions{
+ ConnectionId: scope.ConnectionId,
+ ProjectKey: scope.ProjectKey,
+ },
+ )
+ if err != nil {
+ return nil, err
}
+
+ stage = append(stage, task)
+ plan[i] = stage
}
return plan, nil
}
func makeScopesV200(
- scopeDetails []*srvhelper.ScopeDetail[models.SonarqubeProject,
models.SonarqubeScopeConfig],
+ scopeDetails []*srvhelper.ScopeDetail[models.SonarqubeProject,
srvhelper.NoScopeConfig],
connection *models.SonarqubeConnection,
) ([]plugin.Scope, errors.Error) {
scopes := make([]plugin.Scope, 0)
for _, scopeDetail := range scopeDetails {
- sonarqubeProject, scopeConfig := scopeDetail.Scope,
scopeDetail.ScopeConfig
+ sonarqubeProject := scopeDetail.Scope
// add board to scopes
- if utils.StringsContains(scopeConfig.Entities,
plugin.DOMAIN_TYPE_CODE_QUALITY) {
- domainBoard := &codequality.CqProject{
- DomainEntity: domainlayer.DomainEntity{
- Id:
didgen.NewDomainIdGenerator(&models.SonarqubeProject{}).Generate(sonarqubeProject.ConnectionId,
sonarqubeProject.ProjectKey),
- },
- Name: sonarqubeProject.Name,
- }
- scopes = append(scopes, domainBoard)
+ domainBoard := &codequality.CqProject{
+ DomainEntity: domainlayer.DomainEntity{
+ Id:
didgen.NewDomainIdGenerator(&models.SonarqubeProject{}).Generate(sonarqubeProject.ConnectionId,
sonarqubeProject.ProjectKey),
+ },
+ Name: sonarqubeProject.Name,
}
+ scopes = append(scopes, domainBoard)
}
return scopes, nil
diff --git a/backend/plugins/sonarqube/api/init.go
b/backend/plugins/sonarqube/api/init.go
index 25ec647f6..9d3ca84f4 100644
--- a/backend/plugins/sonarqube/api/init.go
+++ b/backend/plugins/sonarqube/api/init.go
@@ -21,6 +21,7 @@ import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/plugins/sonarqube/models"
"github.com/go-playground/validator/v10"
)
@@ -28,7 +29,7 @@ import (
var vld *validator.Validate
var basicRes context.BasicRes
-var dsHelper *api.DsHelper[models.SonarqubeConnection,
models.SonarqubeProject, models.SonarqubeScopeConfig]
+var dsHelper *api.DsHelper[models.SonarqubeConnection,
models.SonarqubeProject, srvhelper.NoScopeConfig]
var raProxy *api.DsRemoteApiProxyHelper[models.SonarqubeConnection]
var raScopeList *api.DsRemoteApiScopeListHelper[models.SonarqubeConnection,
models.SonarqubeProject, SonarqubeRemotePagination]
var raScopeSearch
*api.DsRemoteApiScopeSearchHelper[models.SonarqubeConnection,
models.SonarqubeProject]
@@ -39,7 +40,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
dsHelper = api.NewDataSourceHelper[
models.SonarqubeConnection,
models.SonarqubeProject,
- models.SonarqubeScopeConfig,
+ srvhelper.NoScopeConfig,
](
br,
p.Name(),