MCPcopy Index your code
hub / github.com/chainloop-dev/chainloop / List

Method List

app/controlplane/pkg/data/workflow.go:266–319  ·  view source on GitHub ↗
(ctx context.Context, orgID uuid.UUID, filter *biz.WorkflowListOpts, pagination *pagination.OffsetPaginationOpts)

Source from the content-addressed store, hash-verified

264}
265
266func (r *WorkflowRepo) List(ctx context.Context, orgID uuid.UUID, filter *biz.WorkflowListOpts, pagination *pagination.OffsetPaginationOpts) ([]*biz.Workflow, int, error) {
267 ctx, span := otelx.Start(ctx, workflowRepoTracer, "WorkflowRepo.List")
268 defer span.End()
269
270 if pagination == nil {
271 return nil, 0, fmt.Errorf("pagination options is required")
272 }
273
274 // Initialize the base query for WorkflowRun
275 baseQuery := orgScopedQuery(r.data.DB, orgID).QueryWorkflows()
276
277 // Apply filters to the WorkflowRun query based on the provided options
278 baseQuery = applyWorkflowRunFilters(baseQuery, filter)
279
280 // Initialize the Workflow query and apply organization and deletion filters
281 wfQuery := baseQuery.Where(workflow.DeletedAtIsNil())
282
283 // Apply additional filters to the Workflow query based on the provided options
284 wfQuery, err := applyWorkflowFilters(wfQuery, filter)
285 if err != nil {
286 return nil, 0, err
287 }
288
289 // Get the count of all filtered rows without the limit and offset
290 count, err := wfQuery.Count(ctx)
291 if err != nil {
292 return nil, 0, err
293 }
294
295 // Apply pagination options and execute the query
296 workflows, err := wfQuery.
297 WithLatestWorkflowRun().
298 WithContract().
299 WithProject().
300 Order(ent.Desc(workflow.FieldCreatedAt)).
301 Limit(pagination.Limit()).
302 Offset(pagination.Offset()).
303 All(ctx)
304 if err != nil {
305 return nil, 0, err
306 }
307
308 result := make([]*biz.Workflow, 0, len(workflows))
309 for _, wf := range workflows {
310 r, err := entWFToBizWF(ctx, wf)
311 if err != nil {
312 return nil, 0, fmt.Errorf("converting entity: %w", err)
313 }
314
315 result = append(result, r)
316 }
317
318 return result, count, nil
319}
320
321// applyWorkflowRunFilters applies filters to the WorkflowRun query based on the provided options
322func applyWorkflowRunFilters(baseQuery *ent.WorkflowQuery, opts *biz.WorkflowListOpts) *ent.WorkflowQuery {

Callers

nothing calls this directly

Implementers 1

WorkflowRepoapp/controlplane/pkg/data/workflow.go

Calls 15

StartFunction · 0.92
DeletedAtIsNilFunction · 0.92
DescFunction · 0.92
orgScopedQueryFunction · 0.85
applyWorkflowRunFiltersFunction · 0.85
applyWorkflowFiltersFunction · 0.85
entWFToBizWFFunction · 0.85
WithLatestWorkflowRunMethod · 0.80
QueryWorkflowsMethod · 0.45
WhereMethod · 0.45
CountMethod · 0.45
AllMethod · 0.45

Tested by

no test coverage detected