repopreview

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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

View Source
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

View Source
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

func Excerpt

func Excerpt(md string, limit int) string

Excerpt turns README markdown into plain text of at most limit runes. The result is data only and is never meant to be rendered as HTML.

Types

type AnalyzeFunc

type AnalyzeFunc func(ctx context.Context, repoURL, ref, token string) (*appwizard.Analysis, error)

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.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, rawURL, ref, token string) (Result, error)

Build returns the preview for rawURL. token may be empty. A host failure becomes the matching Kind so the UI can degrade; only unexpected errors return err.

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

type HTTPClient struct {
	HTTP  *http.Client
	Hosts func(ctx context.Context) repolayout.Hosts
}

HTTPClient reads repository metadata through provider REST APIs. The http.Client must be the SSRF-guarded one; hosts are re-checked by Builder.

func (*HTTPClient) Fetch

func (c *HTTPClient) Fetch(ctx context.Context, t Target, token string) (Meta, error)

Fetch implements HostClient.

type HostClient

type HostClient interface {
	Fetch(ctx context.Context, t Target, token string) (Meta, error)
}

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 Language

type Language struct {
	Name    string  `json:"name"`
	Percent float64 `json:"percent"`
}

Language is one entry of the languages bar.

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

type Target struct {
	URL   string
	Host  string
	Owner string
	Repo  string
	Ref   string
}

Target identifies one repository on one host.

func ParseTarget

func ParseTarget(raw, ref string) (Target, error)

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.

Jump to

Keyboard shortcuts

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