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

Function fetchLocalExperiments

pkg/cli/experiments_command.go:482–526  ·  view source on GitHub ↗

fetchLocalExperiments lists experiment branches and reads their state from the local git repo.

()

Source from the content-addressed store, hash-verified

480
481// fetchLocalExperiments lists experiment branches and reads their state from the local git repo.
482func fetchLocalExperiments() ([]ExperimentInfo, error) {
483 experimentsLog.Print("Fetching local experiment branches via git for-each-ref")
484
485 cmd := exec.Command("git", "for-each-ref",
486 "--sort=-committerdate",
487 "--format=%(refname:short)",
488 "refs/remotes/origin/"+experimentsBranchPrefix+"*",
489 "refs/heads/"+experimentsBranchPrefix+"*",
490 )
491 output, err := cmd.Output()
492 if err != nil {
493 var exitErr *exec.ExitError
494 if errors.As(err, &exitErr) && exitErr.ExitCode() == 128 {
495 return []ExperimentInfo{}, nil
496 }
497 return nil, fmt.Errorf("failed to list experiment branches: %w", err)
498 }
499
500 seen := make(map[string]struct {
501 })
502 var experiments []ExperimentInfo
503
504 for line := range strings.SplitSeq(strings.TrimSpace(string(output)), "\n") {
505 if line == "" {
506 continue
507 }
508 workflowID := extractExperimentName(line)
509 if workflowID == "" || setutil.Contains(seen, workflowID) {
510 continue
511 }
512 seen[workflowID] = struct {
513 }{}
514
515 branchName := experimentsBranchPrefix + workflowID
516 // Prefer remote ref; fall back to local.
517 ref := "origin/" + branchName
518 if !gitRefExists(ref) {
519 ref = branchName
520 }
521 state := readLocalExperimentState(ref)
522 experiments = append(experiments, experimentInfoFromState(workflowID, branchName, state))
523 }
524
525 return experiments, nil
526}
527
528// fetchRemoteExperiments lists experiment branches and reads their state via the GitHub API.
529func fetchRemoteExperiments(repoOverride string) ([]ExperimentInfo, error) {

Callers 1

RunExperimentsListFunction · 0.85

Calls 7

ContainsFunction · 0.92
extractExperimentNameFunction · 0.85
gitRefExistsFunction · 0.85
readLocalExperimentStateFunction · 0.85
experimentInfoFromStateFunction · 0.85
PrintMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected