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
90 changes: 40 additions & 50 deletions backend/plugins/tapd/api/blueprint_v200.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,100 +18,90 @@ limitations under the License.
package api

import (
"strconv"

"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/models/domainlayer/ticket"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/core/utils"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/plugins/tapd/models"
"github.com/apache/incubator-devlake/plugins/tapd/tasks"
)

func MakeDataSourcePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
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)
if err != nil {
return nil, nil, err
}

return plan, scopes, nil
plan, err := makePipelinePlanV200(subtaskMetas, scopeDetails, connection)
if err != nil {
return nil, nil, err
}
scopes, err := makeScopesV200(scopeDetails, connection)
return plan, scopes, err
}

func makeDataSourcePipelinePlanV200(
func makePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
plan coreModels.PipelinePlan,
bpScopes []*coreModels.BlueprintScope,
connectionId uint64,
scopeDetails []*srvhelper.ScopeDetail[models.TapdWorkspace, models.TapdScopeConfig],
connection *models.TapdConnection,
) (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 tapd
options := make(map[string]interface{})
intNum, err := errors.Convert01(strconv.Atoi(bpScope.ScopeId))
if err != nil {
return nil, err
}
options["workspaceId"] = intNum
options["connectionId"] = connectionId

_, scopeConfig, err := scopeHelper.DbHelper().GetScopeAndConfig(connectionId, bpScope.ScopeId)
scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
// construct task options for circleci
task, err := helper.MakePipelinePlanTask(
"tapd",
subtaskMetas,
scopeConfig.Entities,
tasks.TapdOptions{
ConnectionId: connection.ID,
WorkspaceId: scope.Id,
},
)
if err != nil {
return nil, err
}

subtasks, err := helper.MakePipelinePlanSubtasks(subtaskMetas, scopeConfig.Entities)
if err != nil {
return nil, err
}
stage = append(stage, &coreModels.PipelineTask{
Plugin: "tapd",
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 {
// get workspace and scope config from db
scopeDetails []*srvhelper.ScopeDetail[models.TapdWorkspace, models.TapdScopeConfig],
connection *models.TapdConnection,
) ([]plugin.Scope, errors.Error) {
scopes := make([]plugin.Scope, 0, len(scopeDetails))

tapdWorkspace, scopeConfig, err := scopeHelper.DbHelper().GetScopeAndConfig(connectionId, bpScope.ScopeId)
if err != nil {
return nil, err
}
idgen := didgen.NewDomainIdGenerator(&models.TapdWorkspace{})
for _, scopeDetail := range scopeDetails {
// get workspace and scope config from db
tapdWorkspace, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig

// add wrokspace to scopes
if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_TICKET) {
domainBoard := &ticket.Board{
DomainEntity: domainlayer.DomainEntity{
Id: didgen.NewDomainIdGenerator(&models.TapdWorkspace{}).Generate(tapdWorkspace.ConnectionId, tapdWorkspace.Id),
},
Name: tapdWorkspace.Name,
Type: "scrum",
}
scopes = append(scopes, domainBoard)
id := idgen.Generate(connection.ID, tapdWorkspace)
board := ticket.NewBoard(id, tapdWorkspace.Name)
board.Type = "scrum"
scopes = append(scopes, board)
}
}
return scopes, nil
Expand Down
129 changes: 0 additions & 129 deletions backend/plugins/tapd/api/blueprint_v200_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/tapd/connections/{connectionId}/test [POST]
func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.TapdConnection{}
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")
}
Expand All @@ -125,17 +124,7 @@ func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResource
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/tapd/connections [POST]
func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
// create a new connections
connection := &models.TapdConnection{}

// update from request and save to database
//err := refreshAndSaveTapdConnection(tapdConnection, input.Body)
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)
}

// @Summary patch tapd connection
Expand All @@ -147,17 +136,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/tapd/connections/{connectionId} [PATCH]
func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.TapdConnection{}
if err := connectionHelper.First(&connection, input.Params); err != nil {
return nil, err
}
if err := (&models.TapdConnection{}).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)
}

// @Summary delete a tapd connection
Expand All @@ -169,13 +148,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/tapd/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
conn := &models.TapdConnection{}
output, err := connectionHelper.Delete(conn, input)
if err != nil {
return output, err
}
output.Body = conn.Sanitize()
return output, nil
return dsHelper.ConnApi.Delete(input)
}

// @Summary get all tapd connections
Expand All @@ -186,15 +159,7 @@ func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/tapd/connections [GET]
func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
var connections []models.TapdConnection
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)
}

// @Summary get tapd connection detail
Expand All @@ -205,10 +170,5 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/tapd/connections/{connectionId} [GET]
func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.TapdConnection{}
err := connectionHelper.First(connection, input.Params)
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection.Sanitize()}, nil
return dsHelper.ConnApi.GetDetail(input)
}
Loading