Skip to content

Commit b9a6246

Browse files
committed
update findTaskNeeds
1 parent ed133ff commit b9a6246

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

routers/api/actions/runner/utils.go

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import (
88
"fmt"
99

1010
actions_model "code.gitea.io/gitea/models/actions"
11-
"code.gitea.io/gitea/models/db"
1211
secret_model "code.gitea.io/gitea/models/secret"
13-
"code.gitea.io/gitea/modules/container"
1412
"code.gitea.io/gitea/modules/log"
1513
"code.gitea.io/gitea/services/actions"
1614

@@ -79,39 +77,16 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct {
7977
}
8078

8179
func findTaskNeeds(ctx context.Context, task *actions_model.ActionTask) (map[string]*runnerv1.TaskNeed, error) {
82-
if err := task.LoadAttributes(ctx); err != nil {
83-
return nil, fmt.Errorf("LoadAttributes: %w", err)
84-
}
85-
if len(task.Job.Needs) == 0 {
86-
return nil, nil
87-
}
88-
needs := container.SetOf(task.Job.Needs...)
89-
90-
jobs, err := db.Find[actions_model.ActionRunJob](ctx, actions_model.FindRunJobOptions{RunID: task.Job.RunID})
80+
taskNeeds, err := actions.FindTaskNeeds(ctx, task)
9181
if err != nil {
92-
return nil, fmt.Errorf("FindRunJobs: %w", err)
82+
return nil, err
9383
}
9484

95-
ret := make(map[string]*runnerv1.TaskNeed, len(needs))
96-
for _, job := range jobs {
97-
if !needs.Contains(job.JobID) {
98-
continue
99-
}
100-
if job.TaskID == 0 || !job.Status.IsDone() {
101-
// it shouldn't happen, or the job has been rerun
102-
continue
103-
}
104-
outputs := make(map[string]string)
105-
got, err := actions_model.FindTaskOutputByTaskID(ctx, job.TaskID)
106-
if err != nil {
107-
return nil, fmt.Errorf("FindTaskOutputByTaskID: %w", err)
108-
}
109-
for _, v := range got {
110-
outputs[v.OutputKey] = v.OutputValue
111-
}
112-
ret[job.JobID] = &runnerv1.TaskNeed{
113-
Outputs: outputs,
114-
Result: runnerv1.Result(job.Status),
85+
ret := make(map[string]*runnerv1.TaskNeed, len(taskNeeds))
86+
for jobID, taskNeed := range taskNeeds {
87+
ret[jobID] = &runnerv1.TaskNeed{
88+
Outputs: taskNeed.Outputs,
89+
Result: runnerv1.Result(taskNeed.Result),
11590
}
11691
}
11792

0 commit comments

Comments
 (0)