Documentation
¶
Overview ¶
Package repopreview builds the read-only repository card shown before an app is created from a git URL. It only talks to known git hosts.
Index ¶
Constants ¶
const ( EnvTimeout = "APP_REPO_PREVIEW_TIMEOUT" EnvCacheTTL = "APP_REPO_PREVIEW_CACHE_TTL" EnvMaxBranches = "APP_REPO_PREVIEW_MAX_BRANCHES" EnvReadmeChars = "APP_REPO_PREVIEW_README_CHARS" EnvCacheMax = "APP_REPO_PREVIEW_CACHE_MAX" )
Env vars bounding one preview.
Variables ¶
var ( // ErrNotFound means the host has no such repository, or hides it from this caller. ErrNotFound = errors.New("repopreview: repository not found") // ErrRateLimited means the host throttled the request. ErrRateLimited = errors.New("repopreview: host rate limited") // ErrNoMetadata means the host is known but exposes no metadata API here. ErrNoMetadata = errors.New("repopreview: no metadata api for host") )
Functions ¶
Types ¶
type AnalyzeFunc ¶
AnalyzeFunc runs the stack analysis for a repository and ref.
type Builder ¶
type Builder struct {
Client HostClient
Analyze AnalyzeFunc
// Extra lists connected self-hosted hosts (host[:port]).
Extra func(ctx context.Context) []string
// Now is swappable for tests.
Now func() time.Time
// contains filtered or unexported fields
}
Builder assembles previews. Hosts are checked before any request is made.
type Commit ¶
type Commit struct {
SHA string `json:"sha"`
Message string `json:"message"`
Author string `json:"author"`
At time.Time `json:"at"`
}
Commit is the latest commit on the previewed branch.
type HTTPClient ¶
HTTPClient reads repository metadata through provider REST APIs. The http.Client must be the SSRF-guarded one; hosts are re-checked by Builder.
type HostClient ¶
HostClient fetches metadata for a target. Implementations return ErrNotFound, ErrRateLimited or ErrNoMetadata for the matching outcomes.
type Kind ¶
type Kind string
Kind is the outcome class the UI switches on.
const ( KindPublic Kind = "public" KindPrivate Kind = "private_needs_account" KindNotFound Kind = "not_found" KindRateLimited Kind = "rate_limited" KindUnsupportedHost Kind = "unsupported_host" KindInvalidURL Kind = "invalid_url" )
Outcome classes. KindPublic means a preview was produced; Visibility says whether the repository is private.
type Meta ¶
type Meta struct {
Owner string
Name string
Description string
DefaultBranch string
Branches []string
Private bool
Stars *int
Forks *int
Languages map[string]int64
LastCommit *Commit
License string
Topics []string
Readme string
SizeKB *int
}
Meta is what a host client returns, before capping and sanitising.
type Result ¶
type Result struct {
Kind Kind `json:"kind"`
Host string `json:"host,omitempty"`
RepoURL string `json:"repo_url,omitempty"`
Owner string `json:"owner,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
DefaultBranch string `json:"default_branch,omitempty"`
Branches []string `json:"branches,omitempty"`
Visibility string `json:"visibility,omitempty"`
Stars *int `json:"stars,omitempty"`
Forks *int `json:"forks,omitempty"`
Languages []Language `json:"languages,omitempty"`
LastCommit *Commit `json:"last_commit,omitempty"`
License string `json:"license,omitempty"`
Topics []string `json:"topics,omitempty"`
ReadmeExcerpt string `json:"readme_excerpt,omitempty"`
SizeKB *int `json:"size_kb,omitempty"`
Analysis *appwizard.Analysis `json:"analysis,omitempty"`
}
Result is the preview payload.
type Target ¶
Target identifies one repository on one host.
func ParseTarget ¶
ParseTarget splits a repository URL into host, owner and repo. Credentials, queries and fragments are dropped so they never reach a cache key or log.