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/03/28 08:18:45 UTC
(incubator-devlake) branch kw-5519-circleci-dshelper created (now 03897da0e)
This is an automated email from the ASF dual-hosted git repository.
klesh pushed a change to branch kw-5519-circleci-dshelper
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
at 03897da0e refactor: 5519 circleci adopts new dshelpers
This branch includes the following new commits:
new 03897da0e refactor: 5519 circleci adopts new dshelpers
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-devlake) 01/01: refactor: 5519 circleci adopts new dshelpers
Posted by kl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch kw-5519-circleci-dshelper
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 03897da0ee9a4725fc169d4b49f239f7dfe5dfb5
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Thu Mar 28 16:18:29 2024 +0800
refactor: 5519 circleci adopts new dshelpers
---
backend/helpers/srvhelper/pagination.go | 2 +
backend/plugins/bamboo/api/blueprint_v200.go | 2 +-
.../api/{remote.go => remote_api.go} | 0
.../api/{scope_config.go => scope_config_api.go} | 0
backend/plugins/circleci/api/blueprint200.go | 93 +++++++++-------------
.../api/{connection.go => connection_api.go} | 55 +++----------
backend/plugins/circleci/api/init.go | 48 +++--------
.../circleci/api/{remote.go => remote_api.go} | 59 +++++++++-----
.../circleci/api/{scope.go => scope_api.go} | 69 ++++++++--------
.../api/{scope_config.go => scope_config_api.go} | 66 +++++++--------
backend/plugins/circleci/impl/impl.go | 10 +--
backend/plugins/circleci/tasks/task_data.go | 6 +-
12 files changed, 173 insertions(+), 237 deletions(-)
diff --git a/backend/helpers/srvhelper/pagination.go b/backend/helpers/srvhelper/pagination.go
index 8b6b96300..180d93357 100644
--- a/backend/helpers/srvhelper/pagination.go
+++ b/backend/helpers/srvhelper/pagination.go
@@ -40,3 +40,5 @@ func (pagination *Pagination) GetLimit() int {
func (pagination *Pagination) GetOffset() int {
return (pagination.GetPage() - 1) * pagination.GetLimit()
}
+
+type NoPagintation struct{}
diff --git a/backend/plugins/bamboo/api/blueprint_v200.go b/backend/plugins/bamboo/api/blueprint_v200.go
index ca7ae2bec..dd6ce9135 100644
--- a/backend/plugins/bamboo/api/blueprint_v200.go
+++ b/backend/plugins/bamboo/api/blueprint_v200.go
@@ -77,7 +77,7 @@ func makePipelinePlanV200(
subtaskMetas,
scopeConfig.Entities,
models.BambooOptions{
- ConnectionId: scope.ConnectionId,
+ ConnectionId: connection.ID,
PlanKey: scope.PlanKey,
},
)
diff --git a/backend/plugins/bitbucket_server/api/remote.go b/backend/plugins/bitbucket_server/api/remote_api.go
similarity index 100%
rename from backend/plugins/bitbucket_server/api/remote.go
rename to backend/plugins/bitbucket_server/api/remote_api.go
diff --git a/backend/plugins/bitbucket_server/api/scope_config.go b/backend/plugins/bitbucket_server/api/scope_config_api.go
similarity index 100%
rename from backend/plugins/bitbucket_server/api/scope_config.go
rename to backend/plugins/bitbucket_server/api/scope_config_api.go
diff --git a/backend/plugins/circleci/api/blueprint200.go b/backend/plugins/circleci/api/blueprint200.go
index 57bb1e6ed..5bc475bc4 100644
--- a/backend/plugins/circleci/api/blueprint200.go
+++ b/backend/plugins/circleci/api/blueprint200.go
@@ -18,19 +18,17 @@ limitations under the License.
package api
import (
- "fmt"
-
"github.com/apache/incubator-devlake/core/models/domainlayer/devops"
"github.com/apache/incubator-devlake/plugins/circleci/models"
+ "github.com/apache/incubator-devlake/plugins/circleci/tasks"
- "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/models/domainlayer"
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/core/utils"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/apache/incubator-devlake/helpers/srvhelper"
)
func MakeDataSourcePipelinePlanV200(
@@ -38,87 +36,70 @@ func MakeDataSourcePipelinePlanV200(
connectionId uint64,
bpScopes []*coreModels.BlueprintScope,
) (coreModels.PipelinePlan, []plugin.Scope, errors.Error) {
- plan := make(coreModels.PipelinePlan, len(bpScopes))
- plan, err := makeDataSourcePipelinePlanV200(subtaskMetas, plan, bpScopes, connectionId)
+ connection, err := dsHelper.ConnSrv.FindByPk(connectionId)
if err != nil {
return nil, nil, err
}
- scopes, err := makeScopesV200(bpScopes, connectionId)
+ scopeDetails, err := dsHelper.ScopeSrv.MapScopeDetails(connectionId, bpScopes)
+
+ plan, err := makePipelinePlanV200(subtaskMetas, scopeDetails, connection)
if err != nil {
return nil, nil, err
}
+ scopes, err := makeScopesV200(scopeDetails, connection)
return plan, scopes, nil
}
-func makeDataSourcePipelinePlanV200(
+func makePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
- plan coreModels.PipelinePlan,
- bpScopes []*coreModels.BlueprintScope,
- connectionId uint64,
+ scopeDetails []*srvhelper.ScopeDetail[models.CircleciProject, models.CircleciScopeConfig],
+ connection *models.CircleciConnection,
) (coreModels.PipelinePlan, errors.Error) {
- for i, bpScope := range bpScopes {
+ plan := make(coreModels.PipelinePlan, len(scopeDetails))
+ for i, scopeDetail := range scopeDetails {
stage := plan[i]
if stage == nil {
stage = coreModels.PipelineStage{}
}
- // construct task options for circleci
- options := make(map[string]interface{})
- project, err := scopeHelper.DbHelper().GetScope(connectionId, bpScope.ScopeId)
- if err != nil {
- return nil, err
- }
- options["projectSlug"] = project.Slug
- options["connectionId"] = connectionId
-
- // get scope config from db
- _, scopeConfig, err := scopeHelper.DbHelper().GetScopeAndConfig(connectionId, bpScope.ScopeId)
- if err != nil {
- return nil, err
- }
- subtasks, err := helper.MakePipelinePlanSubtasks(subtaskMetas, scopeConfig.Entities)
+ scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
+ // construct task options for circleci
+ task, err := helper.MakePipelinePlanTask(
+ "circleci",
+ subtaskMetas,
+ scopeConfig.Entities,
+ tasks.CircleciOptions{
+ ConnectionId: scope.ConnectionId,
+ ProjectSlug: scope.Slug,
+ },
+ )
if err != nil {
return nil, err
}
- stage = append(stage, &coreModels.PipelineTask{
- Plugin: "circleci",
- Subtasks: subtasks,
- Options: options,
- })
+ stage = append(stage, task)
plan[i] = stage
}
return plan, nil
}
-func makeScopesV200(bpScopes []*coreModels.BlueprintScope, connectionId uint64) ([]plugin.Scope, errors.Error) {
- scopes := make([]plugin.Scope, 0)
- for _, bpScope := range bpScopes {
- project := &models.CircleciProject{}
- // get project from db
- err := basicRes.GetDal().First(project,
- dal.Where(`connection_id = ? and id = ?`,
- connectionId, bpScope.ScopeId))
- if err != nil {
- return nil, errors.Default.Wrap(err, fmt.Sprintf("fail to find project %s", bpScope.ScopeId))
- }
- // get scope config from db
- _, scopeConfig, err := scopeHelper.DbHelper().GetScopeAndConfig(connectionId, bpScope.ScopeId)
- if err != nil {
- return nil, err
- }
+func makeScopesV200(
+ scopeDetails []*srvhelper.ScopeDetail[models.CircleciProject, models.CircleciScopeConfig],
+ connection *models.CircleciConnection,
+) ([]plugin.Scope, errors.Error) {
+ scopes := make([]plugin.Scope, 0, len(scopeDetails))
- // add board to scopes
+ idgen := didgen.NewDomainIdGenerator(&models.CircleciProject{})
+ for _, scopeDetail := range scopeDetails {
+ scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
+ id := idgen.Generate(connection.ID, scope.Slug)
+
+ // add cicd_scope to scopes
if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CICD) {
- domainBoard := &devops.CicdScope{
- DomainEntity: domainlayer.DomainEntity{
- Id: didgen.NewDomainIdGenerator(&models.CircleciProject{}).Generate(project.ConnectionId, project.Id),
- },
- Name: project.Name,
- }
- scopes = append(scopes, domainBoard)
+ scopes = append(scopes, devops.NewCicdScope(id, scope.Slug))
}
}
+
return scopes, nil
}
diff --git a/backend/plugins/circleci/api/connection.go b/backend/plugins/circleci/api/connection_api.go
similarity index 77%
rename from backend/plugins/circleci/api/connection.go
rename to backend/plugins/circleci/api/connection_api.go
index 9b8d75cf5..0b644d14d 100644
--- a/backend/plugins/circleci/api/connection.go
+++ b/backend/plugins/circleci/api/connection_api.go
@@ -33,7 +33,7 @@ type CircleciTestConnResponse struct {
shared.ApiBody
}
-func testConnection(ctx context.Context, connection models.CircleciConn) (*CircleciTestConnResponse, errors.Error) {
+func testConnection(ctx context.Context, connection *models.CircleciConnection) (*CircleciTestConnResponse, errors.Error) {
// validate
if vld != nil {
if err := vld.Struct(connection); err != nil {
@@ -41,7 +41,7 @@ func testConnection(ctx context.Context, connection models.CircleciConn) (*Circl
}
}
// test connection
- apiClient, err := api.NewApiClientFromConnection(ctx, basicRes, &connection)
+ apiClient, err := api.NewApiClientFromConnection(ctx, basicRes, connection)
if err != nil {
return nil, err
}
@@ -73,8 +73,7 @@ func testConnection(ctx context.Context, connection models.CircleciConn) (*Circl
// @Router /plugins/circleci/test [POST]
func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
// process input
- var connection models.CircleciConn
- err := api.Decode(input.Body, &connection, vld)
+ connection, err := dsHelper.ConnApi.GetMergedConnection(input)
if err != nil {
return nil, err
}
@@ -96,8 +95,7 @@ func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/circleci/connections/{connectionId}/test [POST]
func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- connection := &models.CircleciConnection{}
- err := connectionHelper.First(connection, input.Params)
+ connection, err := dsHelper.ConnApi.GetMergedConnection(input)
if err != nil {
return nil, errors.BadInput.Wrap(err, "find connection from db")
}
@@ -105,7 +103,7 @@ func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResource
return nil, err
}
// test connection
- result, err := testConnection(context.TODO(), connection.CircleciConn)
+ result, err := testConnection(context.TODO(), connection)
if err != nil {
return nil, plugin.WrapTestConnectionErrResp(basicRes, err)
}
@@ -121,13 +119,7 @@ func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResource
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/circleci/connections [POST]
func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- // update from request and save to database
- connection := &models.CircleciConnection{}
- err := connectionHelper.Create(connection, input)
- if err != nil {
- return nil, err
- }
- return &plugin.ApiResourceOutput{Body: connection.Sanitize(), Status: http.StatusOK}, nil
+ return dsHelper.ConnApi.Post(input)
}
// PatchConnection @Summary patch circleci connection
@@ -139,17 +131,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/circleci/connections/{connectionId} [PATCH]
func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- connection := &models.CircleciConnection{}
- if err := connectionHelper.First(&connection, input.Params); err != nil {
- return nil, err
- }
- if err := (&models.CircleciConnection{}).MergeFromRequest(connection, input.Body); err != nil {
- return nil, errors.Convert(err)
- }
- if err := connectionHelper.SaveWithCreateOrUpdate(connection); err != nil {
- return nil, err
- }
- return &plugin.ApiResourceOutput{Body: connection.Sanitize()}, nil
+ return dsHelper.ConnApi.Patch(input)
}
// DeleteConnection @Summary delete a circleci connection
@@ -160,14 +142,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/circleci/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- conn := &models.CircleciConnection{}
- output, err := connectionHelper.Delete(conn, input)
- if err != nil {
- return output, err
- }
- output.Body = conn.Sanitize()
- return output, nil
-
+ return dsHelper.ConnApi.Delete(input)
}
// ListConnections @Summary get all circleci connections
@@ -178,15 +153,7 @@ func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/circleci/connections [GET]
func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- var connections []models.CircleciConnection
- err := connectionHelper.List(&connections)
- if err != nil {
- return nil, err
- }
- for idx, c := range connections {
- connections[idx] = c.Sanitize()
- }
- return &plugin.ApiResourceOutput{Body: connections, Status: http.StatusOK}, nil
+ return dsHelper.ConnApi.GetAll(input)
}
// GetConnection @Summary get circleci connection detail
@@ -197,7 +164,5 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/circleci/connections/{connectionId} [GET]
func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- connection := &models.CircleciConnection{}
- err := connectionHelper.First(connection, input.Params)
- return &plugin.ApiResourceOutput{Body: connection.Sanitize()}, err
+ return dsHelper.ConnApi.GetDetail(input)
}
diff --git a/backend/plugins/circleci/api/init.go b/backend/plugins/circleci/api/init.go
index e066e1584..b57b994c9 100644
--- a/backend/plugins/circleci/api/init.go
+++ b/backend/plugins/circleci/api/init.go
@@ -20,53 +20,25 @@ package api
import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/plugins/circleci/models"
"github.com/go-playground/validator/v10"
)
-var vld *validator.Validate
-var connectionHelper *helper.ConnectionApiHelper
-var scopeHelper *helper.ScopeApiHelper[models.CircleciConnection, models.CircleciProject, models.CircleciScopeConfig]
-var scHelper *helper.ScopeConfigHelper[models.CircleciScopeConfig, *models.CircleciScopeConfig]
-var remoteHelper *helper.RemoteApiHelper[models.CircleciConnection, models.CircleciProject, RemoteProject, helper.NoRemoteGroupResponse]
var basicRes context.BasicRes
+var vld *validator.Validate
+
var dsHelper *helper.DsHelper[models.CircleciConnection, models.CircleciProject, models.CircleciScopeConfig]
+var raProxy *api.DsRemoteApiProxyHelper[models.CircleciConnection]
+var raScopeList *api.DsRemoteApiScopeListHelper[models.CircleciConnection, models.CircleciProject, srvhelper.NoPagintation]
+
+// var raScopeSearch *api.DsRemoteApiScopeSearchHelper[models.CircleciConnection, models.CircleciProject]
func Init(br context.BasicRes, p plugin.PluginMeta) {
basicRes = br
vld = validator.New()
- connectionHelper = helper.NewConnectionHelper(
- basicRes,
- vld,
- p.Name(),
- )
- params := &helper.ReflectionParameters{
- ScopeIdFieldName: "Id",
- ScopeIdColumnName: "id",
- RawScopeParamName: "Slug",
- SearchScopeParamName: "name",
- }
- scopeHelper = helper.NewScopeHelper[models.CircleciConnection, models.CircleciProject, models.CircleciScopeConfig](
- basicRes,
- vld,
- connectionHelper,
- helper.NewScopeDatabaseHelperImpl[models.CircleciConnection, models.CircleciProject, models.CircleciScopeConfig](
- basicRes, connectionHelper, params),
- params,
- nil,
- )
- remoteHelper = helper.NewRemoteHelper[models.CircleciConnection, models.CircleciProject, RemoteProject, helper.NoRemoteGroupResponse](
- basicRes,
- vld,
- connectionHelper,
- )
- scHelper = helper.NewScopeConfigHelper[models.CircleciScopeConfig, *models.CircleciScopeConfig](
- basicRes,
- vld,
- p.Name(),
- )
-
dsHelper = helper.NewDataSourceHelper[
models.CircleciConnection, models.CircleciProject, models.CircleciScopeConfig,
](
@@ -79,5 +51,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
nil,
nil,
)
-
+ raProxy = api.NewDsRemoteApiProxyHelper[models.CircleciConnection](dsHelper.ConnApi.ModelApiHelper)
+ raScopeList = api.NewDsRemoteApiScopeListHelper[models.CircleciConnection, models.CircleciProject, srvhelper.NoPagintation](raProxy, listCircleciRemoteScopes)
+ // raScopeSearch = api.NewDsRemoteApiScopeSearchHelper[models.CircleciConnection, models.CircleciProject](raProxy, searchCircleciProjects)
}
diff --git a/backend/plugins/circleci/api/remote.go b/backend/plugins/circleci/api/remote_api.go
similarity index 64%
rename from backend/plugins/circleci/api/remote.go
rename to backend/plugins/circleci/api/remote_api.go
index 8f743f1ea..5aa812fcb 100644
--- a/backend/plugins/circleci/api/remote.go
+++ b/backend/plugins/circleci/api/remote_api.go
@@ -18,19 +18,16 @@ limitations under the License.
package api
import (
- gocontext "context"
"net/http"
- "github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ dsmodels "github.com/apache/incubator-devlake/helpers/pluginhelper/api/models"
+ "github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/plugins/circleci/models"
)
-// RemoteApiScope
-var _ plugin.ApiScope = (*RemoteProject)(nil)
-
type RemoteProject struct {
Id string `json:"id"`
Name string `json:"name"`
@@ -39,7 +36,7 @@ type RemoteProject struct {
}
// ConvertApiScope implements plugin.ApiScope.
-func (c RemoteProject) ConvertApiScope() plugin.ToolLayerScope {
+func (c RemoteProject) ConvertApiScope() *models.CircleciProject {
return &models.CircleciProject{
Id: c.Id,
Name: c.Name,
@@ -48,22 +45,22 @@ func (c RemoteProject) ConvertApiScope() plugin.ToolLayerScope {
}
}
-func getRemoteProjects(
- basicRes context.BasicRes,
- gid string,
- queryData *api.RemoteQueryData,
- connection models.CircleciConnection,
-) ([]RemoteProject, errors.Error) {
+func listCircleciRemoteScopes(
+ connection *models.CircleciConnection,
+ apiClient plugin.ApiClient,
+ groupId string,
+ page srvhelper.NoPagintation,
+) (
+ children []dsmodels.DsRemoteApiScopeListEntry[models.CircleciProject],
+ nextPage *srvhelper.NoPagintation,
+ err errors.Error,
+) {
// create api client
- apiClient, err := api.NewApiClientFromConnection(gocontext.TODO(), basicRes, &connection)
- if err != nil {
- return nil, err
- }
res, err := apiClient.Get("private/me", nil, http.Header{
"Accept": []string{"application/json"},
})
if err != nil {
- return nil, err
+ return nil, nil, err
}
var projects struct {
@@ -71,11 +68,19 @@ func getRemoteProjects(
}
err = api.UnmarshalResponse(res, &projects)
if err != nil {
- return nil, err
+ return nil, nil, err
}
- // hack the queryData to stop pagination
- queryData.PerPage = len(projects.FollowedProjects) + 1
- return projects.FollowedProjects, err
+ for _, p := range projects.FollowedProjects {
+ children = append(children, dsmodels.DsRemoteApiScopeListEntry[models.CircleciProject]{
+ Type: api.RAS_ENTRY_TYPE_SCOPE,
+ Id: p.Id,
+ ParentId: nil,
+ Name: p.Name,
+ FullName: p.Slug,
+ Data: p.ConvertApiScope(),
+ })
+ }
+ return children, nil, nil
}
// RemoteScopes list all available scope for users
@@ -91,5 +96,15 @@ func getRemoteProjects(
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/circleci/connections/{connectionId}/remote-scopes [GET]
func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return remoteHelper.GetScopesFromRemote(input, nil, getRemoteProjects)
+ return raScopeList.Get(input)
+}
+
+// @Summary Remote server API proxy
+// @Description Forward API requests to the specified remote server
+// @Param connectionId path int true "connection ID"
+// @Param path path string true "path to a API endpoint"
+// @Tags plugins/circle
+// @Router /plugins/bitbucket/connections/{connectionId}/proxy/{path} [GET]
+func Proxy(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+ return raProxy.Proxy(input)
}
diff --git a/backend/plugins/circleci/api/scope.go b/backend/plugins/circleci/api/scope_api.go
similarity index 68%
rename from backend/plugins/circleci/api/scope.go
rename to backend/plugins/circleci/api/scope_api.go
index 7d66fdeba..fb8510bfc 100644
--- a/backend/plugins/circleci/api/scope.go
+++ b/backend/plugins/circleci/api/scope_api.go
@@ -20,74 +20,73 @@ package api
import (
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/circleci/models"
)
-// nolint
-type scopeReq struct {
- Data []models.CircleciPipeline `json:"data"`
-}
+type PutScopesReqBody api.PutScopesReqBody[models.CircleciProject]
+type ScopeDetail api.ScopeDetail[models.CircleciProject, models.CircleciScopeConfig]
-// PutScope create or update circleci pipeline
-// @Summary create or update circleci pipeline
-// @Description Create or update circleci pipeline
+// PutScopes create or update project
+// @Summary create or update project
+// @Description Create or update project
// @Tags plugins/circleci
// @Accept application/json
// @Param connectionId path int true "connection ID"
-// @Param scope body scopeReq true "json"
-// @Success 200 {object} models.CircleciPipeline
+// @Param scope body PutScopesReqBody true "json"
+// @Success 200 {object} []models.CircleciProject
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/circleci/connections/{connectionId}/scopes [PUT]
-func PutScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scopeHelper.Put(input)
+func PutScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+ return dsHelper.ScopeApi.PutMultiple(input)
}
-// UpdateScope patch to circleci pipeline
-// @Summary patch to circleci pipeline
-// @Description patch to circleci pipeline
+// PatchScope patch to project
+// @Summary patch to project
+// @Description patch to project
// @Tags plugins/circleci
// @Accept application/json
// @Param connectionId path int true "connection ID"
-// @Param scopeId path int true "pipeline id"
-// @Param scope body models.CircleciPipeline true "json"
-// @Success 200 {object} models.CircleciPipeline
+// @Param scopeId path string true "project ID"
+// @Param scope body models.CircleciProject true "json"
+// @Success 200 {object} models.CircleciProject
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/circleci/connections/{connectionId}/scopes/{scopeId} [PATCH]
-func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scopeHelper.Update(input)
+func PatchScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+ return dsHelper.ScopeApi.Patch(input)
}
-// GetScopeList get Circleci pipelines
-// @Summary get Circleci pipelines
-// @Description get Circleci pipelines
+// GetScopes get projects
+// @Summary get projects
+// @Description get projects
// @Tags plugins/circleci
// @Param connectionId path int true "connection ID"
// @Param searchTerm query string false "search term for scope name"
+// @Param pageSize query int false "page size, default 50"
+// @Param page query int false "page size, default 1"
// @Param blueprints query bool false "also return blueprints using these scopes as part of the payload"
-// @Success 200 {object} []models.CircleciPipeline
+// @Success 200 {object} []ScopeDetail
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/circleci/connections/{connectionId}/scopes/ [GET]
-func GetScopeList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scopeHelper.GetScopeList(input)
+func GetScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+ return dsHelper.ScopeApi.GetPage(input)
}
-// GetScope get one Circleci pipeline
-// @Summary get one Circleci pipeline
-// @Description get one Circleci pipeline
+// GetScope get one project
+// @Summary get one project
+// @Description get one project
// @Tags plugins/circleci
// @Param connectionId path int true "connection ID"
-// @Param scopeId path int true "pipeline id"
-// @Param pageSize query int false "page size, default 50"
-// @Param page query int false "page size, default 1"
-// @Success 200 {object} models.CircleciPipeline
+// @Param scopeId path string true "project ID"
+// @Success 200 {object} ScopeDetail
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/circleci/connections/{connectionId}/scopes/{scopeId} [GET]
func GetScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scopeHelper.GetScope(input)
+ return dsHelper.ScopeApi.GetScopeDetail(input)
}
// DeleteScope delete plugin data associated with the scope and optionally the scope itself
@@ -95,7 +94,7 @@ func GetScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors
// @Description delete data associated with plugin scope
// @Tags plugins/circleci
// @Param connectionId path int true "connection ID"
-// @Param scopeId path int true "scope ID"
+// @Param scopeId path string true "scope ID"
// @Param delete_data_only query bool false "Only delete the scope data, not the scope itself"
// @Success 200
// @Failure 400 {object} shared.ApiBody "Bad Request"
@@ -103,5 +102,5 @@ func GetScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/circleci/connections/{connectionId}/scopes/{scopeId} [DELETE]
func DeleteScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scopeHelper.Delete(input)
+ return dsHelper.ScopeApi.Delete(input)
}
diff --git a/backend/plugins/circleci/api/scope_config.go b/backend/plugins/circleci/api/scope_config_api.go
similarity index 59%
rename from backend/plugins/circleci/api/scope_config.go
rename to backend/plugins/circleci/api/scope_config_api.go
index 8d75ec4d8..28dff9ec4 100644
--- a/backend/plugins/circleci/api/scope_config.go
+++ b/backend/plugins/circleci/api/scope_config_api.go
@@ -22,76 +22,76 @@ import (
"github.com/apache/incubator-devlake/core/plugin"
)
-// CreateScopeConfig create scope config for Bamboo
-// @Summary create scope config for Bamboo
-// @Description create scope config for Bamboo
-// @Tags plugins/bamboo
+// PostScopeConfig create scope config for Circleci
+// @Summary create scope config for Circleci
+// @Description create scope config for Circleci
// @Accept application/json
// @Param connectionId path int true "connectionId"
-// @Param scopeConfig body models.BambooScopeConfig true "scope config"
-// @Success 200 {object} models.BambooScopeConfig
+// @Param scopeConfig body models.CircleciScopeConfig true "scope config"
+// @Success 200 {object} models.CircleciScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
-// @Router /plugins/bamboo/connections/{connectionId}/scope-configs [POST]
-func CreateScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scHelper.Create(input)
+// @Tags plugins/circleci
+// @Router /plugins/circleci/connections/{connectionId}/scope-configs [POST]
+func PostScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+ return dsHelper.ScopeConfigApi.Post(input)
}
-// UpdateScopeConfig update scope config for Bamboo
-// @Summary update scope config for Bamboo
-// @Description update scope config for Bamboo
-// @Tags plugins/bamboo
+// PatchScopeConfig update scope config for Circleci
+// @Summary update scope config for Circleci
+// @Description update scope config for Circleci
+// @Tags plugins/circleci
// @Accept application/json
// @Param id path int true "id"
-// @Param scopeConfig body models.BambooScopeConfig true "scope config"
// @Param connectionId path int true "connectionId"
-// @Success 200 {object} models.BambooScopeConfig
+// @Param scopeConfig body models.CircleciScopeConfig true "scope config"
+// @Success 200 {object} models.CircleciScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
-// @Router /plugins/bamboo/connections/{connectionId}/scope-configs/{id} [PATCH]
-func UpdateScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scHelper.Update(input)
+// @Router /plugins/circleci/connections/{connectionId}/scope-configs/{id} [PATCH]
+func PatchScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+ return dsHelper.ScopeConfigApi.Patch(input)
}
-// GetScopeConfig return onescope config
-// @Summary return onescope config
-// @Description return onescope config
-// @Tags plugins/bamboo
+// GetScopeConfig return one scope config
+// @Summary return one scope config
+// @Description return one scope config
+// @Tags plugins/circleci
// @Param id path int true "id"
// @Param connectionId path int true "connectionId"
-// @Success 200 {object} models.BambooScopeConfig
+// @Success 200 {object} models.CircleciScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
-// @Router /plugins/bamboo/connections/{connectionId}/scope-configs/{id} [GET]
+// @Router /plugins/circleci/connections/{connectionId}/scope-configs/{id} [GET]
func GetScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scHelper.Get(input)
+ return dsHelper.ScopeConfigApi.GetDetail(input)
}
// GetScopeConfigList return all scope configs
// @Summary return all scope configs
// @Description return all scope configs
-// @Tags plugins/bamboo
+// @Tags plugins/circleci
+// @Param connectionId path int true "connectionId"
// @Param pageSize query int false "page size, default 50"
// @Param page query int false "page size, default 1"
-// @Param connectionId path int true "connectionId"
-// @Success 200 {object} []models.BambooScopeConfig
+// @Success 200 {object} []models.CircleciScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
-// @Router /plugins/bamboo/connections/{connectionId}/scope-configs [GET]
+// @Router /plugins/circleci/connections/{connectionId}/scope-configs [GET]
func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scHelper.List(input)
+ return dsHelper.ScopeConfigApi.GetAll(input)
}
// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
-// @Tags plugins/bamboo
+// @Tags plugins/circleci
// @Param id path int true "id"
// @Param connectionId path int true "connectionId"
// @Success 200
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
-// @Router /plugins/bamboo/connections/{connectionId}/scope-configs/{id} [DELETE]
+// @Router /plugins/circleci/connections/{connectionId}/scope-configs/{id} [DELETE]
func DeleteScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
- return scHelper.Delete(input)
+ return dsHelper.ScopeConfigApi.Delete(input)
}
diff --git a/backend/plugins/circleci/impl/impl.go b/backend/plugins/circleci/impl/impl.go
index 041a42a95..3e2f55dd1 100644
--- a/backend/plugins/circleci/impl/impl.go
+++ b/backend/plugins/circleci/impl/impl.go
@@ -188,22 +188,22 @@ func (p Circleci) ApiResources() map[string]map[string]plugin.ApiResourceHandler
},
"connections/:connectionId/scopes/:scopeId": {
"GET": api.GetScope,
- "PATCH": api.UpdateScope,
+ "PATCH": api.PatchScope,
"DELETE": api.DeleteScope,
},
"connections/:connectionId/scopes/:scopeId/latest-sync-state": {
"GET": api.GetScopeLatestSyncState,
},
"connections/:connectionId/scopes": {
- "GET": api.GetScopeList,
- "PUT": api.PutScope,
+ "GET": api.GetScopes,
+ "PUT": api.PutScopes,
},
"connections/:connectionId/scope-configs": {
- "POST": api.CreateScopeConfig,
+ "POST": api.PostConnections,
"GET": api.GetScopeConfigList,
},
"connections/:connectionId/scope-configs/:id": {
- "PATCH": api.UpdateScopeConfig,
+ "PATCH": api.PatchScopeConfig,
"GET": api.GetScopeConfig,
"DELETE": api.DeleteScopeConfig,
},
diff --git a/backend/plugins/circleci/tasks/task_data.go b/backend/plugins/circleci/tasks/task_data.go
index ddc6335ce..2b10ee9c2 100644
--- a/backend/plugins/circleci/tasks/task_data.go
+++ b/backend/plugins/circleci/tasks/task_data.go
@@ -24,9 +24,9 @@ import (
)
type CircleciOptions struct {
- ConnectionId uint64 `json:"connectionId"`
- ProjectSlug string `json:"projectSlug"`
- PageSize uint64 `mapstruct:"pageSize"`
+ ConnectionId uint64 `json:"connectionId" mapstructure:"connectionId"`
+ ProjectSlug string `json:"projectSlug" mapstructure:"projectSlug"`
+ PageSize uint64 `mapstruct:"pageSize" mapstructure:"pageSize,omitempty"`
ScopeConfigId uint64 `json:"scopeConfigId" mapstructure:"scopeConfigId,omitempty"`
ScopeConfig *models.CircleciScopeConfig `json:"scopeConfig" mapstructure:"scopeConfig,omitempty"`
helper.CollectorOptions `mapstructure:",squash"`