Skip to content

Commit

Permalink
feat(api): load pipelines with usages (#6304)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin committed Sep 26, 2022
1 parent f18ed88 commit d293f83
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions engine/api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ func (api *API) getPipelinesHandler() service.Handler {
// Get project name in URL
vars := mux.Vars(r)
key := vars[permProjectKey]
withUsage := service.FormBool(r, "withUsage")
withoutDetails := service.FormBool(r, "withoutDetails")

project, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default)
if err != nil {
Expand All @@ -389,15 +391,27 @@ func (api *API) getPipelinesHandler() service.Handler {
return err
}

pip, err := pipeline.LoadPipelines(api.mustDB(), project.ID, true)
pips, err := pipeline.LoadPipelines(api.mustDB(), project.ID, withoutDetails)
if err != nil {
if !sdk.ErrorIs(err, sdk.ErrPipelineNotFound) {
log.Warn(ctx, "getPipelinesHandler>Cannot load pipelines: %s\n", err)
}
return err
}

return service.WriteJSON(w, pip, http.StatusOK)
if withUsage {
for i := range pips {
p := &pips[i]
wf, err := workflow.LoadByPipelineName(ctx, api.mustDB(), key, p.Name)
if err != nil {
return sdk.WrapError(err, "cannot load workflows using pipeline %s", p.Name)
}
p.Usage = &sdk.Usage{}
p.Usage.Workflows = wf
}
}

return service.WriteJSON(w, pips, http.StatusOK)
}
}

Expand Down

0 comments on commit d293f83

Please sign in to comment.