MCPcopy Create free account
hub / github.com/github/gh-aw / readRemoteExperimentState

Function readRemoteExperimentState

pkg/cli/experiments_command.go:620–642  ·  view source on GitHub ↗

readRemoteExperimentState fetches state.json from an experiments/* branch via the GitHub API. Returns an empty state on any error (branch missing, file absent, parse failure).

(repoOverride, branchName string)

Source from the content-addressed store, hash-verified

618// readRemoteExperimentState fetches state.json from an experiments/* branch via the GitHub API.
619// Returns an empty state on any error (branch missing, file absent, parse failure).
620func readRemoteExperimentState(repoOverride, branchName string) *ExperimentState {
621 args := []string{"api",
622 "repos/{owner}/{repo}/contents/state.json",
623 "--field", "ref=" + branchName,
624 "--jq", ".content",
625 "--repo", repoOverride,
626 }
627 cmd := workflow.ExecGH(args...)
628 out, err := cmd.Output()
629 if err != nil {
630 return emptyExperimentState()
631 }
632
633 // GitHub API returns base64-encoded content with embedded newlines for line-wrapping.
634 // Strip all whitespace before decoding.
635 b64 := strings.Join(strings.Fields(strings.TrimSpace(string(out))), "")
636 decoded, err := base64.StdEncoding.DecodeString(b64)
637 if err != nil {
638 experimentsLog.Printf("Failed to base64-decode state.json from %s: %v", branchName, err)
639 return emptyExperimentState()
640 }
641 return parseExperimentState(decoded)
642}
643
644// parseExperimentState unmarshals raw JSON into an ExperimentState.
645// Returns an empty state when parsing fails or the data is invalid.

Callers 2

fetchRemoteExperimentsFunction · 0.85

Calls 4

ExecGHFunction · 0.92
emptyExperimentStateFunction · 0.85
parseExperimentStateFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected