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

Fix skipped pipelines model #2923

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 5 additions & 2 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4249,10 +4249,12 @@ const docTemplate = `{
"killed",
"error",
"blocked",
"declined"
"declined",
"created"
],
"x-enum-comments": {
"StatusBlocked": "waiting for approval",
"StatusCreated": "created / internal use only",
"StatusDeclined": "blocked and declined",
"StatusError": "error with the config / while parsing / some other system problem",
"StatusFailure": "failed to finish (exit code != 0)",
Expand All @@ -4271,7 +4273,8 @@ const docTemplate = `{
"StatusKilled",
"StatusError",
"StatusBlocked",
"StatusDeclined"
"StatusDeclined",
"StatusCreated"
]
},
"Step": {
Expand Down
78 changes: 77 additions & 1 deletion server/forge/mocks/forge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/model/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (
StatusError StatusValue = "error" // error with the config / while parsing / some other system problem
StatusBlocked StatusValue = "blocked" // waiting for approval
StatusDeclined StatusValue = "declined" // blocked and declined
StatusCreated StatusValue = "created" // created / internal use only
)

// SCMKind represent different version control systems
Expand Down
24 changes: 23 additions & 1 deletion server/pipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline

// update some pipeline fields
pipeline.RepoID = repo.ID
pipeline.Status = model.StatusPending
pipeline.Status = model.StatusCreated
setGatedState(repo, pipeline)
err = _store.CreatePipeline(pipeline)
if err != nil {
Expand Down Expand Up @@ -81,9 +81,17 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline

if len(pipelineItems) == 0 {
log.Debug().Str("repo", repo.FullName).Msg(ErrFiltered.Error())
if err := _store.DeletePipeline(pipeline); err != nil {
log.Error().Str("repo", repo.FullName).Err(err).Msg("failed to delete empty pipeline")
}

return nil, ErrFiltered
}

if err := updatePipelinePending(ctx, _store, pipeline, repo, repoUser); err != nil {
return nil, err
}

pipeline = setPipelineStepsOnPipeline(pipeline, pipelineItems)

// persist the pipeline config for historical correctness, restarts, etc
Expand Down Expand Up @@ -135,3 +143,17 @@ func updatePipelineWithErr(ctx context.Context, _store store.Store, pipeline *mo

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
}

publishPipeline(ctx, pipeline, repo, repoUser)

return nil
}
6 changes: 5 additions & 1 deletion server/store/datastore/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ func (s storage) UpdatePipeline(pipeline *model.Pipeline) error {
return err
}

func deletePipeline(sess *xorm.Session, pipelineID int64) error {
func (s storage) DeletePipeline(pipeline *model.Pipeline) error {
return s.deletePipeline(s.engine.NewSession(), pipeline.ID)
}

func (s storage) deletePipeline(sess *xorm.Session, pipelineID int64) error {
// delete related steps
for startSteps := 0; ; startSteps += perPage {
stepIDs := make([]int64, 0, perPage)
Expand Down
2 changes: 1 addition & 1 deletion server/store/datastore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s storage) deleteRepo(sess *xorm.Session, repo *model.Repo) error {
}

for i := range pipelineIDs {
if err := deletePipeline(sess, pipelineIDs[i]); err != nil {
if err := s.deletePipeline(sess, pipelineIDs[i]); err != nil {
return err
}
}
Expand Down
Loading