repolayout

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 21 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

func Affected

func Affected(changed []string, pkgs []Package) []string

Affected returns the directories of the packages whose watch paths match any changed file. Callers pass both sides of a rename. An empty diff affects nothing, so a no-op push never rebuilds every service.

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 DefaultBrancher

type DefaultBrancher interface {
	DefaultBranch(ctx context.Context) (string, error)
}

DefaultBrancher is implemented by sources whose provider can name the repository's default branch, so callers need not guess main or master.

type Hosts

type Hosts struct {
	GitHub          string
	GitLab          string
	Gitea           string
	BitbucketServer string
}

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

type Package

type Package struct {
	Name       string   `json:"name"`
	Dir        string   `json:"dir"`
	Tool       string   `json:"tool"`
	Dockerfile string   `json:"dockerfile,omitempty"`
	DependsOn  []string `json:"depends_on"`
	// WatchPaths is the deploy filter that redeploys only this package:
	// its own directory, its workspace dependencies and the shared root files.
	WatchPaths []string `json:"watch_paths"`
}

Package is one workspace member that can run as its own service.

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"`
	Packages          []Package    `json:"packages"`
	// StaticBuild is set when the repository root is a static-site
	// framework, to prefill the build command and publish directory.
	StaticBuild *StaticBuildSuggestion `json:"static_build,omitempty"`
}

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 StaticBuildSuggestion

type StaticBuildSuggestion struct {
	PresetID   string `json:"preset_id"`
	PresetName string `json:"preset_name"`
	Command    string `json:"command"`
	PublishDir string `json:"publish_dir"`
}

StaticBuildSuggestion is a framework preset's build command and output directory.

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