application

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package application holds the routing use cases: the provider (tier resolution and defaults merge) and the per-PR router (layering monorepo path rules over the base repo/org tier). It depends only on the routing domain layer and the standard library — never on infrastructure or a platform client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateMappings

func ValidateMappings(m map[string]domain.Org) error

ValidateMappings runs the same per-org/per-tier structural checks as Parse over a mappings map. An empty map (no orgs) is valid. Returns an error for invalid org names, empty orgs, bad repo keys, malformed channel IDs, or any repo tier that cannot resolve a channel.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider serves repository → mapping lookups from a parsed mappings.yaml. Construct with NewProvider; safe for concurrent reads (no mutation after construction).

func NewProvider

func NewProvider(defaults domain.Defaults, m map[string]domain.Org, digest *domain.DigestConfig) *Provider

NewProvider builds a Provider from already-decoded sections (config.yaml's `mappings:` map and `digest:` block), the in-memory counterpart to Load. A nil digest leaves the feature on by default (see Digest).

func (*Provider) Digest

func (p *Provider) Digest() domain.DigestConfig

Digest returns the effective stuck-PR digest configuration. The feature is enabled by default, so an absent `digest:` section yields {Enabled: true, Schedule: DefaultDigestSchedule}. An explicit section may disable it or override the schedule.

func (*Provider) DigestFor

func (p *Provider) DigestFor(repository string) domain.DigestConfig

DigestFor returns the effective digest config for a repository: the global Digest() merged with the org/* and org/repo tiers (most-specific tier that sets enabled/schedule wins). An unmapped repo yields the global digest.

func (*Provider) Entries

func (p *Provider) Entries() []domain.Entry

Entries returns validation units in deterministic order: orgs A→Z, explicit repos within each org A→Z, the wildcard entry last. Each entry's Channel is the resolved channel (the tier's own, or inherited from org/*), so the validator and lock operate on what a webhook would actually route to.

func (*Provider) Get

func (p *Provider) Get(_ context.Context, repository string) (domain.RepoMapping, error)

Get returns the resolved mapping for "org/repo": the org/repo tier merged over the org/* tier. Returns domain.ErrNotFound when the org is unmapped or neither an explicit tier nor a wildcard tier matches.

func (*Provider) HasPathRules

func (p *Provider) HasPathRules() bool

HasPathRules reports whether any repo tier in the mappings configures a `paths:` block. Used to gate the "path routing needs GITHUB_TOKEN" warnings: without paths there is nothing to warn about.

func (*Provider) PathChannels

func (p *Provider) PathChannels(repository string) []string

PathChannels returns the distinct channels explicitly set on the repository's path rules (those that override the base channel), in sorted order. The base channel is validated separately; these are the extra Slack channels path routing can post to, so validation must confirm the bot is in each.

func (*Provider) RepoHasPathRules

func (p *Provider) RepoHasPathRules(repository string) bool

RepoHasPathRules reports whether the specific repository's tier configures a `paths:` block. The runtime uses it to decide, per webhook, whether fetching the PR's changed files is worthwhile — repos without path rules skip the GitHub call entirely.

func (*Provider) Schedules

func (p *Provider) Schedules() []string

Schedules returns the sorted distinct set of effective digest schedules across every mapping entry whose effective digest is enabled. The scheduler registers one cron per returned spec.

func (*Provider) TargetsForFiles

func (p *Provider) TargetsForFiles(repository string, files []string) []domain.Target

TargetsForFiles returns the fan-out destinations for a PR touching files: one Target per distinct matched channel, mentions unioned within each channel. With no path rules, no files, or no match it returns a single base target.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router resolves routing, layering per-path rules over the base repo/org tier when the repository configures `paths:` and a changed-files fetcher is available. With no fetcher (no GitHub token) or no path rules for the repo it is exactly the provider's Get. A fetch error is treated softly: it logs and falls back to the repo tier, so a GitHub hiccup never drops a notification.

func NewRouter

func NewRouter(mappings domain.RoutingProvider, files domain.ChangedFilesReader, logger *slog.Logger) *Router

NewRouter builds a Router. files may be nil (no token) — path routing is then inert and every PR resolves to its repo/org tier.

func (*Router) ResolveTargets

func (r *Router) ResolveTargets(ctx context.Context, repository string, prNumber int) (domain.RepoMapping, []domain.Target, error)

ResolveTargets returns the per-repo behavior plus the fan-out targets for a PR. With no fetcher (no token) or no path rules it returns a single base target. A files-API error is soft: it logs and returns the base target.

Jump to

Keyboard shortcuts

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