Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker): worker cmd list all run results #6460

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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