fetchRemoteExperimentDetails reads the state.json from a remote experiment branch.
(repoOverride, branchName, workflowID string)
| 578 | |
| 579 | // fetchRemoteExperimentDetails reads the state.json from a remote experiment branch. |
| 580 | func fetchRemoteExperimentDetails(repoOverride, branchName, workflowID string) (*ExperimentDetails, error) { |
| 581 | experimentsLog.Printf("Fetching remote experiment details: repo=%s, branch=%s", repoOverride, branchName) |
| 582 | |
| 583 | // Verify the branch exists. |
| 584 | encodedBranch := url.PathEscape(branchName) |
| 585 | checkArgs := []string{"api", |
| 586 | "repos/{owner}/{repo}/branches/" + encodedBranch, |
| 587 | "--jq", ".name", |
| 588 | "--repo", repoOverride, |
| 589 | } |
| 590 | checkCmd := workflow.ExecGH(checkArgs...) |
| 591 | if _, err := checkCmd.Output(); err != nil { |
| 592 | var exitErr *exec.ExitError |
| 593 | if errors.As(err, &exitErr) { |
| 594 | stderr := strings.TrimSpace(string(exitErr.Stderr)) |
| 595 | if strings.Contains(stderr, "404") || strings.Contains(stderr, "not found") { |
| 596 | return nil, fmt.Errorf("experiment %q not found in %s", workflowID, repoOverride) |
| 597 | } |
| 598 | return nil, fmt.Errorf("failed to fetch experiment branch (exit %d): %s", exitErr.ExitCode(), stderr) |
| 599 | } |
| 600 | return nil, fmt.Errorf("failed to fetch experiment branch: %w", err) |
| 601 | } |
| 602 | |
| 603 | state := readRemoteExperimentState(repoOverride, branchName) |
| 604 | return experimentDetailsFromState(workflowID, branchName, state), nil |
| 605 | } |
| 606 | |
| 607 | // readLocalExperimentState reads state.json from a local git ref (e.g. "origin/experiments/foo"). |
| 608 | // Returns an empty state when the file is absent or cannot be parsed. |
no test coverage detected