@@ -19,30 +19,14 @@ import (
1919 "code.gitea.io/gitea/modules/git"
2020 "code.gitea.io/gitea/modules/log"
2121 api "code.gitea.io/gitea/modules/structs"
22+ "code.gitea.io/gitea/modules/util"
2223 "code.gitea.io/gitea/services/context"
2324 "code.gitea.io/gitea/services/convert"
2425
2526 "github.com/nektos/act/pkg/jobparser"
2627 "github.com/nektos/act/pkg/model"
2728)
2829
29- type TranslateableError struct {
30- Translation string
31- Args []any
32- Code int
33- }
34-
35- func (t TranslateableError ) Error () string {
36- return t .Translation
37- }
38-
39- func (t TranslateableError ) GetCode () int {
40- if t .Code == 0 {
41- return http .StatusInternalServerError
42- }
43- return t .Code
44- }
45-
4630func getActionWorkflowPath (commit * git.Commit ) string {
4731 paths := []string {".gitea/workflows" , ".github/workflows" }
4832 for _ , path := range paths {
@@ -156,22 +140,29 @@ func DisableActionWorkflow(ctx *context.APIContext, workflowID string) error {
156140 return disableOrEnableWorkflow (ctx , workflowID , false )
157141}
158142
159- func DispatchActionWorkflow (ctx * context.Context , workflowID , ref string , processInputs func (model * model.WorkflowDispatch , inputs * map [string ]any ) error ) error {
160- if len (workflowID ) == 0 {
161- return fmt .Errorf ("workflowID is empty" )
143+ func DispatchActionWorkflow (ctx * context.Context , workflowID , ref string , processInputs func (model * model.WorkflowDispatch , inputs map [string ]any ) error ) error {
144+ if workflowID == "" {
145+ return util .ErrWrapLocale (
146+ util .NewNotExistErrorf ("workflowID is empty" ),
147+ "actions.workflow.not_found" , workflowID ,
148+ )
162149 }
163150
164- if len (ref ) == 0 {
165- return fmt .Errorf ("ref is empty" )
151+ if ref == "" {
152+ return util .ErrWrapLocale (
153+ util .NewNotExistErrorf ("ref is empty" ),
154+ "form.target_ref_not_exist" , ref ,
155+ )
166156 }
167157
168158 // can not rerun job when workflow is disabled
169159 cfgUnit := ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions )
170160 cfg := cfgUnit .ActionsConfig ()
171161 if cfg .IsWorkflowDisabled (workflowID ) {
172- return & TranslateableError {
173- Translation : "actions.workflow.disabled" ,
174- }
162+ return util .ErrWrapLocale (
163+ util .NewPermissionDeniedErrorf ("workflow is disabled" ),
164+ "actions.workflow.disabled" ,
165+ )
175166 }
176167
177168 // get target commit of run from specified ref
@@ -187,11 +178,10 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
187178 runTargetCommit , err = ctx .Repo .GitRepo .GetBranchCommit (ref )
188179 }
189180 if err != nil {
190- return & TranslateableError {
191- Code : http .StatusNotFound ,
192- Translation : "form.target_ref_not_exist" ,
193- Args : []any {ref },
194- }
181+ return util .ErrWrapLocale (
182+ util .NewNotExistErrorf ("ref %q doesn't exist" , ref ),
183+ "form.target_ref_not_exist" , ref ,
184+ )
195185 }
196186
197187 // get workflow entry from runTargetCommit
@@ -219,11 +209,10 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
219209 }
220210
221211 if len (workflows ) == 0 {
222- return & TranslateableError {
223- Code : http .StatusNotFound ,
224- Translation : "actions.workflow.not_found" ,
225- Args : []any {workflowID },
226- }
212+ return util .ErrWrapLocale (
213+ util .NewNotExistErrorf ("workflow %q doesn't exist" , workflowID ),
214+ "actions.workflow.not_found" , workflowID ,
215+ )
227216 }
228217
229218 // get inputs from post
@@ -232,7 +221,7 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
232221 }
233222 inputsWithDefaults := make (map [string ]any )
234223 workflowDispatch := workflow .WorkflowDispatchConfig ()
235- if err := processInputs (workflowDispatch , & inputsWithDefaults ); err != nil {
224+ if err := processInputs (workflowDispatch , inputsWithDefaults ); err != nil {
236225 return err
237226 }
238227
@@ -279,14 +268,14 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
279268
280269 // Insert the action run and its associated jobs into the database
281270 if err := actions_model .InsertRun (ctx , run , workflows ); err != nil {
282- return fmt .Errorf ("workflow : %w" , err )
271+ return fmt .Errorf ("InsertRun : %w" , err )
283272 }
284273
285- alljobs , err := db .Find [actions_model.ActionRunJob ](ctx , actions_model.FindRunJobOptions {RunID : run .ID })
274+ allJobs , err := db .Find [actions_model.ActionRunJob ](ctx , actions_model.FindRunJobOptions {RunID : run .ID })
286275 if err != nil {
287276 log .Error ("FindRunJobs: %v" , err )
288277 }
289- CreateCommitStatus (ctx , alljobs ... )
278+ CreateCommitStatus (ctx , allJobs ... )
290279
291280 return nil
292281}
0 commit comments