Skip to content

Commit

Permalink
delete
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys committed Dec 11, 2023
1 parent 87fcad4 commit 2ebd648
Show file tree
Hide file tree
Showing 8 changed files with 545 additions and 7 deletions.
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 {
return nil, err
}

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

0 comments on commit 2ebd648

Please sign in to comment.