From 0e0c25c25bf9d9b3700a9415b5d22fe2fed83c03 Mon Sep 17 00:00:00 2001 From: abeizn Date: Tue, 30 Apr 2024 08:50:54 +0800 Subject: [PATCH 1/2] feat: support get related projects by scope config --- backend/core/models/project.go | 12 ++++ .../api/ds_scope_config_api_helper.go | 12 ++++ .../srvhelper/scope_config_service_helper.go | 56 ++++++++++++++++ .../azuredevops_go/api/scope_config_api.go | 14 ++++ backend/plugins/azuredevops_go/impl/impl.go | 6 +- .../plugins/bamboo/api/scope_config_api.go | 14 ++++ backend/plugins/bamboo/impl/impl.go | 3 + .../plugins/bitbucket/api/scope_config_api.go | 14 ++++ backend/plugins/bitbucket/impl/impl.go | 3 + .../bitbucket_server/api/scope_config_api.go | 14 ++++ backend/plugins/bitbucket_server/impl/impl.go | 3 + .../plugins/circleci/api/scope_config_api.go | 14 ++++ backend/plugins/circleci/impl/impl.go | 3 + .../plugins/github/api/scope_config_api.go | 14 ++++ backend/plugins/github/impl/impl.go | 3 + .../plugins/gitlab/api/scope_config_api.go | 14 ++++ backend/plugins/gitlab/impl/impl.go | 3 + .../plugins/jenkins/api/scope_config_api.go | 14 ++++ backend/plugins/jenkins/impl/impl.go | 3 + backend/plugins/jira/api/scope_config_api.go | 14 ++++ backend/plugins/jira/impl/impl.go | 3 + backend/plugins/tapd/api/scope_config_api.go | 14 ++++ backend/plugins/tapd/impl/impl.go | 3 + .../plugins/trello/api/scope_config_api.go | 14 ++++ backend/plugins/trello/impl/impl.go | 3 + .../plugins/zentao/api/scope_config_api.go | 14 ++++ backend/plugins/zentao/impl/impl.go | 3 + .../services/remote/plugin/default_api.go | 3 + .../remote/plugin/scope_config_api.go | 64 ++++++++++++++++++- 29 files changed, 352 insertions(+), 2 deletions(-) diff --git a/backend/core/models/project.go b/backend/core/models/project.go index 0c77238915d..f5cf6779abc 100644 --- a/backend/core/models/project.go +++ b/backend/core/models/project.go @@ -85,3 +85,15 @@ type Store struct { func (Store) TableName() string { return "_devlake_store" } + +type ProjectScopeOutput struct { + Projects []ProjectScope `json:"projects"` + Count int `json:"count"` +} + +type ProjectScope struct { + Name string `json:"name"` + Scopes []struct { + ScopeID string `json:"scopeId"` + } `json:"scopes"` +} diff --git a/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go b/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go index 6e76341ef5c..2809d8523ce 100644 --- a/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go +++ b/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go @@ -57,6 +57,18 @@ func (connApi *DsScopeConfigApiHelper[C, S, SC]) GetAll(input *plugin.ApiResourc }, nil } +func (connApi *DsScopeConfigApiHelper[C, S, SC]) GetProjects(input *plugin.ApiResourceInput) (out *plugin.ApiResourceOutput, err errors.Error) { + var scopeConfig *SC + scopeConfig, err = connApi.FindByPk(input) + if err != nil { + return nil, err + } + projectDetails := errors.Must1(connApi.ScopeConfigSrvHelper.GetProjects(input.Params["plugin"], scopeConfig)) + return &plugin.ApiResourceOutput{ + Body: projectDetails, + }, nil +} + func (connApi *DsScopeConfigApiHelper[C, S, SC]) Post(input *plugin.ApiResourceInput) (out *plugin.ApiResourceOutput, err errors.Error) { // fix connectionId connectionId, err := extractConnectionId(input) diff --git a/backend/helpers/srvhelper/scope_config_service_helper.go b/backend/helpers/srvhelper/scope_config_service_helper.go index 796ba29a511..3df6c8fd0ef 100644 --- a/backend/helpers/srvhelper/scope_config_service_helper.go +++ b/backend/helpers/srvhelper/scope_config_service_helper.go @@ -21,6 +21,7 @@ import ( "github.com/apache/incubator-devlake/core/context" "github.com/apache/incubator-devlake/core/dal" "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/models" "github.com/apache/incubator-devlake/core/plugin" ) @@ -55,6 +56,61 @@ func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) GetAllByConnectionId(conne return scopeConfigs, err } +func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) GetProjects(pluginName string, scopeConfig *SC) (*models.ProjectScopeOutput, errors.Error) { + ps := &models.ProjectScopeOutput{} + projectMap := make(map[string]*models.ProjectScope) + // 1. get all scopes that are using the scopeConfigId + var scope []*S + err := scopeConfigSrv.db.All(&scope, + dal.Where("scope_config_id = ?", (*scopeConfig).ScopeConfigId()), + ) + if err != nil { + return nil, err + } + for _, s := range scope { + // 2. get blueprint id by connection id and scope id + bpScope := []*models.BlueprintScope{} + err = scopeConfigSrv.db.All(&bpScope, + dal.Where("plugin_name = ? and connection_id = ? and scope_id = ?", pluginName, (*s).ScopeConnectionId(), (*s).ScopeId()), + ) + if err != nil { + return nil, err + } + + for _, bs := range bpScope { + // 3. get project details by blueprint id + bp := models.Blueprint{} + err = scopeConfigSrv.db.All(&bp, + dal.Where("id = ?", bs.BlueprintId), + ) + if err != nil { + return nil, err + } + if project, exists := projectMap[bp.ProjectName]; exists { + project.Scopes = append(project.Scopes, struct { + ScopeID string `json:"scopeId"` + }{ScopeID: bs.ScopeId}) + } else { + projectMap[bp.ProjectName] = &models.ProjectScope{ + Name: bp.ProjectName, + Scopes: []struct { + ScopeID string `json:"scopeId"` + }{ + {ScopeID: bs.ScopeId}, + }, + } + } + } + } + // 4. combine all projects + for _, project := range projectMap { + ps.Projects = append(ps.Projects, *project) + } + ps.Count = len(ps.Projects) + + return ps, err +} + func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) DeleteScopeConfig(scopeConfig *SC) (refs []*S, err errors.Error) { err = scopeConfigSrv.ModelSrvHelper.NoRunningPipeline(func(tx dal.Transaction) errors.Error { // make sure no scope is using the scopeConfig diff --git a/backend/plugins/azuredevops_go/api/scope_config_api.go b/backend/plugins/azuredevops_go/api/scope_config_api.go index be02fb2f044..081a728e916 100644 --- a/backend/plugins/azuredevops_go/api/scope_config_api.go +++ b/backend/plugins/azuredevops_go/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/azuredevops +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/azuredevops/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/azuredevops_go/impl/impl.go b/backend/plugins/azuredevops_go/impl/impl.go index 2ada8fd59d0..cfb9f364a36 100644 --- a/backend/plugins/azuredevops_go/impl/impl.go +++ b/backend/plugins/azuredevops_go/impl/impl.go @@ -19,10 +19,11 @@ package impl import ( "fmt" + "time" + coreModels "github.com/apache/incubator-devlake/core/models" "github.com/apache/incubator-devlake/helpers/pluginhelper/subtaskmeta/sorter" "github.com/apache/incubator-devlake/plugins/azuredevops_go/tasks" - "time" "github.com/apache/incubator-devlake/core/models/domainlayer/devops" @@ -243,6 +244,9 @@ func (p Azuredevops) ApiResources() map[string]map[string]plugin.ApiResourceHand "connections/:connectionId/proxy/rest/*path": { "GET": api.Proxy, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/bamboo/api/scope_config_api.go b/backend/plugins/bamboo/api/scope_config_api.go index 2cc54564502..31fa0a7d4dc 100644 --- a/backend/plugins/bamboo/api/scope_config_api.go +++ b/backend/plugins/bamboo/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/bamboo +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/bamboo/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/bamboo/impl/impl.go b/backend/plugins/bamboo/impl/impl.go index ddec6bd6c92..b28ed481ccb 100644 --- a/backend/plugins/bamboo/impl/impl.go +++ b/backend/plugins/bamboo/impl/impl.go @@ -248,6 +248,9 @@ func (p Bamboo) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "connections/:connectionId/proxy/rest/*path": { "GET": api.Proxy, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/bitbucket/api/scope_config_api.go b/backend/plugins/bitbucket/api/scope_config_api.go index 1e894165cf7..ab0a142fcd2 100644 --- a/backend/plugins/bitbucket/api/scope_config_api.go +++ b/backend/plugins/bitbucket/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/bitbucket +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/bitbucket/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/bitbucket/impl/impl.go b/backend/plugins/bitbucket/impl/impl.go index f4cdb5f9095..48c1ab333f1 100644 --- a/backend/plugins/bitbucket/impl/impl.go +++ b/backend/plugins/bitbucket/impl/impl.go @@ -238,6 +238,9 @@ func (p Bitbucket) ApiResources() map[string]map[string]plugin.ApiResourceHandle "GET": api.GetScopeConfig, "DELETE": api.DeleteScopeConfig, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/bitbucket_server/api/scope_config_api.go b/backend/plugins/bitbucket_server/api/scope_config_api.go index 6ca92f84ea4..30f4ead76f0 100644 --- a/backend/plugins/bitbucket_server/api/scope_config_api.go +++ b/backend/plugins/bitbucket_server/api/scope_config_api.go @@ -86,6 +86,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/bitbucket_server +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/bitbucket_server/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/bitbucket_server/impl/impl.go b/backend/plugins/bitbucket_server/impl/impl.go index d3ec499c865..1dcc54c2343 100644 --- a/backend/plugins/bitbucket_server/impl/impl.go +++ b/backend/plugins/bitbucket_server/impl/impl.go @@ -201,6 +201,9 @@ func (p BitbucketServer) ApiResources() map[string]map[string]plugin.ApiResource "GET": api.GetScopeConfig, "DELETE": api.DeleteScopeConfig, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/circleci/api/scope_config_api.go b/backend/plugins/circleci/api/scope_config_api.go index 28dff9ec4ad..c455a609b96 100644 --- a/backend/plugins/circleci/api/scope_config_api.go +++ b/backend/plugins/circleci/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/circleci +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/circleci/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/circleci/impl/impl.go b/backend/plugins/circleci/impl/impl.go index 3e2f55dd195..3d68cf770fd 100644 --- a/backend/plugins/circleci/impl/impl.go +++ b/backend/plugins/circleci/impl/impl.go @@ -207,6 +207,9 @@ func (p Circleci) ApiResources() map[string]map[string]plugin.ApiResourceHandler "GET": api.GetScopeConfig, "DELETE": api.DeleteScopeConfig, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/github/api/scope_config_api.go b/backend/plugins/github/api/scope_config_api.go index 57d083066e6..b2fd7f7af45 100644 --- a/backend/plugins/github/api/scope_config_api.go +++ b/backend/plugins/github/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/github +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/github/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/github/impl/impl.go b/backend/plugins/github/impl/impl.go index dc6b5496766..bcb964ec1a4 100644 --- a/backend/plugins/github/impl/impl.go +++ b/backend/plugins/github/impl/impl.go @@ -220,6 +220,9 @@ func (p Github) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "connections/:connectionId/proxy/rest/*path": { "GET": api.Proxy, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/gitlab/api/scope_config_api.go b/backend/plugins/gitlab/api/scope_config_api.go index 4ed8b36c022..eea51490885 100644 --- a/backend/plugins/gitlab/api/scope_config_api.go +++ b/backend/plugins/gitlab/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/gitlab +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/gitlab/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/gitlab/impl/impl.go b/backend/plugins/gitlab/impl/impl.go index ad99ec5012f..93e17160730 100644 --- a/backend/plugins/gitlab/impl/impl.go +++ b/backend/plugins/gitlab/impl/impl.go @@ -271,6 +271,9 @@ func (p Gitlab) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "connections/:connectionId/proxy/rest/*path": { "GET": api.Proxy, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/jenkins/api/scope_config_api.go b/backend/plugins/jenkins/api/scope_config_api.go index 2a9c82df755..a90a7285537 100644 --- a/backend/plugins/jenkins/api/scope_config_api.go +++ b/backend/plugins/jenkins/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/jenkins +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jenkins/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/jenkins/impl/impl.go b/backend/plugins/jenkins/impl/impl.go index 7042a5b4b5f..cd0b0f3530b 100644 --- a/backend/plugins/jenkins/impl/impl.go +++ b/backend/plugins/jenkins/impl/impl.go @@ -218,6 +218,9 @@ func (p Jenkins) ApiResources() map[string]map[string]plugin.ApiResourceHandler "connections/:connectionId/proxy/rest/*path": { "GET": api.Proxy, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/jira/api/scope_config_api.go b/backend/plugins/jira/api/scope_config_api.go index 58eb46ae406..a6f0e072af7 100644 --- a/backend/plugins/jira/api/scope_config_api.go +++ b/backend/plugins/jira/api/scope_config_api.go @@ -111,6 +111,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/jira +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/jira/impl/impl.go b/backend/plugins/jira/impl/impl.go index 5dd315393c0..17d38d3f649 100644 --- a/backend/plugins/jira/impl/impl.go +++ b/backend/plugins/jira/impl/impl.go @@ -323,6 +323,9 @@ func (p Jira) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "connections/:connectionId/dev-panel-commits": { "GET": api.GetCommitsURLs, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, "generate-regex": { "POST": api.GenRegex, }, diff --git a/backend/plugins/tapd/api/scope_config_api.go b/backend/plugins/tapd/api/scope_config_api.go index abca28949e5..15e7d0235ab 100644 --- a/backend/plugins/tapd/api/scope_config_api.go +++ b/backend/plugins/tapd/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/tapd +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/tapd/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/tapd/impl/impl.go b/backend/plugins/tapd/impl/impl.go index 326da6d16ad..38f5c2656ac 100644 --- a/backend/plugins/tapd/impl/impl.go +++ b/backend/plugins/tapd/impl/impl.go @@ -303,6 +303,9 @@ func (p Tapd) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "GET": api.GetScopeConfig, "DELETE": api.DeleteScopeConfig, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/trello/api/scope_config_api.go b/backend/plugins/trello/api/scope_config_api.go index 5a372cd344a..20ef0d70bc3 100644 --- a/backend/plugins/trello/api/scope_config_api.go +++ b/backend/plugins/trello/api/scope_config_api.go @@ -78,6 +78,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/trello +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/trello/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/trello/impl/impl.go b/backend/plugins/trello/impl/impl.go index 49dbb7c9ad2..e171c606053 100644 --- a/backend/plugins/trello/impl/impl.go +++ b/backend/plugins/trello/impl/impl.go @@ -189,6 +189,9 @@ func (p Trello) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "GET": api.GetScopeList, "PUT": api.PutScopes, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/plugins/zentao/api/scope_config_api.go b/backend/plugins/zentao/api/scope_config_api.go index 53b40e65738..28eef394b7a 100644 --- a/backend/plugins/zentao/api/scope_config_api.go +++ b/backend/plugins/zentao/api/scope_config_api.go @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } +// GetProjects return projects details related by scope config +// @Summary return all related projects +// @Description return all related projects +// @Tags plugins/zentao +// @Param id path int true "id" +// @Param scopeConfigId path int true "scopeConfigId" +// @Success 200 {object} models.ProjectScopeOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/zentao/scope-config/{scopeConfigId}/projects [GET] +func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjects(input) +} + // DeleteScopeConfig delete a scope config // @Summary delete a scope config // @Description delete a scope config diff --git a/backend/plugins/zentao/impl/impl.go b/backend/plugins/zentao/impl/impl.go index fa367534653..36e9d0ff9b3 100644 --- a/backend/plugins/zentao/impl/impl.go +++ b/backend/plugins/zentao/impl/impl.go @@ -282,6 +282,9 @@ func (p Zentao) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "connections/:connectionId/proxy/*path": { "GET": api.Proxy, }, + "scope-config/:scopeConfigId/projects": { + "GET": api.GetProjects, + }, } } diff --git a/backend/server/services/remote/plugin/default_api.go b/backend/server/services/remote/plugin/default_api.go index f891a5a20e7..84f1bcdb019 100644 --- a/backend/server/services/remote/plugin/default_api.go +++ b/backend/server/services/remote/plugin/default_api.go @@ -93,6 +93,9 @@ func GetDefaultAPI( "connections/:connectionId/search-remote-scopes": { "GET": papi.SearchRemoteScopes, }, + "scope-config/:id/projects": { + "GET": papi.GetProjects, + }, } papi.createScopeHelper() return resources diff --git a/backend/server/services/remote/plugin/scope_config_api.go b/backend/server/services/remote/plugin/scope_config_api.go index c772e9fa0da..44f85681f35 100644 --- a/backend/server/services/remote/plugin/scope_config_api.go +++ b/backend/server/services/remote/plugin/scope_config_api.go @@ -18,14 +18,15 @@ limitations under the License. package plugin import ( - "github.com/apache/incubator-devlake/server/services/remote/models" "net/http" "strconv" "github.com/apache/incubator-devlake/core/dal" "github.com/apache/incubator-devlake/core/errors" + coreModels "github.com/apache/incubator-devlake/core/models" "github.com/apache/incubator-devlake/core/plugin" "github.com/apache/incubator-devlake/helpers/pluginhelper/api" + "github.com/apache/incubator-devlake/server/services/remote/models" ) func (pa *pluginAPI) PostScopeConfigs(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { @@ -89,6 +90,67 @@ func (pa *pluginAPI) GetScopeConfig(input *plugin.ApiResourceInput) (*plugin.Api return &plugin.ApiResourceOutput{Body: scopeConfig.Unwrap()}, nil } +func (pa *pluginAPI) GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + db := basicRes.GetDal() + configId, err := strconv.ParseUint(input.Params["id"], 10, 64) + if err != nil { + return nil, errors.BadInput.New("invalid configId") + } + + ps := &coreModels.ProjectScopeOutput{} + projectMap := make(map[string]*coreModels.ProjectScope) + // 1. get all scopes that are using the scopeConfigId + scopes := models.NewDynamicScopeModel(pa.scopeType.NewSlice()) + err = api.CallDB(db.All, scopes, dal.Where("scope_config_id = ?", configId)) + if err != nil { + return nil, errors.Default.Wrap(err, "no scope config with given id") + } + for _, s := range scopes.UnwrapSlice() { + // 2. get blueprint id by connection id and scope id + scope := models.NewDynamicScopeModel(pa.scopeType) + _ = scope.From(s) + // result = append(result, scope) + bpScope := []*coreModels.BlueprintScope{} + err = db.All(&bpScope, + dal.Where("plugin_name = ? and connection_id = ? and scope_id = ?", input.Params["plugin"], scope.ConnectionId(), scope.ScopeId()), + ) + if err != nil { + return nil, errors.Default.Wrap(err, "no blueprint scope with given id") + } + for _, bs := range bpScope { + // 3. get project details by blueprint id + bp := coreModels.Blueprint{} + err = db.All(&bp, + dal.Where("id = ?", bs.BlueprintId), + ) + if err != nil { + return nil, errors.Default.Wrap(err, "no blueprint with given id") + } + if project, exists := projectMap[bp.ProjectName]; exists { + project.Scopes = append(project.Scopes, struct { + ScopeID string `json:"scopeId"` + }{ScopeID: bs.ScopeId}) + } else { + projectMap[bp.ProjectName] = &coreModels.ProjectScope{ + Name: bp.ProjectName, + Scopes: []struct { + ScopeID string `json:"scopeId"` + }{ + {ScopeID: bs.ScopeId}, + }, + } + } + } + } + // 4. combine all projects + for _, project := range projectMap { + ps.Projects = append(ps.Projects, *project) + } + ps.Count = len(ps.Projects) + + return &plugin.ApiResourceOutput{Body: ps}, nil +} + func (pa *pluginAPI) ListScopeConfigs(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { scopeConfigs := pa.scopeConfigType.NewSlice() limit, offset := api.GetLimitOffset(input.Query, "pageSize", "page") From f860998603217114cddcce0a4304b7b141c5da5e Mon Sep 17 00:00:00 2001 From: abeizn Date: Tue, 30 Apr 2024 12:06:10 +0800 Subject: [PATCH 2/2] fix: rename getProjects --- .../helpers/pluginhelper/api/ds_scope_config_api_helper.go | 4 ++-- backend/helpers/srvhelper/scope_config_service_helper.go | 2 +- backend/plugins/azuredevops_go/api/scope_config_api.go | 6 +++--- backend/plugins/azuredevops_go/impl/impl.go | 2 +- backend/plugins/bamboo/api/scope_config_api.go | 6 +++--- backend/plugins/bamboo/impl/impl.go | 2 +- backend/plugins/bitbucket/api/scope_config_api.go | 6 +++--- backend/plugins/bitbucket/impl/impl.go | 2 +- backend/plugins/bitbucket_server/api/scope_config_api.go | 6 +++--- backend/plugins/bitbucket_server/impl/impl.go | 2 +- backend/plugins/circleci/api/scope_config_api.go | 6 +++--- backend/plugins/circleci/impl/impl.go | 2 +- backend/plugins/github/api/scope_config_api.go | 6 +++--- backend/plugins/github/impl/impl.go | 2 +- backend/plugins/gitlab/api/scope_config_api.go | 6 +++--- backend/plugins/gitlab/impl/impl.go | 2 +- backend/plugins/jenkins/api/scope_config_api.go | 6 +++--- backend/plugins/jenkins/impl/impl.go | 2 +- backend/plugins/jira/api/scope_config_api.go | 6 +++--- backend/plugins/jira/impl/impl.go | 2 +- backend/plugins/tapd/api/scope_config_api.go | 6 +++--- backend/plugins/tapd/impl/impl.go | 2 +- backend/plugins/trello/api/scope_config_api.go | 6 +++--- backend/plugins/trello/impl/impl.go | 2 +- backend/plugins/zentao/api/scope_config_api.go | 6 +++--- backend/plugins/zentao/impl/impl.go | 2 +- backend/server/services/remote/plugin/default_api.go | 2 +- backend/server/services/remote/plugin/scope_config_api.go | 2 +- 28 files changed, 53 insertions(+), 53 deletions(-) diff --git a/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go b/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go index 2809d8523ce..c93144e455f 100644 --- a/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go +++ b/backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go @@ -57,13 +57,13 @@ func (connApi *DsScopeConfigApiHelper[C, S, SC]) GetAll(input *plugin.ApiResourc }, nil } -func (connApi *DsScopeConfigApiHelper[C, S, SC]) GetProjects(input *plugin.ApiResourceInput) (out *plugin.ApiResourceOutput, err errors.Error) { +func (connApi *DsScopeConfigApiHelper[C, S, SC]) GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (out *plugin.ApiResourceOutput, err errors.Error) { var scopeConfig *SC scopeConfig, err = connApi.FindByPk(input) if err != nil { return nil, err } - projectDetails := errors.Must1(connApi.ScopeConfigSrvHelper.GetProjects(input.Params["plugin"], scopeConfig)) + projectDetails := errors.Must1(connApi.ScopeConfigSrvHelper.GetProjectsByScopeConfig(input.Params["plugin"], scopeConfig)) return &plugin.ApiResourceOutput{ Body: projectDetails, }, nil diff --git a/backend/helpers/srvhelper/scope_config_service_helper.go b/backend/helpers/srvhelper/scope_config_service_helper.go index 3df6c8fd0ef..59d8bc93f8e 100644 --- a/backend/helpers/srvhelper/scope_config_service_helper.go +++ b/backend/helpers/srvhelper/scope_config_service_helper.go @@ -56,7 +56,7 @@ func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) GetAllByConnectionId(conne return scopeConfigs, err } -func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) GetProjects(pluginName string, scopeConfig *SC) (*models.ProjectScopeOutput, errors.Error) { +func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) GetProjectsByScopeConfig(pluginName string, scopeConfig *SC) (*models.ProjectScopeOutput, errors.Error) { ps := &models.ProjectScopeOutput{} projectMap := make(map[string]*models.ProjectScope) // 1. get all scopes that are using the scopeConfigId diff --git a/backend/plugins/azuredevops_go/api/scope_config_api.go b/backend/plugins/azuredevops_go/api/scope_config_api.go index 081a728e916..6294cb5c7da 100644 --- a/backend/plugins/azuredevops_go/api/scope_config_api.go +++ b/backend/plugins/azuredevops_go/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/azuredevops @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/azuredevops/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/azuredevops_go/impl/impl.go b/backend/plugins/azuredevops_go/impl/impl.go index cfb9f364a36..44cc01e5238 100644 --- a/backend/plugins/azuredevops_go/impl/impl.go +++ b/backend/plugins/azuredevops_go/impl/impl.go @@ -245,7 +245,7 @@ func (p Azuredevops) ApiResources() map[string]map[string]plugin.ApiResourceHand "GET": api.Proxy, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/bamboo/api/scope_config_api.go b/backend/plugins/bamboo/api/scope_config_api.go index 31fa0a7d4dc..c74ac3a3f98 100644 --- a/backend/plugins/bamboo/api/scope_config_api.go +++ b/backend/plugins/bamboo/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/bamboo @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/bamboo/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/bamboo/impl/impl.go b/backend/plugins/bamboo/impl/impl.go index b28ed481ccb..bf5b10747a3 100644 --- a/backend/plugins/bamboo/impl/impl.go +++ b/backend/plugins/bamboo/impl/impl.go @@ -249,7 +249,7 @@ func (p Bamboo) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "GET": api.Proxy, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/bitbucket/api/scope_config_api.go b/backend/plugins/bitbucket/api/scope_config_api.go index ab0a142fcd2..1e737951eef 100644 --- a/backend/plugins/bitbucket/api/scope_config_api.go +++ b/backend/plugins/bitbucket/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/bitbucket @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/bitbucket/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/bitbucket/impl/impl.go b/backend/plugins/bitbucket/impl/impl.go index 48c1ab333f1..933a11a4c6d 100644 --- a/backend/plugins/bitbucket/impl/impl.go +++ b/backend/plugins/bitbucket/impl/impl.go @@ -239,7 +239,7 @@ func (p Bitbucket) ApiResources() map[string]map[string]plugin.ApiResourceHandle "DELETE": api.DeleteScopeConfig, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/bitbucket_server/api/scope_config_api.go b/backend/plugins/bitbucket_server/api/scope_config_api.go index 30f4ead76f0..3e0a3d3478c 100644 --- a/backend/plugins/bitbucket_server/api/scope_config_api.go +++ b/backend/plugins/bitbucket_server/api/scope_config_api.go @@ -86,7 +86,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/bitbucket_server @@ -96,8 +96,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/bitbucket_server/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/bitbucket_server/impl/impl.go b/backend/plugins/bitbucket_server/impl/impl.go index 1dcc54c2343..bc2366d18ac 100644 --- a/backend/plugins/bitbucket_server/impl/impl.go +++ b/backend/plugins/bitbucket_server/impl/impl.go @@ -202,7 +202,7 @@ func (p BitbucketServer) ApiResources() map[string]map[string]plugin.ApiResource "DELETE": api.DeleteScopeConfig, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/circleci/api/scope_config_api.go b/backend/plugins/circleci/api/scope_config_api.go index c455a609b96..5daa5ba44ba 100644 --- a/backend/plugins/circleci/api/scope_config_api.go +++ b/backend/plugins/circleci/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/circleci @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/circleci/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/circleci/impl/impl.go b/backend/plugins/circleci/impl/impl.go index 3d68cf770fd..0c1ad8529bd 100644 --- a/backend/plugins/circleci/impl/impl.go +++ b/backend/plugins/circleci/impl/impl.go @@ -208,7 +208,7 @@ func (p Circleci) ApiResources() map[string]map[string]plugin.ApiResourceHandler "DELETE": api.DeleteScopeConfig, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/github/api/scope_config_api.go b/backend/plugins/github/api/scope_config_api.go index b2fd7f7af45..b109341e771 100644 --- a/backend/plugins/github/api/scope_config_api.go +++ b/backend/plugins/github/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/github @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/github/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/github/impl/impl.go b/backend/plugins/github/impl/impl.go index bcb964ec1a4..f0bce7313a4 100644 --- a/backend/plugins/github/impl/impl.go +++ b/backend/plugins/github/impl/impl.go @@ -221,7 +221,7 @@ func (p Github) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "GET": api.Proxy, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/gitlab/api/scope_config_api.go b/backend/plugins/gitlab/api/scope_config_api.go index eea51490885..a97c5050c25 100644 --- a/backend/plugins/gitlab/api/scope_config_api.go +++ b/backend/plugins/gitlab/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/gitlab @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/gitlab/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/gitlab/impl/impl.go b/backend/plugins/gitlab/impl/impl.go index 93e17160730..166624536e1 100644 --- a/backend/plugins/gitlab/impl/impl.go +++ b/backend/plugins/gitlab/impl/impl.go @@ -272,7 +272,7 @@ func (p Gitlab) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "GET": api.Proxy, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/jenkins/api/scope_config_api.go b/backend/plugins/jenkins/api/scope_config_api.go index a90a7285537..9e46d05d8c0 100644 --- a/backend/plugins/jenkins/api/scope_config_api.go +++ b/backend/plugins/jenkins/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/jenkins @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/jenkins/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/jenkins/impl/impl.go b/backend/plugins/jenkins/impl/impl.go index cd0b0f3530b..c33e50daa25 100644 --- a/backend/plugins/jenkins/impl/impl.go +++ b/backend/plugins/jenkins/impl/impl.go @@ -219,7 +219,7 @@ func (p Jenkins) ApiResources() map[string]map[string]plugin.ApiResourceHandler "GET": api.Proxy, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/jira/api/scope_config_api.go b/backend/plugins/jira/api/scope_config_api.go index a6f0e072af7..dae0514ef32 100644 --- a/backend/plugins/jira/api/scope_config_api.go +++ b/backend/plugins/jira/api/scope_config_api.go @@ -111,7 +111,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/jira @@ -121,8 +121,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/jira/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/jira/impl/impl.go b/backend/plugins/jira/impl/impl.go index 17d38d3f649..6eeb146cedc 100644 --- a/backend/plugins/jira/impl/impl.go +++ b/backend/plugins/jira/impl/impl.go @@ -324,7 +324,7 @@ func (p Jira) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "GET": api.GetCommitsURLs, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, "generate-regex": { "POST": api.GenRegex, diff --git a/backend/plugins/tapd/api/scope_config_api.go b/backend/plugins/tapd/api/scope_config_api.go index 15e7d0235ab..25d10ebe088 100644 --- a/backend/plugins/tapd/api/scope_config_api.go +++ b/backend/plugins/tapd/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/tapd @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/tapd/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/tapd/impl/impl.go b/backend/plugins/tapd/impl/impl.go index 38f5c2656ac..ad81640193c 100644 --- a/backend/plugins/tapd/impl/impl.go +++ b/backend/plugins/tapd/impl/impl.go @@ -304,7 +304,7 @@ func (p Tapd) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "DELETE": api.DeleteScopeConfig, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/trello/api/scope_config_api.go b/backend/plugins/trello/api/scope_config_api.go index 20ef0d70bc3..026e8ccc868 100644 --- a/backend/plugins/trello/api/scope_config_api.go +++ b/backend/plugins/trello/api/scope_config_api.go @@ -78,7 +78,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/trello @@ -88,8 +88,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/trello/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/trello/impl/impl.go b/backend/plugins/trello/impl/impl.go index e171c606053..35a646b5926 100644 --- a/backend/plugins/trello/impl/impl.go +++ b/backend/plugins/trello/impl/impl.go @@ -190,7 +190,7 @@ func (p Trello) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "PUT": api.PutScopes, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/plugins/zentao/api/scope_config_api.go b/backend/plugins/zentao/api/scope_config_api.go index 28eef394b7a..9ce1a614d40 100644 --- a/backend/plugins/zentao/api/scope_config_api.go +++ b/backend/plugins/zentao/api/scope_config_api.go @@ -82,7 +82,7 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp return dsHelper.ScopeConfigApi.GetAll(input) } -// GetProjects return projects details related by scope config +// GetProjectsByScopeConfig return projects details related by scope config // @Summary return all related projects // @Description return all related projects // @Tags plugins/zentao @@ -92,8 +92,8 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Failure 400 {object} shared.ApiBody "Bad Request" // @Failure 500 {object} shared.ApiBody "Internal Error" // @Router /plugins/zentao/scope-config/{scopeConfigId}/projects [GET] -func GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { - return dsHelper.ScopeConfigApi.GetProjects(input) +func GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input) } // DeleteScopeConfig delete a scope config diff --git a/backend/plugins/zentao/impl/impl.go b/backend/plugins/zentao/impl/impl.go index 36e9d0ff9b3..933c296ab4b 100644 --- a/backend/plugins/zentao/impl/impl.go +++ b/backend/plugins/zentao/impl/impl.go @@ -283,7 +283,7 @@ func (p Zentao) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "GET": api.Proxy, }, "scope-config/:scopeConfigId/projects": { - "GET": api.GetProjects, + "GET": api.GetProjectsByScopeConfig, }, } } diff --git a/backend/server/services/remote/plugin/default_api.go b/backend/server/services/remote/plugin/default_api.go index 84f1bcdb019..83ead132798 100644 --- a/backend/server/services/remote/plugin/default_api.go +++ b/backend/server/services/remote/plugin/default_api.go @@ -94,7 +94,7 @@ func GetDefaultAPI( "GET": papi.SearchRemoteScopes, }, "scope-config/:id/projects": { - "GET": papi.GetProjects, + "GET": papi.GetProjectsByScopeConfig, }, } papi.createScopeHelper() diff --git a/backend/server/services/remote/plugin/scope_config_api.go b/backend/server/services/remote/plugin/scope_config_api.go index 44f85681f35..952f0e42c0a 100644 --- a/backend/server/services/remote/plugin/scope_config_api.go +++ b/backend/server/services/remote/plugin/scope_config_api.go @@ -90,7 +90,7 @@ func (pa *pluginAPI) GetScopeConfig(input *plugin.ApiResourceInput) (*plugin.Api return &plugin.ApiResourceOutput{Body: scopeConfig.Unwrap()}, nil } -func (pa *pluginAPI) GetProjects(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { +func (pa *pluginAPI) GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { db := basicRes.GetDal() configId, err := strconv.ParseUint(input.Params["id"], 10, 64) if err != nil {