Skip to content

Commit d293f83

Browse files
authored
feat(api): load pipelines with usages (#6304)
1 parent f18ed88 commit d293f83

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

engine/api/pipeline.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ func (api *API) getPipelinesHandler() service.Handler {
380380
// Get project name in URL
381381
vars := mux.Vars(r)
382382
key := vars[permProjectKey]
383+
withUsage := service.FormBool(r, "withUsage")
384+
withoutDetails := service.FormBool(r, "withoutDetails")
383385

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

392-
pip, err := pipeline.LoadPipelines(api.mustDB(), project.ID, true)
394+
pips, err := pipeline.LoadPipelines(api.mustDB(), project.ID, withoutDetails)
393395
if err != nil {
394396
if !sdk.ErrorIs(err, sdk.ErrPipelineNotFound) {
395397
log.Warn(ctx, "getPipelinesHandler>Cannot load pipelines: %s\n", err)
396398
}
397399
return err
398400
}
399401

400-
return service.WriteJSON(w, pip, http.StatusOK)
402+
if withUsage {
403+
for i := range pips {
404+
p := &pips[i]
405+
wf, err := workflow.LoadByPipelineName(ctx, api.mustDB(), key, p.Name)
406+
if err != nil {
407+
return sdk.WrapError(err, "cannot load workflows using pipeline %s", p.Name)
408+
}
409+
p.Usage = &sdk.Usage{}
410+
p.Usage.Workflows = wf
411+
}
412+
}
413+
414+
return service.WriteJSON(w, pips, http.StatusOK)
401415
}
402416
}
403417

0 commit comments

Comments
 (0)