( request pluginruntime.ProtocolRequestContext, pinned pluginruntime.PinnedEndpoint, task *model.Task, artifactContentURL func(taskID, artifactKey string) (string, error), )
| 1152 | } |
| 1153 | |
| 1154 | func taskPluginProtocolRendererContext( |
| 1155 | request pluginruntime.ProtocolRequestContext, |
| 1156 | pinned pluginruntime.PinnedEndpoint, |
| 1157 | task *model.Task, |
| 1158 | artifactContentURL func(taskID, artifactKey string) (string, error), |
| 1159 | ) (map[string]any, error) { |
| 1160 | rendererContext := request.JSValue() |
| 1161 | if task == nil || task.Status != model.TaskStatusSuccess { |
| 1162 | return rendererContext, nil |
| 1163 | } |
| 1164 | if pinned.Plugin == nil { |
| 1165 | return nil, errors.New("task artifact projection is unavailable") |
| 1166 | } |
| 1167 | |
| 1168 | artifacts, err := taskjsplugin.New(pinned.Plugin).ListArtifacts(task) |
| 1169 | if err != nil { |
| 1170 | return nil, fmt.Errorf("project task artifacts: %w", err) |
| 1171 | } |
| 1172 | artifacts, err = validateProjectedTaskArtifacts(artifacts) |
| 1173 | if err != nil { |
| 1174 | return nil, err |
| 1175 | } |
| 1176 | if len(artifacts) > 0 && artifactContentURL == nil { |
| 1177 | return nil, errors.New("task artifact projection is unavailable") |
| 1178 | } |
| 1179 | |
| 1180 | rendererArtifacts := make(map[string]any, len(artifacts)) |
| 1181 | for _, artifact := range artifacts { |
| 1182 | contentURL, buildErr := artifactContentURL(task.TaskID, artifact.Key) |
| 1183 | if buildErr != nil { |
| 1184 | return nil, fmt.Errorf("build task artifact content URL: %w", buildErr) |
| 1185 | } |
| 1186 | item := map[string]any{ |
| 1187 | "key": artifact.Key, |
| 1188 | "type": artifact.Type, |
| 1189 | "url": contentURL, |
| 1190 | } |
| 1191 | if artifact.MimeType != "" { |
| 1192 | item["mimeType"] = artifact.MimeType |
| 1193 | } |
| 1194 | rendererArtifacts[artifact.Key] = item |
| 1195 | } |
| 1196 | rendererContext["artifacts"] = rendererArtifacts |
| 1197 | return rendererContext, nil |
| 1198 | } |
| 1199 | |
| 1200 | func pluginProtocolTickDelay(taskID string, tick uint64, base, jitter time.Duration) time.Duration { |
| 1201 | if jitter <= 0 { |
no test coverage detected