You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commit_status.go 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package structs
  4. // CommitStatusState holds the state of a CommitStatus
  5. // It can be "pending", "success", "error" and "failure"
  6. type CommitStatusState string
  7. const (
  8. // CommitStatusPending is for when the CommitStatus is Pending
  9. CommitStatusPending CommitStatusState = "pending"
  10. // CommitStatusSuccess is for when the CommitStatus is Success
  11. CommitStatusSuccess CommitStatusState = "success"
  12. // CommitStatusError is for when the CommitStatus is Error
  13. CommitStatusError CommitStatusState = "error"
  14. // CommitStatusFailure is for when the CommitStatus is Failure
  15. CommitStatusFailure CommitStatusState = "failure"
  16. // CommitStatusWarning is for when the CommitStatus is Warning
  17. CommitStatusWarning CommitStatusState = "warning"
  18. )
  19. var commitStatusPriorities = map[CommitStatusState]int{
  20. CommitStatusError: 0,
  21. CommitStatusFailure: 1,
  22. CommitStatusWarning: 2,
  23. CommitStatusPending: 3,
  24. CommitStatusSuccess: 4,
  25. }
  26. func (css CommitStatusState) String() string {
  27. return string(css)
  28. }
  29. // NoBetterThan returns true if this State is no better than the given State
  30. // This function only handles the states defined in CommitStatusPriorities
  31. func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {
  32. // NoBetterThan only handles the 5 states above
  33. if _, exist := commitStatusPriorities[css]; !exist {
  34. return false
  35. }
  36. if _, exist := commitStatusPriorities[css2]; !exist {
  37. return false
  38. }
  39. return commitStatusPriorities[css] <= commitStatusPriorities[css2]
  40. }
  41. // IsPending represents if commit status state is pending
  42. func (css CommitStatusState) IsPending() bool {
  43. return css == CommitStatusPending
  44. }
  45. // IsSuccess represents if commit status state is success
  46. func (css CommitStatusState) IsSuccess() bool {
  47. return css == CommitStatusSuccess
  48. }
  49. // IsError represents if commit status state is error
  50. func (css CommitStatusState) IsError() bool {
  51. return css == CommitStatusError
  52. }
  53. // IsFailure represents if commit status state is failure
  54. func (css CommitStatusState) IsFailure() bool {
  55. return css == CommitStatusFailure
  56. }
  57. // IsWarning represents if commit status state is warning
  58. func (css CommitStatusState) IsWarning() bool {
  59. return css == CommitStatusWarning
  60. }