ListDescendantEnvironments returns environments that are descendants of the given commit. This filters environments to only those where the provided commit is an ancestor of the environment's current HEAD. Environments are sorted by most recently updated first.
(ctx context.Context, ancestorCommit string)
| 334 | // This filters environments to only those where the provided commit is an ancestor |
| 335 | // of the environment's current HEAD. Environments are sorted by most recently updated first. |
| 336 | func (r *Repository) ListDescendantEnvironments(ctx context.Context, ancestorCommit string) ([]*environment.EnvironmentInfo, error) { |
| 337 | allEnvs, err := r.List(ctx) |
| 338 | if err != nil { |
| 339 | return nil, err |
| 340 | } |
| 341 | |
| 342 | var filteredEnvs []*environment.EnvironmentInfo |
| 343 | for _, env := range allEnvs { |
| 344 | if r.isDescendantOfCommit(ctx, ancestorCommit, env.ID) { |
| 345 | filteredEnvs = append(filteredEnvs, env) |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | return filteredEnvs, nil |
| 350 | } |
| 351 | |
| 352 | // isDescendantOfCommit checks if the environment is a descendant of the given commit |
| 353 | // using git merge-base --is-ancestor which is the canonical way to check ancestry |