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.

status.go 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package actions
  4. import (
  5. "code.gitea.io/gitea/modules/translation"
  6. runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
  7. )
  8. // Status represents the status of ActionRun, ActionRunJob, ActionTask, or ActionTaskStep
  9. type Status int
  10. const (
  11. StatusUnknown Status = iota // 0, consistent with runnerv1.Result_RESULT_UNSPECIFIED
  12. StatusSuccess // 1, consistent with runnerv1.Result_RESULT_SUCCESS
  13. StatusFailure // 2, consistent with runnerv1.Result_RESULT_FAILURE
  14. StatusCancelled // 3, consistent with runnerv1.Result_RESULT_CANCELLED
  15. StatusSkipped // 4, consistent with runnerv1.Result_RESULT_SKIPPED
  16. StatusWaiting // 5, isn't a runnerv1.Result
  17. StatusRunning // 6, isn't a runnerv1.Result
  18. StatusBlocked // 7, isn't a runnerv1.Result
  19. )
  20. var statusNames = map[Status]string{
  21. StatusUnknown: "unknown",
  22. StatusWaiting: "waiting",
  23. StatusRunning: "running",
  24. StatusSuccess: "success",
  25. StatusFailure: "failure",
  26. StatusCancelled: "cancelled",
  27. StatusSkipped: "skipped",
  28. StatusBlocked: "blocked",
  29. }
  30. // String returns the string name of the Status
  31. func (s Status) String() string {
  32. return statusNames[s]
  33. }
  34. // LocaleString returns the locale string name of the Status
  35. func (s Status) LocaleString(lang translation.Locale) string {
  36. return lang.Tr("actions.status." + s.String())
  37. }
  38. // IsDone returns whether the Status is final
  39. func (s Status) IsDone() bool {
  40. return s.In(StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped)
  41. }
  42. // HasRun returns whether the Status is a result of running
  43. func (s Status) HasRun() bool {
  44. return s.In(StatusSuccess, StatusFailure)
  45. }
  46. func (s Status) IsUnknown() bool {
  47. return s == StatusUnknown
  48. }
  49. func (s Status) IsSuccess() bool {
  50. return s == StatusSuccess
  51. }
  52. func (s Status) IsFailure() bool {
  53. return s == StatusFailure
  54. }
  55. func (s Status) IsCancelled() bool {
  56. return s == StatusCancelled
  57. }
  58. func (s Status) IsSkipped() bool {
  59. return s == StatusSkipped
  60. }
  61. func (s Status) IsWaiting() bool {
  62. return s == StatusWaiting
  63. }
  64. func (s Status) IsRunning() bool {
  65. return s == StatusRunning
  66. }
  67. // In returns whether s is one of the given statuses
  68. func (s Status) In(statuses ...Status) bool {
  69. for _, v := range statuses {
  70. if s == v {
  71. return true
  72. }
  73. }
  74. return false
  75. }
  76. func (s Status) AsResult() runnerv1.Result {
  77. if s.IsDone() {
  78. return runnerv1.Result(s)
  79. }
  80. return runnerv1.Result_RESULT_UNSPECIFIED
  81. }