fetchRemoteExperiments lists experiment branches and reads their state via the GitHub API.
(repoOverride string)
| 527 | |
| 528 | // fetchRemoteExperiments lists experiment branches and reads their state via the GitHub API. |
| 529 | func fetchRemoteExperiments(repoOverride string) ([]ExperimentInfo, error) { |
| 530 | experimentsLog.Printf("Fetching remote experiment branches: repo=%s", repoOverride) |
| 531 | |
| 532 | args := []string{"api", "repos/{owner}/{repo}/branches", |
| 533 | "--paginate", |
| 534 | "--jq", `[.[] | select(.name | startswith("` + experimentsBranchPrefix + `")) | .name]`, |
| 535 | "--repo", repoOverride, |
| 536 | } |
| 537 | cmd := workflow.ExecGH(args...) |
| 538 | output, err := cmd.Output() |
| 539 | if err != nil { |
| 540 | var exitErr *exec.ExitError |
| 541 | if errors.As(err, &exitErr) { |
| 542 | return nil, fmt.Errorf("failed to fetch branches (exit %d): %s", exitErr.ExitCode(), strings.TrimSpace(string(exitErr.Stderr))) |
| 543 | } |
| 544 | return nil, fmt.Errorf("failed to fetch branches: %w", err) |
| 545 | } |
| 546 | |
| 547 | branchNames, err := parsePagedJSONArray[string](string(output)) |
| 548 | if err != nil { |
| 549 | return nil, fmt.Errorf("failed to parse branch list: %w", err) |
| 550 | } |
| 551 | |
| 552 | var experiments []ExperimentInfo |
| 553 | for _, branchName := range branchNames { |
| 554 | workflowID := strings.TrimPrefix(branchName, experimentsBranchPrefix) |
| 555 | state := readRemoteExperimentState(repoOverride, branchName) |
| 556 | experiments = append(experiments, experimentInfoFromState(workflowID, branchName, state)) |
| 557 | } |
| 558 | |
| 559 | return experiments, nil |
| 560 | } |
| 561 | |
| 562 | // fetchLocalExperimentDetails reads the state.json from a local experiment branch. |
| 563 | func fetchLocalExperimentDetails(branchName, workflowID string) (*ExperimentDetails, error) { |
no test coverage detected