You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2024/04/30 04:13:27 UTC

(incubator-devlake) branch main updated: feat: support get related projects by scope config (#7414)

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 24abaeffd feat: support get related projects by scope config (#7414)
24abaeffd is described below

commit 24abaeffddd403eb981f91864f04127dd6e713a4
Author: abeizn <zi...@merico.dev>
AuthorDate: Tue Apr 30 12:13:22 2024 +0800

    feat: support get related projects by scope config (#7414)
    
    * feat: support get related projects by scope config
    
    * fix: rename getProjects
---
 backend/core/models/project.go                     | 12 ++++
 .../pluginhelper/api/ds_scope_config_api_helper.go | 12 ++++
 .../srvhelper/scope_config_service_helper.go       | 56 +++++++++++++++++++
 .../plugins/azuredevops_go/api/scope_config_api.go | 14 +++++
 backend/plugins/azuredevops_go/impl/impl.go        |  6 +-
 backend/plugins/bamboo/api/scope_config_api.go     | 14 +++++
 backend/plugins/bamboo/impl/impl.go                |  3 +
 backend/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 +
 backend/plugins/circleci/api/scope_config_api.go   | 14 +++++
 backend/plugins/circleci/impl/impl.go              |  3 +
 backend/plugins/github/api/scope_config_api.go     | 14 +++++
 backend/plugins/github/impl/impl.go                |  3 +
 backend/plugins/gitlab/api/scope_config_api.go     | 14 +++++
 backend/plugins/gitlab/impl/impl.go                |  3 +
 backend/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 +
 backend/plugins/trello/api/scope_config_api.go     | 14 +++++
 backend/plugins/trello/impl/impl.go                |  3 +
 backend/plugins/zentao/api/scope_config_api.go     | 14 +++++
 backend/plugins/zentao/impl/impl.go                |  3 +
 .../server/services/remote/plugin/default_api.go   |  3 +
 .../services/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 0c7723891..f5cf6779a 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 6e76341ef..c93144e45 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]) 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)
diff --git a/backend/helpers/srvhelper/scope_config_service_helper.go b/backend/helpers/srvhelper/scope_config_service_helper.go
index 796ba29a5..59d8bc93f 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]) 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
diff --git a/backend/plugins/azuredevops_go/api/scope_config_api.go b/backend/plugins/azuredevops_go/api/scope_config_api.go
index be02fb2f0..6294cb5c7 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)
 }
 
+// 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
diff --git a/backend/plugins/azuredevops_go/impl/impl.go b/backend/plugins/azuredevops_go/impl/impl.go
index 2ada8fd59..44cc01e52 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/bamboo/api/scope_config_api.go b/backend/plugins/bamboo/api/scope_config_api.go
index 2cc545645..c74ac3a3f 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)
 }
 
+// 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
diff --git a/backend/plugins/bamboo/impl/impl.go b/backend/plugins/bamboo/impl/impl.go
index ddec6bd6c..bf5b10747 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/bitbucket/api/scope_config_api.go b/backend/plugins/bitbucket/api/scope_config_api.go
index 1e894165c..1e737951e 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)
 }
 
+// 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
diff --git a/backend/plugins/bitbucket/impl/impl.go b/backend/plugins/bitbucket/impl/impl.go
index f4cdb5f90..933a11a4c 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/bitbucket_server/api/scope_config_api.go b/backend/plugins/bitbucket_server/api/scope_config_api.go
index 6ca92f84e..3e0a3d347 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)
 }
 
+// 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
diff --git a/backend/plugins/bitbucket_server/impl/impl.go b/backend/plugins/bitbucket_server/impl/impl.go
index d3ec499c8..bc2366d18 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/circleci/api/scope_config_api.go b/backend/plugins/circleci/api/scope_config_api.go
index 28dff9ec4..5daa5ba44 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)
 }
 
+// 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
diff --git a/backend/plugins/circleci/impl/impl.go b/backend/plugins/circleci/impl/impl.go
index 3e2f55dd1..0c1ad8529 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/github/api/scope_config_api.go b/backend/plugins/github/api/scope_config_api.go
index 57d083066..b109341e7 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)
 }
 
+// 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
diff --git a/backend/plugins/github/impl/impl.go b/backend/plugins/github/impl/impl.go
index dc6b54967..f0bce7313 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/gitlab/api/scope_config_api.go b/backend/plugins/gitlab/api/scope_config_api.go
index 4ed8b36c0..a97c5050c 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)
 }
 
+// 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
diff --git a/backend/plugins/gitlab/impl/impl.go b/backend/plugins/gitlab/impl/impl.go
index ad99ec501..166624536 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/jenkins/api/scope_config_api.go b/backend/plugins/jenkins/api/scope_config_api.go
index 2a9c82df7..9e46d05d8 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)
 }
 
+// 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
diff --git a/backend/plugins/jenkins/impl/impl.go b/backend/plugins/jenkins/impl/impl.go
index 7042a5b4b..c33e50daa 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/jira/api/scope_config_api.go b/backend/plugins/jira/api/scope_config_api.go
index 58eb46ae4..dae0514ef 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)
 }
 
+// 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
diff --git a/backend/plugins/jira/impl/impl.go b/backend/plugins/jira/impl/impl.go
index 5dd315393..6eeb146ce 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.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 abca28949..25d10ebe0 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)
 }
 
+// GetProjectsByScopeConfig 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 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
diff --git a/backend/plugins/tapd/impl/impl.go b/backend/plugins/tapd/impl/impl.go
index 326da6d16..ad8164019 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/trello/api/scope_config_api.go b/backend/plugins/trello/api/scope_config_api.go
index 5a372cd34..026e8ccc8 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)
 }
 
+// GetProjectsByScopeConfig 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 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
diff --git a/backend/plugins/trello/impl/impl.go b/backend/plugins/trello/impl/impl.go
index 49dbb7c9a..35a646b59 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/plugins/zentao/api/scope_config_api.go b/backend/plugins/zentao/api/scope_config_api.go
index 53b40e657..9ce1a614d 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)
 }
 
+// GetProjectsByScopeConfig 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 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
diff --git a/backend/plugins/zentao/impl/impl.go b/backend/plugins/zentao/impl/impl.go
index fa3675346..933c296ab 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.GetProjectsByScopeConfig,
+		},
 	}
 }
 
diff --git a/backend/server/services/remote/plugin/default_api.go b/backend/server/services/remote/plugin/default_api.go
index f891a5a20..83ead1327 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.GetProjectsByScopeConfig,
+		},
 	}
 	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 c772e9fa0..952f0e42c 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) GetProjectsByScopeConfig(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")