application

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 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 off by default (see Digest).

func (*Provider) AdditionalChannels added in v0.24.0

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

AdditionalChannels returns the channels the repository can post to beyond its primary base channel (extra base-list channels plus per-path channels), sorted and deduped. The validator checks bot membership for each; the doctor and notifycat-config validate share this via the validation port.

func (*Provider) BaseTargets added in v0.24.0

func (p *Provider) BaseTargets(repository string) []domain.Target

BaseTargets returns the repository's unconditional base fan-out targets (the channels every PR is announced to before any path rules apply). The router uses it when the repo has no path rules or no changed-files reader.

func (*Provider) Digest

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

Digest returns the effective stuck-PR digest configuration. The feature is opt-in, so an absent `digest:` section yields {Enabled: false, Schedule: DefaultDigestSchedule}. An explicit section turns it on with `enabled: true` and may 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) NotificationSchedules added in v0.27.0

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

NotificationSchedules returns the sorted distinct cron specs across every mapping entry whose effective notifications strategy is scheduled. The scheduled-notification runner registers one cron per returned spec.

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. With no path rules, no files, or no match it returns the full base target set. Matched path rules (single or list) replace the base set; a matched rule that omits channels inherits the primary base channel. Targets are grouped by channel with mentions unioned; a list entry's absent mentions default to @channel, a single-form rule's absent mentions inherit the primary base.

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 the full base target set. A files-API error is soft: it logs and returns the base targets.

Jump to

Keyboard shortcuts

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