mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 19:31:05 +00:00
Only update pipelineStatus in one place (#2952)
This commit is contained in:
parent
ff1f51d6a9
commit
1f8b3b5e1b
3 changed files with 16 additions and 20 deletions
|
@ -14,9 +14,9 @@
|
|||
|
||||
package types
|
||||
|
||||
// Config defines the runtime configuration of a pipeline.
|
||||
// Config defines the runtime configuration of a workflow.
|
||||
type Config struct {
|
||||
Stages []*Stage `json:"pipeline"` // pipeline stages
|
||||
Stages []*Stage `json:"pipeline"` // workflow stages
|
||||
Networks []*Network `json:"networks"` // network definitions
|
||||
Volumes []*Volume `json:"volumes"` // volume definitions
|
||||
Secrets []*Secret `json:"secrets"` // secret definitions
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
|
@ -128,16 +127,12 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline
|
|||
}
|
||||
|
||||
func updatePipelineWithErr(ctx context.Context, _store store.Store, pipeline *model.Pipeline, repo *model.Repo, repoUser *model.User, err error) error {
|
||||
pipeline.Started = time.Now().Unix()
|
||||
pipeline.Finished = pipeline.Started
|
||||
pipeline.Status = model.StatusError
|
||||
pipeline.Errors = errors.GetPipelineErrors(err)
|
||||
dbErr := _store.UpdatePipeline(pipeline)
|
||||
if dbErr != nil {
|
||||
msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName)
|
||||
log.Error().Err(dbErr).Msg(msg.Error())
|
||||
return msg
|
||||
_pipeline, err := UpdateToStatusError(_store, *pipeline, err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// update value in ref
|
||||
*pipeline = *_pipeline
|
||||
|
||||
publishPipeline(ctx, pipeline, repo, repoUser)
|
||||
|
||||
|
@ -145,13 +140,12 @@ func updatePipelineWithErr(ctx context.Context, _store store.Store, pipeline *mo
|
|||
}
|
||||
|
||||
func updatePipelinePending(ctx context.Context, _store store.Store, pipeline *model.Pipeline, repo *model.Repo, repoUser *model.User) error {
|
||||
pipeline.Status = model.StatusPending
|
||||
dbErr := _store.UpdatePipeline(pipeline)
|
||||
if dbErr != nil {
|
||||
msg := fmt.Errorf("failed to save pipeline for %s", repo.FullName)
|
||||
log.Error().Err(dbErr).Msg(msg.Error())
|
||||
return msg
|
||||
_pipeline, err := UpdateToStatusPending(_store, *pipeline, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// update value in ref
|
||||
*pipeline = *_pipeline
|
||||
|
||||
publishPipeline(ctx, pipeline, repo, repoUser)
|
||||
|
||||
|
|
|
@ -29,9 +29,11 @@ func UpdateToStatusRunning(store model.UpdatePipelineStore, pipeline model.Pipel
|
|||
}
|
||||
|
||||
func UpdateToStatusPending(store model.UpdatePipelineStore, pipeline model.Pipeline, reviewer string) (*model.Pipeline, error) {
|
||||
pipeline.Reviewer = reviewer
|
||||
if reviewer != "" {
|
||||
pipeline.Reviewer = reviewer
|
||||
pipeline.Reviewed = time.Now().Unix()
|
||||
}
|
||||
pipeline.Status = model.StatusPending
|
||||
pipeline.Reviewed = time.Now().Unix()
|
||||
return &pipeline, store.UpdatePipeline(&pipeline)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue