api

package
v2.49.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VSCSTargetLocal       = "local"
	VSCSTargetDevelopment = "development"
	VSCSTargetPPE         = "ppe"
	VSCSTargetProduction  = "production"
)
View Source
const (
	// CodespaceStateAvailable is the state for a running codespace environment.
	CodespaceStateAvailable = "Available"
	// CodespaceStateShutdown is the state for a shutdown codespace environment.
	CodespaceStateShutdown = "Shutdown"
	// CodespaceStateStarting is the state for a starting codespace environment.
	CodespaceStateStarting = "Starting"
	// CodespaceStateRebuilding is the state for a rebuilding codespace environment.
	CodespaceStateRebuilding = "Rebuilding"
)

Variables

View Source
var ListCodespaceFields = []string{
	"displayName",
	"name",
	"owner",
	"repository",
	"state",
	"gitStatus",
	"createdAt",
	"lastUsedAt",
	"machineName",
	"vscsTarget",
}

ListCodespaceFields is the list of exportable fields for a codespace when using the `gh cs list` command.

View Source
var ViewCodespaceFields = []string{
	"name",
	"displayName",
	"state",
	"owner",
	"billableOwner",
	"location",
	"repository",
	"gitStatus",
	"devcontainerPath",
	"machineName",
	"machineDisplayName",
	"prebuild",
	"createdAt",
	"lastUsedAt",
	"idleTimeoutMinutes",
	"retentionPeriodDays",
	"retentionExpiresAt",
	"recentFolders",
	"vscsTarget",
	"environmentId",
}

ViewCodespaceFields is the list of exportable fields for a codespace when using the `gh cs view` command.

Functions

This section is empty.

Types

type API

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

API is the interface to the codespace service.

func New

func New(f *cmdutil.Factory) *API

New creates a new API client connecting to the configured endpoints with the HTTP client.

func (*API) CreateCodespace

func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams) (*Codespace, error)

CreateCodespace creates a codespace with the given parameters and returns a non-nil error if it fails to create.

func (*API) DeleteCodespace

func (a *API) DeleteCodespace(ctx context.Context, codespaceName string, orgName string, userName string) error

DeleteCodespace deletes the given codespace.

func (*API) EditCodespace added in v2.6.0

func (a *API) EditCodespace(ctx context.Context, codespaceName string, params *EditCodespaceParams) (*Codespace, error)

func (*API) GetCodespace

func (a *API) GetCodespace(ctx context.Context, codespaceName string, includeConnection bool) (*Codespace, error)

GetCodespace returns the user codespace based on the provided name. If the codespace is not found, an error is returned. If includeConnection is true, it will return the connection information for the codespace.

func (*API) GetCodespaceBillableOwner added in v2.13.0

func (a *API) GetCodespaceBillableOwner(ctx context.Context, nwo string) (*User, error)

GetCodespaceBillableOwner returns the billable owner and expected default values for codespaces created by the user for a given repository.

func (*API) GetCodespaceRepoSuggestions added in v2.5.0

func (a *API) GetCodespaceRepoSuggestions(ctx context.Context, partialSearch string, parameters RepoSearchParameters) ([]string, error)

GetCodespaceRepoSuggestions searches for and returns repo names based on the provided search text.

func (*API) GetCodespaceRepositoryContents

func (a *API) GetCodespaceRepositoryContents(ctx context.Context, codespace *Codespace, path string) ([]byte, error)

func (*API) GetCodespacesMachines

func (a *API) GetCodespacesMachines(ctx context.Context, repoID int, branch, location string, devcontainerPath string) ([]*Machine, error)

GetCodespacesMachines returns the codespaces machines for the given repo, branch and location.

func (*API) GetCodespacesPermissionsCheck added in v2.37.0

func (a *API) GetCodespacesPermissionsCheck(ctx context.Context, repoID int, branch string, devcontainerPath string) (bool, error)

GetCodespacesPermissionsCheck returns a bool indicating whether the user has accepted permissions for the given repo and devcontainer path.

func (*API) GetOrgMemberCodespace added in v2.13.0

func (a *API) GetOrgMemberCodespace(ctx context.Context, orgName string, userName string, codespaceName string) (*Codespace, error)

func (*API) GetRepository

func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error)

GetRepository returns the repository associated with the given owner and name.

func (*API) GetUser

func (a *API) GetUser(ctx context.Context) (*User, error)

GetUser returns the user associated with the given token.

func (*API) HTTPClient added in v2.36.0

func (a *API) HTTPClient() (*http.Client, error)

HTTPClient returns the HTTP client used to make requests to the API.

func (*API) ListCodespaces

func (a *API) ListCodespaces(ctx context.Context, opts ListCodespacesOptions) (codespaces []*Codespace, err error)

ListCodespaces returns a list of codespaces for the user. Pass a negative limit to request all pages from the API until all codespaces have been fetched.

func (*API) ListDevContainers added in v2.9.0

func (a *API) ListDevContainers(ctx context.Context, repoID int, branch string, limit int) (devcontainers []DevContainerEntry, err error)

ListDevContainers returns a list of valid devcontainer.json files for the repo. Pass a negative limit to request all pages from the API until all devcontainer.json files have been fetched.

func (*API) ServerURL added in v2.33.0

func (a *API) ServerURL() string

ServerURL returns the server url (not the API url), such as https://github.com

func (*API) StartCodespace

func (a *API) StartCodespace(ctx context.Context, codespaceName string) error

StartCodespace starts a codespace for the user. If the codespace is already running, the returned error from the API is ignored.

func (*API) StopCodespace

func (a *API) StopCodespace(ctx context.Context, codespaceName string, orgName string, userName string) error

type AcceptPermissionsRequiredError added in v2.5.2

type AcceptPermissionsRequiredError struct {
	Message             string `json:"message"`
	AllowPermissionsURL string `json:"allow_permissions_url"`
}

func (AcceptPermissionsRequiredError) Error added in v2.5.2

type Codespace

type Codespace struct {
	Name                           string              `json:"name"`
	CreatedAt                      string              `json:"created_at"`
	DisplayName                    string              `json:"display_name"`
	LastUsedAt                     string              `json:"last_used_at"`
	Owner                          User                `json:"owner"`
	Repository                     Repository          `json:"repository"`
	State                          string              `json:"state"`
	GitStatus                      CodespaceGitStatus  `json:"git_status"`
	Connection                     CodespaceConnection `json:"connection"`
	Machine                        CodespaceMachine    `json:"machine"`
	RuntimeConstraints             RuntimeConstraints  `json:"runtime_constraints"`
	VSCSTarget                     string              `json:"vscs_target"`
	PendingOperation               bool                `json:"pending_operation"`
	PendingOperationDisabledReason string              `json:"pending_operation_disabled_reason"`
	IdleTimeoutNotice              string              `json:"idle_timeout_notice"`
	WebURL                         string              `json:"web_url"`
	DevContainerPath               string              `json:"devcontainer_path"`
	Prebuild                       bool                `json:"prebuild"`
	Location                       string              `json:"location"`
	IdleTimeoutMinutes             int                 `json:"idle_timeout_minutes"`
	RetentionPeriodMinutes         int                 `json:"retention_period_minutes"`
	RetentionExpiresAt             string              `json:"retention_expires_at"`
	RecentFolders                  []string            `json:"recent_folders"`
	BillableOwner                  User                `json:"billable_owner"`
	EnvironmentId                  string              `json:"environment_id"`
}

Codespace represents a codespace. You can see more about the fields in this type in the codespaces api docs: https://docs.github.com/en/rest/reference/codespaces

func (*Codespace) ExportData added in v2.2.0

func (c *Codespace) ExportData(fields []string) map[string]interface{}

type CodespaceConnection

type CodespaceConnection struct {
	TunnelProperties TunnelProperties `json:"tunnelProperties"`
}

type CodespaceGitStatus added in v2.2.0

type CodespaceGitStatus struct {
	Ahead                 int    `json:"ahead"`
	Behind                int    `json:"behind"`
	Ref                   string `json:"ref"`
	HasUnpushedChanges    bool   `json:"has_unpushed_changes"`
	HasUncommittedChanges bool   `json:"has_uncommitted_changes"`
}

type CodespaceMachine added in v2.6.0

type CodespaceMachine struct {
	Name            string `json:"name"`
	DisplayName     string `json:"display_name"`
	OperatingSystem string `json:"operating_system"`
	StorageInBytes  uint64 `json:"storage_in_bytes"`
	MemoryInBytes   uint64 `json:"memory_in_bytes"`
	CPUCount        int    `json:"cpus"`
}

type CreateCodespaceParams

type CreateCodespaceParams struct {
	RepositoryID           int
	IdleTimeoutMinutes     int
	RetentionPeriodMinutes *int
	Branch                 string
	Machine                string
	Location               string
	DevContainerPath       string
	VSCSTarget             string
	VSCSTargetURL          string
	PermissionsOptOut      bool
	DisplayName            string
}

CreateCodespaceParams are the required parameters for provisioning a Codespace.

type DevContainerEntry added in v2.9.0

type DevContainerEntry struct {
	Path string `json:"path"`
	Name string `json:"name,omitempty"`
}

type EditCodespaceParams added in v2.6.0

type EditCodespaceParams struct {
	DisplayName        string `json:"display_name,omitempty"`
	IdleTimeoutMinutes int    `json:"idle_timeout_minutes,omitempty"`
	Machine            string `json:"machine,omitempty"`
}

type ListCodespacesOptions added in v2.14.0

type ListCodespacesOptions struct {
	OrgName  string
	UserName string
	RepoName string
	Limit    int
}

type Machine

type Machine struct {
	Name                 string `json:"name"`
	DisplayName          string `json:"display_name"`
	PrebuildAvailability string `json:"prebuild_availability"`
}

type RepoSearchParameters added in v2.5.0

type RepoSearchParameters struct {
	// The maximum number of repos to return. At most 100 repos are returned even if this value is greater than 100.
	MaxRepos int
	// The sort order for returned repos. Possible values are 'stars', 'forks', 'help-wanted-issues', or 'updated'. If empty the API's default ordering is used.
	Sort string
}

RepoSearchParameters are the optional parameters for searching for repositories.

type Repository

type Repository struct {
	ID            int             `json:"id"`
	FullName      string          `json:"full_name"`
	DefaultBranch string          `json:"default_branch"`
	Owner         RepositoryOwner `json:"owner"`
}

Repository represents a GitHub repository.

type RepositoryOwner added in v2.29.0

type RepositoryOwner struct {
	Type  string `json:"type"`
	Login string `json:"login"`
}

RepositoryOwner represents owner of a repository

type RuntimeConstraints added in v2.36.0

type RuntimeConstraints struct {
	AllowedPortPrivacySettings []string `json:"allowed_port_privacy_settings"`
}

type TunnelProperties added in v2.36.0

type TunnelProperties struct {
	ConnectAccessToken     string `json:"connectAccessToken"`
	ManagePortsAccessToken string `json:"managePortsAccessToken"`
	ServiceUri             string `json:"serviceUri"`
	TunnelId               string `json:"tunnelId"`
	ClusterId              string `json:"clusterId"`
	Domain                 string `json:"domain"`
}

type User

type User struct {
	Login string `json:"login"`
	Type  string `json:"type"`
}

User represents a GitHub user.

Jump to

Keyboard shortcuts

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