From 91dfef04251812f605ff25ae0c7cca371942c0ce Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 6 Jan 2023 15:02:03 +0800 Subject: [PATCH] feat: LocaleString for status --- models/actions/status.go | 11 ++++++++++- options/locale/locale_en-US.ini | 9 +++++++++ routers/web/repo/actions/view.go | 2 +- templates/shared/actions/runner_edit.tmpl | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/models/actions/status.go b/models/actions/status.go index ae74b4a4d1..059cf9bc09 100644 --- a/models/actions/status.go +++ b/models/actions/status.go @@ -3,7 +3,11 @@ package actions -import runnerv1 "code.gitea.io/actions-proto-go/runner/v1" +import ( + "code.gitea.io/gitea/modules/translation" + + runnerv1 "code.gitea.io/actions-proto-go/runner/v1" +) // Status represents the status of ActionRun, ActionRunJob, ActionTask, or ActionTaskStep type Status int @@ -35,6 +39,11 @@ func (s Status) String() string { return statusNames[s] } +// LocaleString returns the locale string name of the Status +func (s Status) LocaleString(lang translation.Locale) string { + return lang.Tr("actions.status." + s.String()) +} + // IsDone returns whether the Status is final func (s Status) IsDone() bool { return s.In(StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 12bbcd8a20..95503c57ad 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3271,3 +3271,12 @@ runners.delete_runner_failed = Failed to delete runner runners.delete_runner_header = Confirm to delete this runner runners.delete_runner_notice = If a task is running on this runner, it will be terminated and mark as failed. It may break building workflow. runners.delete_runner_confirm = Delete this runner + +status.unknown = "Unknown" +status.waiting = "Waiting" +status.running = "Running" +status.success = "Success" +status.failure = "Failure" +status.cancelled = "Cancelled" +status.skipped = "Skipped" +status.blocked = "Blocked" diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 2993fed622..1941761bbf 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -148,7 +148,7 @@ func ViewPost(ctx *context_module.Context) { resp.StateData.CurrentJobInfo.Title = current.Name resp.StateData.CurrentJobSteps = make([]ViewJobStep, 0) resp.LogsData.StreamingLogs = make([]ViewStepLog, 0, len(req.StepLogCursors)) - resp.StateData.CurrentJobInfo.Detail = current.Status.String() + resp.StateData.CurrentJobInfo.Detail = current.Status.LocaleString(ctx.Locale) if task != nil { steps := actions.FullSteps(task) diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index 461c02ecad..d3cbb19ba8 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -70,7 +70,7 @@ {{range .Tasks}} {{template "shared/actions/runner_id" .ID}} - {{.Status.String}} + {{.Status.LocaleString $.locale}} {{.GetRepoName}} {{.GetCommitSHAShort}}