Documentation
¶
Overview ¶
Package githubrepos lists the signed-in account's GitHub repositories for picking and clones a picked repository with the same sign-in. See README.md.
Index ¶
- Constants
- type CloneState
- type Item
- type Lister
- type Listing
- type Registry
- type Service
- func (s *Service) DefaultDir(ctx context.Context, owner, name string) (string, error)
- func (s *Service) Handler() http.Handler
- func (s *Service) Listing(ctx context.Context, query string, refresh, more bool) (Listing, error)
- func (s *Service) ResetIdentity()
- func (s *Service) Run(ctx context.Context)
Constants ¶
const ( // CacheTTL is how long a listing is reused; ?refresh=1 skips it. CacheTTL = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloneState ¶
type CloneState struct {
Repository string `json:"repository"`
Dir string `json:"dir"`
// State is running, done or failed.
State string `json:"state"`
Error string `json:"error,omitempty"`
// Code names a failure the app explains itself, such as url_rewritten.
Code string `json:"code,omitempty"`
}
CloneState is a clone's progress, as the API serves it.
type Item ¶
type Item struct {
Repository string `json:"repository"`
Private bool `json:"private"`
Top bool `json:"top"`
Fork bool `json:"fork"`
PushedAt *time.Time `json:"pushed_at"`
Description string `json:"description"`
Picked bool `json:"picked"`
// Clone is an available registered clone of a picked repository, or "".
// Clones are looked for only once a repository is picked.
Clone string `json:"clone"`
// EarlierNames are names GitHub forwards to a picked repository that its
// clones' remotes were registered with.
EarlierNames []string `json:"earlier_names,omitempty"`
}
Item is one repository in the listing.
type Lister ¶
type Lister interface {
ViewerRepositories(ctx context.Context, host string, first int, cursor *string) (github.ViewerRepositoryList, error)
SearchRepositories(ctx context.Context, host, query string, scope github.SearchScope, cursor *string) (github.ViewerRepositoryList, error)
}
Lister reads the account's repositories from GitHub.
type Listing ¶
type Listing struct {
FetchedAt time.Time `json:"fetched_at"`
TotalCount int `json:"total_count"`
Repositories []Item `json:"repositories"`
Searching bool `json:"searching,omitempty"`
SearchError string `json:"search_error,omitempty"`
TopRepositories []Item `json:"top_repositories,omitempty"`
// HasMore says GitHub has another page for this query, which ?more=1 loads.
HasMore bool `json:"has_more,omitempty"`
}
Listing is the JSON of GET /api/github/repositories.
type Registry ¶
type Registry interface {
Repositories(context.Context) ([]repos.Repository, error)
CloneRows(context.Context) ([]repos.Clone, error)
Pick(ctx context.Context, repository string, settings *repos.Settings) (repos.Repository, error)
AddFor(ctx context.Context, path, repository string, settings *repos.Settings) (repos.Clone, error)
}
Registry is the part of the repository registry the service uses.
type Service ¶
type Service struct {
Lister Lister
Registry Registry
// Token returns the GitHub token for github.com; an error wrapping
// config.ErrNoGitHubToken means signed out, and clones are anonymous.
Token func(ctx context.Context) (string, error)
// Clone runs the clone; nil uses gitlocal.Clone.
Clone func(ctx context.Context, opts gitlocal.CloneOptions) error
// Health reports the runtime health of the GitHub sign-in after a failed
// request (config.GitHubAuth.Health); nil means healthy.
Health func() error
// Home is the home directory used for clone targets (including top-level
// code-folder symlinks to another disk).
Home string
// Context ends running clones when the daemon stops; nil means never.
Context context.Context
// Changed tells the app the registry changed.
Changed func()
Now func() time.Time
// contains filtered or unexported fields
}
Service serves the listing and the clone API. It has no authentication: the daemon mounts Handler behind its authenticated host and origin checks, because it returns and writes local paths.
func (*Service) DefaultDir ¶
DefaultDir is where a repository is cloned unless the person chooses. Beside the registered clones: the most common parent directory below home, so <parent>/<name>; but if the clones are laid out as <root>/<owner>/<name> (their parent is named after their owner), <root>/<owner>/<name>. With no clone, ~/code/<owner>/<name>. -2, -3... is appended while the path exists. The result always passes the location rule POST applies.
func (*Service) Listing ¶
Listing combines immediate cached top matches with a cached GitHub search. more starts loading the query's next page.
func (*Service) ResetIdentity ¶
func (s *Service) ResetIdentity()
ResetIdentity drops the cached listing, which belongs to the account that was signed in.