2020-01-21 20:46:04 -07:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-01-21 20:46:04 -07:00
|
|
|
|
|
|
|
package structs
|
|
|
|
|
2020-12-17 20:33:32 -07:00
|
|
|
// CommitStatusState holds the state of a CommitStatus
|
2023-07-26 02:52:07 -06:00
|
|
|
// It can be "pending", "success", "error" and "failure"
|
2020-01-21 20:46:04 -07:00
|
|
|
type CommitStatusState string
|
|
|
|
|
|
|
|
const (
|
2020-12-17 20:33:32 -07:00
|
|
|
// CommitStatusPending is for when the CommitStatus is Pending
|
2020-01-21 20:46:04 -07:00
|
|
|
CommitStatusPending CommitStatusState = "pending"
|
2020-12-17 20:33:32 -07:00
|
|
|
// CommitStatusSuccess is for when the CommitStatus is Success
|
2020-01-21 20:46:04 -07:00
|
|
|
CommitStatusSuccess CommitStatusState = "success"
|
2020-12-17 20:33:32 -07:00
|
|
|
// CommitStatusError is for when the CommitStatus is Error
|
2020-01-21 20:46:04 -07:00
|
|
|
CommitStatusError CommitStatusState = "error"
|
2020-12-17 20:33:32 -07:00
|
|
|
// CommitStatusFailure is for when the CommitStatus is Failure
|
2020-01-21 20:46:04 -07:00
|
|
|
CommitStatusFailure CommitStatusState = "failure"
|
2023-10-08 21:56:02 -06:00
|
|
|
// CommitStatusWarning is for when the CommitStatus is Warning
|
|
|
|
CommitStatusWarning CommitStatusState = "warning"
|
2020-01-21 20:46:04 -07:00
|
|
|
)
|
|
|
|
|
2023-07-26 02:52:07 -06:00
|
|
|
var commitStatusPriorities = map[CommitStatusState]int{
|
|
|
|
CommitStatusError: 0,
|
|
|
|
CommitStatusFailure: 1,
|
2023-10-08 21:56:02 -06:00
|
|
|
CommitStatusWarning: 2,
|
|
|
|
CommitStatusPending: 3,
|
|
|
|
CommitStatusSuccess: 4,
|
2023-07-26 02:52:07 -06:00
|
|
|
}
|
|
|
|
|
2023-08-21 01:26:10 -06:00
|
|
|
func (css CommitStatusState) String() string {
|
|
|
|
return string(css)
|
|
|
|
}
|
|
|
|
|
2020-01-21 20:46:04 -07:00
|
|
|
// NoBetterThan returns true if this State is no better than the given State
|
2023-07-26 02:52:07 -06:00
|
|
|
// This function only handles the states defined in CommitStatusPriorities
|
2020-01-21 20:46:04 -07:00
|
|
|
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {
|
2023-10-08 21:56:02 -06:00
|
|
|
// NoBetterThan only handles the 5 states above
|
2023-07-26 02:52:07 -06:00
|
|
|
if _, exist := commitStatusPriorities[css]; !exist {
|
|
|
|
return false
|
2020-01-21 20:46:04 -07:00
|
|
|
}
|
2023-07-26 02:52:07 -06:00
|
|
|
|
|
|
|
if _, exist := commitStatusPriorities[css2]; !exist {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-07-21 02:24:36 -06:00
|
|
|
return commitStatusPriorities[css] <= commitStatusPriorities[css2]
|
2020-01-21 20:46:04 -07: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
|
|
|
|
}
|
2023-10-08 21:56:02 -06:00
|
|
|
|
|
|
|
// IsWarning represents if commit status state is warning
|
|
|
|
func (css CommitStatusState) IsWarning() bool {
|
|
|
|
return css == CommitStatusWarning
|
|
|
|
}
|