2020-01-21 20:46:04 -07:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package structs
|
|
|
|
|
2020-12-17 20:33:32 -07:00
|
|
|
// CommitStatusState holds the state of a CommitStatus
|
2020-01-21 20:46:04 -07:00
|
|
|
// It can be "pending", "success", "error", "failure", and "warning"
|
|
|
|
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"
|
2020-12-17 20:33:32 -07:00
|
|
|
// CommitStatusWarning is for when the CommitStatus is Warning
|
2020-01-21 20:46:04 -07:00
|
|
|
CommitStatusWarning CommitStatusState = "warning"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NoBetterThan returns true if this State is no better than the given State
|
|
|
|
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {
|
|
|
|
switch css {
|
|
|
|
case CommitStatusError:
|
|
|
|
return true
|
|
|
|
case CommitStatusFailure:
|
|
|
|
return css2 != CommitStatusError
|
|
|
|
case CommitStatusWarning:
|
|
|
|
return css2 != CommitStatusError && css2 != CommitStatusFailure
|
|
|
|
case CommitStatusPending:
|
|
|
|
return css2 != CommitStatusError && css2 != CommitStatusFailure && css2 != CommitStatusWarning
|
|
|
|
default:
|
|
|
|
return css2 != CommitStatusError && css2 != CommitStatusFailure && css2 != CommitStatusWarning && css2 != CommitStatusPending
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsWarning represents if commit status state is warning
|
|
|
|
func (css CommitStatusState) IsWarning() bool {
|
|
|
|
return css == CommitStatusWarning
|
|
|
|
}
|