MCPcopy
hub / github.com/dagger/container-use / List

Method List

repository/repository.go:296–331  ·  view source on GitHub ↗

List returns information about all environments in the repository. Returns EnvironmentInfo slice avoiding dagger client initialization. Use Get() on individual environments when you need full Environment with container operations.

(ctx context.Context)

Source from the content-addressed store, hash-verified

294// Returns EnvironmentInfo slice avoiding dagger client initialization.
295// Use Get() on individual environments when you need full Environment with container operations.
296func (r *Repository) List(ctx context.Context) ([]*environment.EnvironmentInfo, error) {
297 branches, err := RunGitCommand(ctx, r.forkRepoPath, "branch", "--format", "%(refname:short)")
298 if err != nil {
299 return nil, err
300 }
301
302 envs := []*environment.EnvironmentInfo{}
303 for branch := range strings.SplitSeq(branches, "\n") {
304 branch = strings.TrimSpace(branch)
305
306 // FIXME(aluzzardi): This is a hack to make sure the branch is actually an environment.
307 // There must be a better way to do this.
308 worktree, err := r.WorktreePath(branch)
309 if err != nil {
310 return nil, err
311 }
312 state, err := r.loadState(ctx, worktree)
313 if err != nil || state == nil {
314 continue
315 }
316
317 envInfo, err := r.Info(ctx, branch)
318 if err != nil {
319 return nil, err
320 }
321
322 envs = append(envs, envInfo)
323 }
324
325 // Sort by most recently updated environments first
326 sort.Slice(envs, func(i, j int) bool {
327 return envs[i].State.UpdatedAt.After(envs[j].State.UpdatedAt)
328 })
329
330 return envs, nil
331}
332
333// ListDescendantEnvironments returns environments that are descendants of the given commit.
334// This filters environments to only those where the provided commit is an ancestor

Callers 8

WithRepositoryFunction · 0.80
TestRepositoryListFunction · 0.80
TestEnvironmentSelectionFunction · 0.80
delete.goFile · 0.80
suggestEnvironmentsFunction · 0.80
list.goFile · 0.80

Calls 4

WorktreePathMethod · 0.95
loadStateMethod · 0.95
InfoMethod · 0.95
RunGitCommandFunction · 0.85

Tested by 2

TestRepositoryListFunction · 0.64
TestEnvironmentSelectionFunction · 0.64