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)
| 294 | // Returns EnvironmentInfo slice avoiding dagger client initialization. |
| 295 | // Use Get() on individual environments when you need full Environment with container operations. |
| 296 | func (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 |