mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +00:00
Factor out sideeffects
This commit is contained in:
parent
b7f61fc81d
commit
ed51df29b3
4 changed files with 16 additions and 10 deletions
|
@ -344,6 +344,7 @@ func PostApproval(c *gin.Context) {
|
|||
store.UpdateBuild(c, build)
|
||||
return
|
||||
}
|
||||
build = setBuildStepsOnBuild(b.Curr, buildItems)
|
||||
|
||||
err = store.FromContext(c).ProcCreate(build.Procs)
|
||||
if err != nil {
|
||||
|
@ -558,6 +559,7 @@ func PostBuild(c *gin.Context) {
|
|||
c.JSON(500, build)
|
||||
return
|
||||
}
|
||||
build = setBuildStepsOnBuild(b.Curr, buildItems)
|
||||
|
||||
err = store.FromContext(c).ProcCreate(build.Procs)
|
||||
if err != nil {
|
||||
|
|
|
@ -177,7 +177,7 @@ func PostHook(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if zeroSteps(*build, remoteYamlConfigs) {
|
||||
if zeroSteps(build, remoteYamlConfigs) {
|
||||
c.String(200, "Step conditions yield zero runnable steps")
|
||||
return
|
||||
}
|
||||
|
@ -261,6 +261,7 @@ func PostHook(c *gin.Context) {
|
|||
store.UpdateBuild(c, build)
|
||||
return
|
||||
}
|
||||
build = setBuildStepsOnBuild(b.Curr, buildItems)
|
||||
|
||||
err = store.FromContext(c).ProcCreate(build.Procs)
|
||||
if err != nil {
|
||||
|
@ -298,11 +299,10 @@ func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bo
|
|||
return true
|
||||
}
|
||||
|
||||
// uses pass by value as procBuilder has side effects on build. Something to be fixed
|
||||
func zeroSteps(build model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
|
||||
func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
|
||||
b := procBuilder{
|
||||
Repo: &model.Repo{},
|
||||
Curr: &build,
|
||||
Curr: build,
|
||||
Last: &model.Build{},
|
||||
Netrc: &model.Netrc{},
|
||||
Secs: []*model.Secret{},
|
||||
|
|
|
@ -128,14 +128,11 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
|
|||
item.Labels = map[string]string{}
|
||||
}
|
||||
|
||||
b.Curr.Procs = append(b.Curr.Procs, proc)
|
||||
items = append(items, item)
|
||||
pidSequence++
|
||||
}
|
||||
}
|
||||
|
||||
setBuildSteps(b.Curr, items)
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
|
@ -214,8 +211,12 @@ func (b *procBuilder) toInternalRepresentation(parsed *yaml.Config, environ map[
|
|||
).Compile(parsed)
|
||||
}
|
||||
|
||||
func setBuildSteps(build *model.Build, buildItems []*buildItem) {
|
||||
pcounter := len(buildItems)
|
||||
func setBuildStepsOnBuild(build *model.Build, buildItems []*buildItem) *model.Build {
|
||||
for _, item := range buildItems {
|
||||
build.Procs = append(build.Procs, item.Proc)
|
||||
}
|
||||
pcounter := len(build.Procs)
|
||||
|
||||
for _, item := range buildItems {
|
||||
for _, stage := range item.Config.Stages {
|
||||
var gid int
|
||||
|
@ -239,6 +240,8 @@ func setBuildSteps(build *model.Build, buildItems []*buildItem) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return build
|
||||
}
|
||||
|
||||
// return the metadata from the cli context.
|
||||
|
|
|
@ -262,7 +262,8 @@ pipeline:
|
|||
},
|
||||
}
|
||||
|
||||
_, err := b.Build()
|
||||
buildItems, err := b.Build()
|
||||
build = setBuildStepsOnBuild(build, buildItems)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue