|
8 | 8 | "fmt" |
9 | 9 |
|
10 | 10 | actions_model "code.gitea.io/gitea/models/actions" |
11 | | - "code.gitea.io/gitea/models/db" |
12 | 11 | secret_model "code.gitea.io/gitea/models/secret" |
13 | | - "code.gitea.io/gitea/modules/container" |
14 | 12 | "code.gitea.io/gitea/modules/log" |
15 | 13 | "code.gitea.io/gitea/services/actions" |
16 | 14 |
|
@@ -79,39 +77,16 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct { |
79 | 77 | } |
80 | 78 |
|
81 | 79 | 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) |
91 | 81 | if err != nil { |
92 | | - return nil, fmt.Errorf("FindRunJobs: %w", err) |
| 82 | + return nil, err |
93 | 83 | } |
94 | 84 |
|
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), |
115 | 90 | } |
116 | 91 | } |
117 | 92 |
|
|
0 commit comments