@@ -218,82 +218,87 @@ func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, re
218218 break
219219 }
220220
221- if entry != nil {
222- content , err := actions .GetContentFromEntry (entry )
223- if err != nil {
224- return err
225- }
221+ if entry == nil {
222+ return util .ErrorWrapLocale (
223+ util .NewNotExistErrorf ("workflow %q doesn't exist" , workflowID ),
224+ "actions.workflow.not_found" , workflowID ,
225+ )
226+ }
226227
227- giteaCtx := GenerateGiteaContext (run , nil )
228+ content , err := actions .GetContentFromEntry (entry )
229+ if err != nil {
230+ return err
231+ }
228232
229- workflows , err = jobparser .Parse (content , jobparser .WithGitContext (giteaCtx .ToGitHubContext ()))
230- if err != nil {
231- return err
232- }
233+ giteaCtx := GenerateGiteaContext (run , nil )
233234
234- if len (workflows ) > 0 && workflows [0 ].RunName != "" {
235- run .Title = workflows [0 ].RunName
236- }
235+ workflows , err = jobparser .Parse (content , jobparser .WithGitContext (giteaCtx .ToGitHubContext ()))
236+ if err != nil {
237+ return err
238+ }
237239
238- if len (workflows ) == 0 {
239- return util .ErrorWrapLocale (
240- util .NewNotExistErrorf ("workflow %q doesn't exist" , workflowID ),
241- "actions.workflow.not_found" , workflowID ,
242- )
243- }
240+ if len (workflows ) > 0 && workflows [0 ].RunName != "" {
241+ run .Title = workflows [0 ].RunName
242+ }
244243
245- // get inputs from post
246- workflow := & model.Workflow {
247- RawOn : workflows [0 ].RawOn ,
248- }
249- inputsWithDefaults := make (map [string ]any )
250- if workflowDispatch := workflow .WorkflowDispatchConfig (); workflowDispatch != nil {
251- if err = processInputs (workflowDispatch , inputsWithDefaults ); err != nil {
252- return err
253- }
254- }
244+ if len (workflows ) == 0 {
245+ return util .ErrorWrapLocale (
246+ util .NewNotExistErrorf ("workflow %q doesn't exist" , workflowID ),
247+ "actions.workflow.not_found" , workflowID ,
248+ )
249+ }
255250
256- // ctx.Req.PostForm -> WorkflowDispatchPayload.Inputs -> ActionRun.EventPayload -> runner: ghc.Event
257- // https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
258- // https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_dispatch
259- workflowDispatchPayload := & api.WorkflowDispatchPayload {
260- Workflow : workflowID ,
261- Ref : ref ,
262- Repository : convert .ToRepo (ctx , repo , access_model.Permission {AccessMode : perm .AccessModeNone }),
263- Inputs : inputsWithDefaults ,
264- Sender : convert .ToUserWithAccessMode (ctx , doer , perm .AccessModeNone ),
251+ // get inputs from post
252+ workflow := & model.Workflow {
253+ RawOn : workflows [0 ].RawOn ,
254+ }
255+ inputsWithDefaults := make (map [string ]any )
256+ if workflowDispatch := workflow .WorkflowDispatchConfig (); workflowDispatch != nil {
257+ if err = processInputs (workflowDispatch , inputsWithDefaults ); err != nil {
258+ return err
265259 }
260+ }
266261
267- var eventPayload []byte
268- if eventPayload , err = workflowDispatchPayload .JSONPayload (); err != nil {
269- return fmt .Errorf ("JSONPayload: %w" , err )
270- }
271- run .EventPayload = string (eventPayload )
272-
273- // cancel running jobs of the same workflow
274- if err := CancelPreviousJobs (
275- ctx ,
276- run .RepoID ,
277- run .Ref ,
278- run .WorkflowID ,
279- run .Event ,
280- ); err != nil {
281- log .Error ("CancelRunningJobs: %v" , err )
282- }
262+ // ctx.Req.PostForm -> WorkflowDispatchPayload.Inputs -> ActionRun.EventPayload -> runner: ghc.Event
263+ // https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
264+ // https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_dispatch
265+ workflowDispatchPayload := & api.WorkflowDispatchPayload {
266+ Workflow : workflowID ,
267+ Ref : ref ,
268+ Repository : convert .ToRepo (ctx , repo , access_model.Permission {AccessMode : perm .AccessModeNone }),
269+ Inputs : inputsWithDefaults ,
270+ Sender : convert .ToUserWithAccessMode (ctx , doer , perm .AccessModeNone ),
271+ }
283272
284- // Insert the action run and its associated jobs into the database
285- if err := actions_model .InsertRun (ctx , run , workflows ); err != nil {
286- return fmt .Errorf ("InsertRun: %w" , err )
287- }
273+ var eventPayload []byte
274+ if eventPayload , err = workflowDispatchPayload .JSONPayload (); err != nil {
275+ return fmt .Errorf ("JSONPayload: %w" , err )
276+ }
277+ run .EventPayload = string (eventPayload )
278+
279+ // cancel running jobs of the same workflow
280+ if err := CancelPreviousJobs (
281+ ctx ,
282+ run .RepoID ,
283+ run .Ref ,
284+ run .WorkflowID ,
285+ run .Event ,
286+ ); err != nil {
287+ log .Error ("CancelRunningJobs: %v" , err )
288+ }
288289
289- allJobs , err := db .Find [actions_model.ActionRunJob ](ctx , actions_model.FindRunJobOptions {RunID : run .ID })
290- if err != nil {
291- log .Error ("FindRunJobs: %v" , err )
292- }
293- CreateCommitStatus (ctx , allJobs ... )
294- for _ , job := range allJobs {
295- notify_service .WorkflowJobStatusUpdate (ctx , repo , doer , job , nil )
296- }
290+ // Insert the action run and its associated jobs into the database
291+ if err := actions_model .InsertRun (ctx , run , workflows ); err != nil {
292+ return fmt .Errorf ("InsertRun: %w" , err )
293+ }
294+
295+ allJobs , err := db .Find [actions_model.ActionRunJob ](ctx , actions_model.FindRunJobOptions {RunID : run .ID })
296+ if err != nil {
297+ log .Error ("FindRunJobs: %v" , err )
298+ }
299+ CreateCommitStatus (ctx , allJobs ... )
300+ for _ , job := range allJobs {
301+ notify_service .WorkflowJobStatusUpdate (ctx , repo , doer , job , nil )
297302 }
298303 return nil
299304}
0 commit comments