codespace¶
Package codespace wraps the GitHub CLI (gh) to list, create, delete, and SSH into GitHub Codespaces. All GitHub API interactions go through the GHRunner interface so they can be stubbed in tests.
Index¶
- func BuildCreateArgs(target config.Target) []string
- func DeleteCodespace(runner GHRunner, name string) error
- func DescribeCodespace(cs *Codespace, recommended bool) string
- func EnsureGHAuth(runner GHRunner) error
- func EnsureReachable(runner GHRunner, codespaceName string) error
- func FindZedBinary() (string, error)
- func GetSSHConfig(runner GHRunner, codespaceName string) (string, error)
- func ListAllRepos(runner GHRunner) ([]string, error)
- func MatchesTarget(cs *Codespace, t *config.Target) bool
- func RequireCommand(name string) error
- func UniqueRepos(codespaces []Codespace) []string
- type Codespace
- func ChooseCodespace(codespaces []Codespace, t *config.Target) (*Codespace, error)
- func CreateCodespace(runner GHRunner, target config.Target) (*Codespace, error)
- func CreateCodespaceInteractive(runner GHRunner, target config.Target) (*Codespace, error)
- func FilterByRepo(codespaces []Codespace, repo string) []Codespace
- func FindMatching(codespaces []Codespace, t *config.Target) []Codespace
- func ListAllCodespaces(runner GHRunner) ([]Codespace, error)
- func ListCodespaces(runner GHRunner, repository string) ([]Codespace, error)
- type DefaultGHRunner
- func (d DefaultGHRunner) Run(args []string) (string, error)
- func (d DefaultGHRunner) RunInteractive(args []string) (string, error)
- func (d DefaultGHRunner) RunMerged(args []string) (string, error)
- type GHRunner
- type GitStatus
- type RepoField
- func (r *RepoField) UnmarshalJSON(data []byte) error
func BuildCreateArgs¶
BuildCreateArgs builds the gh codespace create command arguments.
func DeleteCodespace¶
DeleteCodespace deletes a codespace by name.
func DescribeCodespace¶
DescribeCodespace returns a human-readable description.
func EnsureGHAuth¶
EnsureGHAuth verifies the user is authenticated with gh.
func EnsureReachable¶
EnsureReachable verifies the codespace SSH server is accessible.
func FindZedBinary¶
FindZedBinary returns the path to the Zed editor CLI binary. It checks "zed" first (Zed.app / Homebrew), then "zeditor" (nix).
func GetSSHConfig¶
GetSSHConfig retrieves the OpenSSH config for a codespace.
func ListAllRepos¶
ListAllRepos returns all repositories the user has access to.
func MatchesTarget¶
MatchesTarget checks whether a codespace matches a config target.
func RequireCommand¶
RequireCommand checks that a command is on PATH.
func UniqueRepos¶
UniqueRepos extracts sorted unique repository names from codespaces.
type Codespace¶
type Codespace struct {
Name string `json:"name"`
DisplayName string `json:"displayName,omitempty"`
Repository RepoField `json:"repository"`
State string `json:"state,omitempty"`
GitStatus *GitStatus `json:"gitStatus,omitempty"`
}
func ChooseCodespace¶
ChooseCodespace auto-selects a codespace in non-interactive mode. Returns nil if no match, errors if ambiguous.
func CreateCodespace¶
CreateCodespace creates a new codespace and returns its details.
func CreateCodespaceInteractive¶
CreateCodespaceInteractive creates a codespace with terminal access so gh can prompt the user if needed (e.g. machine type selection). Output is shown on the terminal in real time.
func FilterByRepo¶
FilterByRepo returns codespaces belonging to a given repository.
func FindMatching¶
FindMatching returns all codespaces matching the target.
func ListAllCodespaces¶
ListAllCodespaces returns all codespaces across all repos.
func ListCodespaces¶
ListCodespaces returns all codespaces for a given repository.
type DefaultGHRunner¶
DefaultGHRunner executes real gh commands.
func (DefaultGHRunner) Run¶
func (DefaultGHRunner) RunInteractive¶
func (DefaultGHRunner) RunMerged¶
type GHRunner¶
GHRunner abstracts the GitHub CLI for testability.
type GHRunner interface {
Run(args []string) (string, error)
RunMerged(args []string) (string, error)
// RunInteractive runs a command with stdin connected and output teed to
// both a capture buffer and the real terminal. Use this when the gh
// subprocess may need to prompt the user (e.g. machine-type selection).
RunInteractive(args []string) (string, error)
}
type GitStatus¶
type RepoField¶
RepoField handles the gh CLI returning repository as either a string or an object.
func (*RepoField) UnmarshalJSON¶
Generated by gomarkdoc