Skip to content

Commit

Permalink
refactor: kw 5519 bamboo (#6846)
Browse files Browse the repository at this point in the history
* feat: add go-dev-tools to install dev tool for golang

* refactor: dshelper for bamboo wip

* refactor: bamboo adopts new dshelpers

* fix: unit test
  • Loading branch information
klesh authored Jan 25, 2024
1 parent 86c4ed9 commit 4652b64
Show file tree
Hide file tree
Showing 26 changed files with 316 additions and 526 deletions.
7 changes: 6 additions & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ go-dep:
go install github.com/vektra/mockery/[email protected]
go install github.com/swaggo/swag/cmd/[email protected]
go install github.com/golangci/golangci-lint/cmd/[email protected]
go install github.com/atombender/go-jsonschema/cmd/gojsonschema@latest

go-dev-tools:
# go install github.com/atombender/go-jsonschema/cmd/gojsonschema@latest
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/gopls@latest
go install github.com/go-delve/delve/cmd/dlv@latest

python-dep:
pip install -r python/requirements.txt
Expand Down
2 changes: 2 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX7IL/m9Y5LO+KQYv+t1CQOiFe6+SV2J7bE=
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ApiCollectorStateManager struct {
}

type CollectorOptions struct {
TimeAfter string `json:"timeAfter,omitempty" mapstructure:"timeAfter"`
TimeAfter string `json:"timeAfter,omitempty" mapstructure:"timeAfter,omitempty"`
}

// NewStatefulApiCollector create a new ApiCollectorStateManager
Expand Down
187 changes: 0 additions & 187 deletions backend/plugins/bamboo/api/blueprint_V200_test.go

This file was deleted.

108 changes: 51 additions & 57 deletions backend/plugins/bamboo/api/blueprint_v200.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ limitations under the License.
package api

import (
"fmt"

coreModels "github.com/apache/incubator-devlake/core/models"
"github.com/apache/incubator-devlake/plugins/bamboo/models"

Expand All @@ -30,90 +28,86 @@ import (
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
plugin "github.com/apache/incubator-devlake/core/plugin"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/helpers/srvhelper"
)

func MakePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
connectionId uint64,
scope []*coreModels.BlueprintScope,
bpScopes []*coreModels.BlueprintScope,
) (coreModels.PipelinePlan, []plugin.Scope, errors.Error) {
var err errors.Error
connection := new(models.BambooConnection)
err1 := connectionHelper.FirstById(connection, connectionId)
if err1 != nil {
return nil, nil, errors.Default.Wrap(err1, fmt.Sprintf("error on get connection by id[%d]", connectionId))
// load connection, scope and scopeConfig from the db
connection, err := dsHelper.ConnSrv.FindByPk(connectionId)
if err != nil {
return nil, nil, err
}

sc, err := makeScopeV200(connectionId, scope)
scopeDetails, err := dsHelper.ScopeSrv.MapScopeDetails(connectionId, bpScopes)
if err != nil {
return nil, nil, err
}

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

return pp, sc, nil
return plan, scopes, nil
}

func makeScopeV200(connectionId uint64, scopes []*coreModels.BlueprintScope) ([]plugin.Scope, errors.Error) {
sc := make([]plugin.Scope, 0, len(scopes))

for _, scope := range scopes {
id := didgen.NewDomainIdGenerator(&models.BambooPlan{}).Generate(connectionId, scope.ScopeId)
func makePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
scopeDetails []*srvhelper.ScopeDetail[models.BambooPlan, models.BambooScopeConfig],
connection *models.BambooConnection,
) (coreModels.PipelinePlan, errors.Error) {
plan := make(coreModels.PipelinePlan, len(scopeDetails))
for i, scopeDetail := range scopeDetails {
stage := plan[i]
if stage == nil {
stage = coreModels.PipelineStage{}
}

// get project from db
project, scopeConfig, err := scopeHelper.DbHelper().GetScopeAndConfig(connectionId, scope.ScopeId)
scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
// construct task options for Jira
task, err := helper.MakePipelinePlanTask(
"bamboo",
subtaskMetas,
scopeConfig.Entities,
models.BambooOptions{
ConnectionId: scope.ConnectionId,
PlanKey: scope.PlanKey,
},
)
if err != nil {
return nil, err
}

// add cicd_scope to scopes
if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CICD) {
scopeCICD := devops.NewCicdScope(id, project.Name)

sc = append(sc, scopeCICD)
}
stage = append(stage, task)
plan[i] = stage
}

return sc, nil
return plan, nil
}

func makePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
scopes []*coreModels.BlueprintScope,
func makeScopesV200(
scopeDetails []*srvhelper.ScopeDetail[models.BambooPlan, models.BambooScopeConfig],
connection *models.BambooConnection,
) (coreModels.PipelinePlan, errors.Error) {
plans := make(coreModels.PipelinePlan, 0, len(scopes))
for _, scope := range scopes {
var stage coreModels.PipelineStage
var err errors.Error
// get project
_, scopeConfig, err := scopeHelper.DbHelper().GetScopeAndConfig(connection.ID, scope.ScopeId)
if err != nil {
return nil, err
}
) ([]plugin.Scope, errors.Error) {
scopes := make([]plugin.Scope, 0, len(scopeDetails))

// bamboo main part
options := make(map[string]interface{})
options["connectionId"] = connection.ID
options["planKey"] = scope.ScopeId
options["scopeConfigId"] = scopeConfig.ID
idgen := didgen.NewDomainIdGenerator(&models.BambooPlan{})
for _, scopeDetail := range scopeDetails {
scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
id := idgen.Generate(connection.ID, scope.PlanKey)

// construct subtasks
subtasks, err := helper.MakePipelinePlanSubtasks(subtaskMetas, scopeConfig.Entities)
if err != nil {
return nil, err
// add cicd_scope to scopes
if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CICD) {
scopes = append(scopes, devops.NewCicdScope(id, scope.PlanKey))
}

stage = append(stage, &coreModels.PipelineTask{
Plugin: "bamboo",
Subtasks: subtasks,
Options: options,
})

plans = append(plans, stage)
}
return plans, nil

return scopes, nil
}
Loading

0 comments on commit 4652b64

Please sign in to comment.