@@ -14,6 +14,7 @@ import (
1414 "code.gitea.io/gitea/modules/timeutil"
1515 "code.gitea.io/gitea/modules/util"
1616
17+ "github.com/nektos/act/pkg/jobparser"
1718 "xorm.io/builder"
1819)
1920
@@ -99,6 +100,24 @@ func (job *ActionRunJob) LoadAttributes(ctx context.Context) error {
99100 return job .Run .LoadAttributes (ctx )
100101}
101102
103+ // ParseJob parses the job structure from the ActionRunJob.WorkflowPayload
104+ func (job * ActionRunJob ) ParseJob () (* jobparser.Job , error ) {
105+ // job.WorkflowPayload is a SingleWorkflow created from an ActionRun's workflow, which exactly contains this job's YAML definition.
106+ // Ideally it shouldn't be called "Workflow", it is just a job with global workflow fields + trigger
107+ parsedWorkflows , err := jobparser .Parse (job .WorkflowPayload )
108+ if err != nil {
109+ return nil , fmt .Errorf ("job %d single workflow: unable to parse: %w" , job .ID , err )
110+ } else if len (parsedWorkflows ) != 1 {
111+ return nil , fmt .Errorf ("job %d single workflow: not single workflow" , job .ID )
112+ }
113+ _ , workflowJob := parsedWorkflows [0 ].Job ()
114+ if workflowJob == nil {
115+ // it shouldn't happen, and since the callers don't check nil, so return an error instead of nil
116+ return nil , util .ErrorWrap (util .ErrNotExist , "job %d single workflow: payload doesn't contain a job" , job .ID )
117+ }
118+ return workflowJob , nil
119+ }
120+
102121func GetRunJobByID (ctx context.Context , id int64 ) (* ActionRunJob , error ) {
103122 var job ActionRunJob
104123 has , err := db .GetEngine (ctx ).Where ("id=?" , id ).Get (& job )
0 commit comments