api

package
v2.5.0-pre13 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

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"
)

Variables

View Source
var CodespaceFields = []string{
	"name",
	"owner",
	"repository",
	"state",
	"gitStatus",
	"createdAt",
	"lastUsedAt",
}

CodespaceFields is the list of exportable fields for a codespace.

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(serverURL, apiURL, vscsURL string, httpClient httpClient) *API

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

func (*API) AuthorizedKeys

func (a *API) AuthorizedKeys(ctx context.Context, user string) ([]byte, error)

AuthorizedKeys returns the public keys (in ~/.ssh/authorized_keys format) registered by the specified GitHub user.

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) error

DeleteCodespace deletes the given codespace.

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) GetCodespaceRegionLocation

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

GetCodespaceRegionLocation returns the closest codespace location for the user.

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) ([]*Machine, error)

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

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) ListCodespaces

func (a *API) ListCodespaces(ctx context.Context, limit int) (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) 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) error

type Codespace

type Codespace struct {
	Name       string              `json:"name"`
	CreatedAt  string              `json:"created_at"`
	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"`
}

Codespace represents a codespace.

func (*Codespace) ExportData added in v2.2.0

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

type CodespaceConnection

type CodespaceConnection struct {
	SessionID      string   `json:"sessionId"`
	SessionToken   string   `json:"sessionToken"`
	RelayEndpoint  string   `json:"relayEndpoint"`
	RelaySAS       string   `json:"relaySas"`
	HostPublicKeys []string `json:"hostPublicKeys"`
}

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"`
	HasUncommitedChanges bool   `json:"has_uncommited_changes"`
}

type CreateCodespaceParams

type CreateCodespaceParams struct {
	RepositoryID       int
	IdleTimeoutMinutes int
	Branch             string
	Machine            string
	Location           string
}

CreateCodespaceParams are the required parameters for provisioning a Codespace.

type Machine

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

type Repository

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

Repository represents a GitHub repository.

type User

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

User represents a GitHub user.

Jump to

Keyboard shortcuts

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