Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only update pipelineStatus in one place #2952

Merged
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
4 changes: 2 additions & 2 deletions pipeline/backend/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 10 additions & 16 deletions server/pipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"context"
"fmt"
"regexp"
"time"

"github.com/rs/zerolog/log"

Expand Down Expand Up @@ -128,30 +127,25 @@
}

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

Check warning on line 132 in server/pipeline/create.go

View check run for this annotation

Codecov / codecov/patch

server/pipeline/create.go#L130-L132

Added lines #L130 - L132 were not covered by tests
}
// update value in ref
*pipeline = *_pipeline

Check warning on line 135 in server/pipeline/create.go

View check run for this annotation

Codecov / codecov/patch

server/pipeline/create.go#L135

Added line #L135 was not covered by tests

publishPipeline(ctx, pipeline, repo, repoUser)

return nil
}

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

Check warning on line 145 in server/pipeline/create.go

View check run for this annotation

Codecov / codecov/patch

server/pipeline/create.go#L143-L145

Added lines #L143 - L145 were not covered by tests
}
// update value in ref
*pipeline = *_pipeline

Check warning on line 148 in server/pipeline/create.go

View check run for this annotation

Codecov / codecov/patch

server/pipeline/create.go#L148

Added line #L148 was not covered by tests

publishPipeline(ctx, pipeline, repo, repoUser)

Expand Down
6 changes: 4 additions & 2 deletions server/pipeline/pipelineStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down