mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 02:11:01 +00:00
adb2c82790
https://go.dev/doc/modules/release-workflow#breaking Fixes https://github.com/woodpecker-ci/woodpecker/issues/2913 fixes #2654 ``` runephilosof@fedora:~/code/platform-woodpecker/woodpecker-repo-configurator (master)$ go get go.woodpecker-ci.org/woodpecker@v2.0.0 go: go.woodpecker-ci.org/woodpecker@v2.0.0: invalid version: module contains a go.mod file, so module path must match major version ("go.woodpecker-ci.org/woodpecker/v2") ``` --------- Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
// Copyright 2023 Woodpecker Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package datastore
|
|
|
|
import (
|
|
"xorm.io/xorm"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
|
)
|
|
|
|
func (s storage) WorkflowGetTree(pipeline *model.Pipeline) ([]*model.Workflow, error) {
|
|
sess := s.engine.NewSession()
|
|
wfList, err := s.workflowList(sess, pipeline)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, wf := range wfList {
|
|
wf.Children, err = s.stepListWorkflow(sess, wf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return wfList, sess.Commit()
|
|
}
|
|
|
|
func (s storage) WorkflowsCreate(workflows []*model.Workflow) error {
|
|
sess := s.engine.NewSession()
|
|
defer sess.Close()
|
|
if err := sess.Begin(); err != nil {
|
|
return err
|
|
}
|
|
|
|
for i := range workflows {
|
|
// only Insert on single object ref set auto created ID back to object
|
|
if err := s.stepCreate(sess, workflows[i].Children); err != nil {
|
|
return err
|
|
}
|
|
if _, err := sess.Insert(workflows[i]); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return sess.Commit()
|
|
}
|
|
|
|
func (s storage) WorkflowList(pipeline *model.Pipeline) ([]*model.Workflow, error) {
|
|
return s.workflowList(s.engine.NewSession(), pipeline)
|
|
}
|
|
|
|
// workflowList lists workflows without child steps
|
|
func (s storage) workflowList(sess *xorm.Session, pipeline *model.Pipeline) ([]*model.Workflow, error) {
|
|
var wfList []*model.Workflow
|
|
err := sess.Where("workflow_pipeline_id = ?", pipeline.ID).
|
|
OrderBy("workflow_pid").
|
|
Find(&wfList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return wfList, nil
|
|
}
|
|
|
|
func (s storage) WorkflowLoad(id int64) (*model.Workflow, error) {
|
|
workflow := new(model.Workflow)
|
|
return workflow, wrapGet(s.engine.ID(id).Get(workflow))
|
|
}
|
|
|
|
func (s storage) WorkflowUpdate(workflow *model.Workflow) error {
|
|
_, err := s.engine.ID(workflow.ID).AllCols().Update(workflow)
|
|
return err
|
|
}
|