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
- Variables
- func Affected(changed []string, pkgs []Package) []string
- func NewSSHDeployKeyAuth(user string, privateKeyPEM []byte) (transport.AuthMethod, error)
- func PackageCap() int
- type Commit
- type CommitSource
- type DefaultBrancher
- type Graph
- type GraphLimits
- type Hosts
- type Package
- type Reader
- type Result
- type Source
- type StaticBuildSuggestion
- type StatusError
- type Suggestion
- type Verdict
Constants ¶
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.
const ( ProviderGitHub = "github" ProviderGitLab = "gitlab" ProviderGitea = "gitea" )
Provider names for CommitSource.Provider.
const ( CodeDependency = "dependency_changed" CodeOwn = "app_changed" CodeUnknown = "unknown" )
Verdict codes.
const EnvMaxPackages = "APP_WIZARD_MAX_PACKAGES"
EnvMaxPackages caps how many workspace packages one analysis returns.
Variables ¶
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 ¶
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.
func NewSSHDeployKeyAuth ¶
func NewSSHDeployKeyAuth(user string, privateKeyPEM []byte) (transport.AuthMethod, error)
NewSSHDeployKeyAuth builds clone auth from a PEM deploy key. Host keys are checked against known_hosts by the transport, never skipped.
func PackageCap ¶
func PackageCap() int
PackageCap is the effective package cap, read from the environment on each call.
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 ¶
DefaultBrancher is implemented by sources whose provider can name the repository's default branch, so callers need not guess main or master.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is the workspace dependency graph read from manifests.
func BuildGraph ¶
func BuildGraph(files []string, truncated bool, read Reader, lim GraphLimits) Graph
BuildGraph reads the workspace manifests among files. Anything it cannot read or understand is recorded, so Decide rebuilds instead of guessing.
func (Graph) Decide ¶
Decide says whether changed rebuilds the package in appDir. It only skips when every changed file belongs to a package the app does not depend on.
type GraphLimits ¶
GraphLimits bounds the dependency graph read; zero fields use the defaults.
type Hosts ¶
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 ¶
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"`
// PackagesTotal is the member count before the package cap, 0 when no workspace.
PackagesTotal int `json:"packages_total,omitempty"`
// 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.
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 ¶
NewAPISource picks a provider API source for repoURL. token may be empty for a public repository.
func NewCloneSource ¶
NewCloneSource fetches branch of repoURL at depth 1 into memory. Nothing is written to disk.
func NewCloneSourceAuth ¶
func NewCloneSourceAuth(ctx context.Context, repoURL, branch string, auth transport.AuthMethod) (Source, error)
NewCloneSourceAuth is NewCloneSource with a caller-built auth method, used for ssh deploy keys. A nil auth clones anonymously.
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 ¶
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.
type Verdict ¶
type Verdict struct {
Rebuild bool `json:"rebuild"`
Code string `json:"code"`
Reason string `json:"reason"`
File string `json:"file,omitempty"`
// Via is the dependency chain from the app to the changed package.
Via []string `json:"via,omitempty"`
}
Verdict is whether a change rebuilds one workspace package, and why.