Help us shape the future of Go! Take the 2026 Go Developer Survey

github

package
v1.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GitSshProtocolType   = "ssh"
	GitHttpsProtocolType = "https"
)

Variables

View Source
var (
	ErrGitHubCliNotLoggedIn = errors.New("gh cli is not logged in")
	ErrUserNotAuthorized    = errors.New("user is not authorized. " +
		"Try running gh auth refresh with the required scopes to request additional authorization")
	ErrRepositoryNameInUse = errors.New("repository name already in use")

	// The hostname of the public GitHub service.
	GitHubHostName = "github.com"

	// Environment variable that gh cli uses for auth token overrides
	TokenEnvVars = []string{"GITHUB_TOKEN", "GH_TOKEN"}
)
View Source
var Version semver.Version = semver.MustParse("2.89.0")

Version is the minimum version of GitHub cli that we require (and the one we fetch when we fetch gh on behalf of a user).

Functions

func RunningOnCodespaces

func RunningOnCodespaces() bool

RunningOnCodespaces check if the application is running on codespaces.

Types

type ApiCallOptions

type ApiCallOptions struct {
	Headers []string
}

ApiCallOptions represent the options for the ApiCall method.

type AuthStatus

type AuthStatus struct {
	LoggedIn bool
}

The result from calling GetAuthStatus

type Cli

type Cli struct {
	// contains filtered or unexported fields
}

func NewGitHubCli

func NewGitHubCli(console input.Console, commandRunner exec.CommandRunner) *Cli

NewGitHubCli creates a new GitHub CLI wrapper. The CLI is not yet installed; call EnsureInstalled before using methods that require the gh binary.

func (*Cli) ApiCall

func (cli *Cli) ApiCall(ctx context.Context, hostname, path string, options ApiCallOptions) (string, error)

ApiCall uses gh cli to call https://api.<hostname>/<path>.

func (*Cli) BinaryPath

func (cli *Cli) BinaryPath() string

func (*Cli) CheckInstalled

func (cli *Cli) CheckInstalled(ctx context.Context) error

func (*Cli) CreateEnvironmentIfNotExist

func (cli *Cli) CreateEnvironmentIfNotExist(ctx context.Context, repoName string, envName string) error

func (*Cli) CreatePrivateRepository

func (cli *Cli) CreatePrivateRepository(ctx context.Context, name string) error

func (*Cli) DeleteEnvironment

func (cli *Cli) DeleteEnvironment(ctx context.Context, repoName string, envName string) error

func (*Cli) DeleteSecret

func (cli *Cli) DeleteSecret(ctx context.Context, repoSlug string, name string) error

func (*Cli) DeleteVariable

func (cli *Cli) DeleteVariable(ctx context.Context, repoSlug string, name string) error

func (*Cli) EnsureInstalled

func (cli *Cli) EnsureInstalled(ctx context.Context) error

EnsureInstalled checks if GitHub CLI is available and downloads/upgrades if needed. This is safe to call multiple times; successful installation is cached and failed attempts are retried. Should be called with a request-scoped context before first use.

func (*Cli) GetAuthStatus

func (cli *Cli) GetAuthStatus(ctx context.Context, hostname string) (AuthStatus, error)

func (*Cli) GetGitProtocolType

func (cli *Cli) GetGitProtocolType(ctx context.Context) (string, error)

func (*Cli) GitHubActionsExists

func (cli *Cli) GitHubActionsExists(ctx context.Context, repoSlug string) (bool, error)

GitHubActionsExists gets the information from upstream about the workflows and return true if there is at least one workflow in the repo.

func (*Cli) InstallUrl

func (cli *Cli) InstallUrl() string

func (*Cli) ListRepositories

func (cli *Cli) ListRepositories(ctx context.Context) ([]GhCliRepository, error)

func (*Cli) ListSecrets

func (cli *Cli) ListSecrets(ctx context.Context, repoSlug string) ([]string, error)

func (*Cli) ListVariables

func (cli *Cli) ListVariables(
	ctx context.Context,
	repoSlug string,
	options *ListVariablesOptions,
) (map[string]string, error)

func (*Cli) Login

func (cli *Cli) Login(ctx context.Context, hostname string) error

func (*Cli) Name

func (cli *Cli) Name() string

func (*Cli) SetSecret

func (cli *Cli) SetSecret(ctx context.Context, repoSlug string, name string, value string) error

func (*Cli) SetVariable

func (cli *Cli) SetVariable(
	ctx context.Context,
	repoSlug string,
	name string,
	value string,
	options *SetVariableOptions,
) error

func (*Cli) ViewRepository

func (cli *Cli) ViewRepository(ctx context.Context, name string) (GhCliRepository, error)

type GhCliRepository

type GhCliRepository struct {
	// The slug for a repository (formatted as "<owner>/<name>")
	NameWithOwner string
	// The Url for the HTTPS endpoint for the repository
	HttpsUrl string `json:"url"`
	// The Url for the SSH endpoint for the repository
	SshUrl string
}

type GitHubActionsResponse

type GitHubActionsResponse struct {
	TotalCount int `json:"total_count"`
}

type ListVariablesOptions

type ListVariablesOptions struct {
	Environment string
}

type SetVariableOptions

type SetVariableOptions struct {
	Environment string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL