2020-01-22 03:46:04 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-01-22 03:46:04 +00:00
|
|
|
|
|
|
|
package structs
|
|
|
|
|
2020-12-18 03:33:32 +00:00
|
|
|
// CommitStatusState holds the state of a CommitStatus
|
2020-01-22 03:46:04 +00:00
|
|
|
// It can be "pending", "success", "error", "failure", and "warning"
|
|
|
|
type CommitStatusState string
|
|
|
|
|
|
|
|
const (
|
2020-12-18 03:33:32 +00:00
|
|
|
// CommitStatusPending is for when the CommitStatus is Pending
|
2020-01-22 03:46:04 +00:00
|
|
|
CommitStatusPending CommitStatusState = "pending"
|
2020-12-18 03:33:32 +00:00
|
|
|
// CommitStatusSuccess is for when the CommitStatus is Success
|
2020-01-22 03:46:04 +00:00
|
|
|
CommitStatusSuccess CommitStatusState = "success"
|
2020-12-18 03:33:32 +00:00
|
|
|
// CommitStatusError is for when the CommitStatus is Error
|
2020-01-22 03:46:04 +00:00
|
|
|
CommitStatusError CommitStatusState = "error"
|
2020-12-18 03:33:32 +00:00
|
|
|
// CommitStatusFailure is for when the CommitStatus is Failure
|
2020-01-22 03:46:04 +00:00
|
|
|
CommitStatusFailure CommitStatusState = "failure"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NoBetterThan returns true if this State is no better than the given State
|
|
|
|
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {
|
2023-07-21 08:24:36 +00:00
|
|
|
commitStatusPriorities := map[CommitStatusState]int{
|
|
|
|
CommitStatusError: 0,
|
|
|
|
CommitStatusFailure: 1,
|
|
|
|
CommitStatusPending: 2,
|
|
|
|
CommitStatusSuccess: 3,
|
2020-01-22 03:46:04 +00:00
|
|
|
}
|
2023-07-21 08:24:36 +00:00
|
|
|
return commitStatusPriorities[css] <= commitStatusPriorities[css2]
|
2020-01-22 03:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsPending represents if commit status state is pending
|
|
|
|
func (css CommitStatusState) IsPending() bool {
|
|
|
|
return css == CommitStatusPending
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsSuccess represents if commit status state is success
|
|
|
|
func (css CommitStatusState) IsSuccess() bool {
|
|
|
|
return css == CommitStatusSuccess
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsError represents if commit status state is error
|
|
|
|
func (css CommitStatusState) IsError() bool {
|
|
|
|
return css == CommitStatusError
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsFailure represents if commit status state is failure
|
|
|
|
func (css CommitStatusState) IsFailure() bool {
|
|
|
|
return css == CommitStatusFailure
|
|
|
|
}
|