api

package
v2.0.0-...-98537dd Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: MIT Imports: 16 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 CodespaceFields = []string{
	"displayName",
	"name",
	"owner",
	"repository",
	"state",
	"gitStatus",
	"createdAt",
	"lastUsedAt",
	"machineName",
	"vscsTarget",
}

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

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

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

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

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

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

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

func (AcceptPermissionsRequiredError) Error

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"`
	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"`
}

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

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

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 CodespaceMachine

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
}

CreateCodespaceParams are the required parameters for provisioning a Codespace.

type DevContainerEntry

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

type EditCodespaceParams

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

type ListCodespacesOptions

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

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"`
}

Repository represents a GitHub repository.

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