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