2019-09-14 12:12:04 +00:00
|
|
|
// Copyright 2019 mhmxs.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2021-09-22 18:48:01 +00:00
|
|
|
package shared
|
2019-09-14 12:12:04 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2021-09-27 17:51:55 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
2019-09-14 12:12:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type UpdateBuildStore interface {
|
|
|
|
UpdateBuild(*model.Build) error
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateToStatusRunning(store UpdateBuildStore, build model.Build, started int64) (*model.Build, error) {
|
|
|
|
build.Status = model.StatusRunning
|
|
|
|
build.Started = started
|
|
|
|
return &build, store.UpdateBuild(&build)
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateToStatusPending(store UpdateBuildStore, build model.Build, reviewer string) (*model.Build, error) {
|
|
|
|
build.Reviewer = reviewer
|
|
|
|
build.Status = model.StatusPending
|
|
|
|
build.Reviewed = time.Now().Unix()
|
|
|
|
return &build, store.UpdateBuild(&build)
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateToStatusDeclined(store UpdateBuildStore, build model.Build, reviewer string) (*model.Build, error) {
|
|
|
|
build.Reviewer = reviewer
|
|
|
|
build.Status = model.StatusDeclined
|
|
|
|
build.Reviewed = time.Now().Unix()
|
|
|
|
return &build, store.UpdateBuild(&build)
|
|
|
|
}
|
|
|
|
|
2021-11-22 11:55:13 +00:00
|
|
|
func UpdateStatusToDone(store UpdateBuildStore, build model.Build, status model.StatusValue, stopped int64) (*model.Build, error) {
|
2019-09-14 12:12:04 +00:00
|
|
|
build.Status = status
|
|
|
|
build.Finished = stopped
|
|
|
|
return &build, store.UpdateBuild(&build)
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateToStatusError(store UpdateBuildStore, build model.Build, err error) (*model.Build, error) {
|
|
|
|
build.Error = err.Error()
|
|
|
|
build.Status = model.StatusError
|
|
|
|
build.Started = time.Now().Unix()
|
|
|
|
build.Finished = build.Started
|
|
|
|
return &build, store.UpdateBuild(&build)
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateToStatusKilled(store UpdateBuildStore, build model.Build) (*model.Build, error) {
|
|
|
|
build.Status = model.StatusKilled
|
|
|
|
build.Finished = time.Now().Unix()
|
|
|
|
return &build, store.UpdateBuild(&build)
|
|
|
|
}
|