Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backend/core/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
12 changes: 12 additions & 0 deletions backend/helpers/pluginhelper/api/ds_scope_config_api_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func (connApi *DsScopeConfigApiHelper[C, S, SC]) GetAll(input *plugin.ApiResourc
}, nil
}

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.GetProjectsByScopeConfig(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)
Expand Down
56 changes: 56 additions & 0 deletions backend/helpers/srvhelper/scope_config_service_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -55,6 +56,61 @@ func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) GetAllByConnectionId(conne
return scopeConfigs, err
}

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
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
Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/azuredevops_go/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
6 changes: 5 additions & 1 deletion backend/plugins/azuredevops_go/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/bamboo/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/bamboo/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/bitbucket/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/bitbucket/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/bitbucket_server/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/bitbucket_server/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/circleci/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/circleci/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/github/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/github/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/gitlab/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/gitlab/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/jenkins/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/jenkins/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions backend/plugins/jira/api/scope_config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetProjectsByScopeConfig 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 GetProjectsByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/jira/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetProjectsByScopeConfig,
},
"generate-regex": {
"POST": api.GenRegex,
},
Expand Down
Loading