diff --git a/models/actions/pre_execution_errors.go b/models/actions/pre_execution_errors.go new file mode 100644 index 0000000000..0ba8f8f362 --- /dev/null +++ b/models/actions/pre_execution_errors.go @@ -0,0 +1,41 @@ +// Copyright 2025 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: GPL-3.0-or-later + +package actions + +import ( + "fmt" + + "forgejo.org/modules/translation" +) + +type PreExecutionError int64 + +// PreExecutionError values are stored in the database in ActionRun.PreExecutionError and therefore values can't be +// reordered or changed without a database migration. Translation arguments are stored in the database in +// PreExecutionErrorDetails, and so they can't be changed or reordered without creating a migration or a new error code +// to represent the new argument details. +const ( + ErrorCodeEventDetectionError PreExecutionError = iota + 1 + ErrorCodeJobParsingError + ErrorCodePersistentIncompleteMatrix +) + +func TranslatePreExecutionError(lang translation.Locale, run *ActionRun) string { + if run.PreExecutionError != "" { + // legacy: Forgejo v13 stored value pre-translated, preventing correct translation to active user + return run.PreExecutionError + } + + switch run.PreExecutionErrorCode { + case 0: + return "" + case ErrorCodeEventDetectionError: + return lang.TrString("actions.workflow.event_detection_error", run.PreExecutionErrorDetails...) + case ErrorCodeJobParsingError: + return lang.TrString("actions.workflow.job_parsing_error", run.PreExecutionErrorDetails...) + case ErrorCodePersistentIncompleteMatrix: + return lang.TrString("actions.workflow.persistent_incomplete_matrix", run.PreExecutionErrorDetails...) + } + return fmt.Sprintf("