repolayout

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package repolayout inspects a repository's file tree to suggest where its build context and Dockerfile should point, so a monorepo does not silently fall back to auto-detecting the repository root.

Index

Constants

View Source
const (
	ReasonTurboPrune     = "turbo_prune"
	ReasonRootCopy       = "root_copy"
	ReasonAppDeployDir   = "app_deploy_dir"
	ReasonRootDockerfile = "root_dockerfile"
	ReasonNestedDocker   = "nested_dockerfile"
	ReasonAppRailpack    = "app_railpack"
)

Suggestion reason codes. The dashboard translates these; Reason carries the same sentence in English for the CLI and API consumers.

View Source
const (
	ProviderGitHub = "github"
	ProviderGitLab = "gitlab"
	ProviderGitea  = "gitea"
)

Provider names for CommitSource.Provider.

Variables

View Source
var ErrUnsupportedHost = errors.New("repolayout: no provider API for this host")

ErrUnsupportedHost means no provider API matches the repository URL, and the caller should fall back to a shallow in-memory clone.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	SHA        string    `json:"sha"`
	Message    string    `json:"message"`
	Author     string    `json:"author"`
	AuthoredAt time.Time `json:"authored_at"`
	URL        string    `json:"url,omitempty"`
}

Commit is one entry of a branch's history, reduced to what a deploy picker shows.

type CommitSource

type CommitSource interface {
	Provider() string
	Commits(ctx context.Context, limit int) ([]Commit, error)
	Branches(ctx context.Context) ([]string, error)
}

CommitSource lists recent commits and branches through a provider API.

type Hosts

type Hosts struct {
	GitHub string
	GitLab string
	Gitea  string
}

Hosts names self-hosted instances so their API base can be inferred from a repository URL. The public hosts are always recognised.

type Reader

type Reader func(p string, limit int) ([]byte, error)

Reader returns the first max bytes of a file, or an error when it cannot be read. Analyze treats a read failure as "no signal", never as a failure.

type Result

type Result struct {
	LooksLikeMonorepo bool         `json:"looks_like_monorepo"`
	RootHasApp        bool         `json:"root_has_app"`
	Tools             []string     `json:"tools"`
	Dockerfiles       []string     `json:"dockerfiles"`
	ComposeFiles      []string     `json:"compose_files"`
	Suggestions       []Suggestion `json:"suggestions"`
	Truncated         bool         `json:"truncated"`
}

Result is what detection found in one repository at one ref.

func Analyze

func Analyze(paths []string, read Reader) Result

Analyze inspects the file paths of a repository (blobs only, slash separated) and returns layout findings. read supplies file contents for the few files whose text decides a suggestion.

func Detect

func Detect(ctx context.Context, src Source) (Result, error)

Detect lists src and returns the layout analysis.

type Source

type Source interface {
	// Paths returns every blob path. truncated is true when the provider
	// capped the listing.
	Paths(ctx context.Context) (paths []string, truncated bool, err error)
	Read(ctx context.Context, p string, limit int) ([]byte, error)
}

Source lists a repository's files at one ref and reads single files, without cloning the repository to disk.

func NewAPISource

func NewAPISource(client *http.Client, repoURL, branch, token string, hosts Hosts) (Source, error)

NewAPISource picks a provider API source for repoURL. token may be empty for a public repository.

func NewCloneSource

func NewCloneSource(ctx context.Context, repoURL, branch, token string) (Source, error)

NewCloneSource fetches branch of repoURL at depth 1 into memory. Nothing is written to disk.

type StatusError

type StatusError struct {
	Status int
	Body   string
}

StatusError is a non-2xx answer from a provider API.

func (*StatusError) Error

func (e *StatusError) Error() string

type Suggestion

type Suggestion struct {
	BuildType      string `json:"build_type"`
	DockerfilePath string `json:"dockerfile_path,omitempty"`
	BaseDirectory  string `json:"base_directory,omitempty"`
	Reason         string `json:"reason"`
	ReasonCode     string `json:"reason_code"`
	Recommended    bool   `json:"recommended"`
	Score          int    `json:"-"`
}

Suggestion is one candidate build setting.

Jump to

Keyboard shortcuts

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