Skip to content

Commit

Permalink
fix: worker cmd list all run results (#6460)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Feb 14, 2023
1 parent 38c942a commit 21ea1e2
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions engine/worker/internal/handler_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func artifactsHandler(ctx context.Context, wk *CurrentWorker) http.HandlerFunc {
return
}

artifactsJSON := []sdk.WorkflowRunResultArtifact{}
artifactsJSON := make([]interface{}, 0)

workflowRunResults, err := wk.client.WorkflowRunResultsList(ctx, projectKey, reqArgs.Workflow, reqArgs.Number)
if err != nil {
Expand All @@ -67,19 +67,41 @@ func artifactsHandler(ctx context.Context, wk *CurrentWorker) http.HandlerFunc {
return
}
for _, result := range workflowRunResults {
if result.Type != sdk.WorkflowRunResultTypeArtifact {
continue
switch result.Type {
case sdk.WorkflowRunResultTypeArtifact:
artData, err := result.GetArtifact()
if err != nil {
newError := sdk.NewError(sdk.ErrUnknownError, fmt.Errorf("item is not an artifact: %s", err))
writeError(w, r, newError)
return
}
if reqArgs.Pattern != "" && !regexp.MatchString(artData.Name) {
continue
}
artifactsJSON = append(artifactsJSON, artData)
case sdk.WorkflowRunResultTypeArtifactManager:
artData, err := result.GetArtifactManager()
if err != nil {
newError := sdk.NewError(sdk.ErrUnknownError, fmt.Errorf("item is not from an artifact manager: %s", err))
writeError(w, r, newError)
return
}
if reqArgs.Pattern != "" && !regexp.MatchString(artData.Name) {
continue
}
artifactsJSON = append(artifactsJSON, artData)
case sdk.WorkflowRunResultTypeCoverage:
artData, err := result.GetCoverage()
if err != nil {
newError := sdk.NewError(sdk.ErrUnknownError, fmt.Errorf("item is not a coverage: %s", err))
writeError(w, r, newError)
return
}
if reqArgs.Pattern != "" && !regexp.MatchString(artData.Name) {
continue
}
artifactsJSON = append(artifactsJSON, artData)
}
artData, err := result.GetArtifact()
if err != nil {
newError := sdk.NewError(sdk.ErrUnknownError, fmt.Errorf("item is not an artifact: %s", err))
writeError(w, r, newError)
return
}
if reqArgs.Pattern != "" && !regexp.MatchString(artData.Name) {
continue
}
artifactsJSON = append(artifactsJSON, artData)
}

writeJSON(w, artifactsJSON, http.StatusOK)
Expand Down

0 comments on commit 21ea1e2

Please sign in to comment.