domain

package
v0.22.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package domain holds the maintenance domain's contracts: the ports, DTOs, enums, and constants for stale-message cleanup and PR reconcile. It depends only on the standard library and the shared kernel.

Index

Constants

View Source
const Interval = 24 * time.Hour

Interval is the fixed cadence between stale-message cleanup passes. 24h is conservative enough that a transient DB error has nearly a full day to clear before the next attempt.

Variables

View Source
var ErrPRDraft = errors.New("reconcile: pull request is a draft")

ErrPRDraft marks a draft PR. A draft must never stay in the database (regardless of open/closed state), so the reconciler deletes its row the same way the live converted_to_draft webhook does — the difference being this catches drafts in the pre-tracking backlog.

View Source
var ErrPRNotFound = errors.New("reconcile: pull request not found")

ErrPRNotFound marks a PR that GitHub reports as 404 — deleted, or in a repo that was renamed or is no longer accessible. The reconciler treats it distinctly from other API errors: rather than leave the row untouched, it removes the PR from the digest (a 404 will never resolve on its own).

Functions

This section is empty.

Types

type CleanerParams

type CleanerParams struct {
	Deleter  StaleMessageDeleter
	TTL      time.Duration
	Interval time.Duration
	Logger   *slog.Logger
	Now      func() time.Time
}

CleanerParams bundles everything the stale-message cleaner needs. TTL is the maximum age a row may reach before it becomes eligible for deletion; Interval is the cadence between passes (use the Interval constant in production); Now supplies the clock (time.Now in production, a fixed clock in tests).

type Closer

type Closer interface {
	MarkClosed(ctx context.Context, repository string, prNumber int) error
}

Closer marks a PR's row closed.

type Deleter

type Deleter interface {
	Delete(ctx context.Context, repository string, prNumber int) error
}

Deleter removes a PR's row entirely. Used for drafts, which must not stay in the database at all (a draft is not review-ready; the row is recreated by the open webhook if it is later marked ready_for_review).

type OpenLister

type OpenLister interface {
	ListOpen(ctx context.Context) ([]PRRow, error)
}

OpenLister lists the tracked PR rows not yet marked closed.

type PRChecker

type PRChecker interface {
	IsOpen(ctx context.Context, repository string, prNumber int) (bool, error)
}

PRChecker reports whether a PR is still open on GitHub.

type PRRow

type PRRow struct {
	Repository string
	PRNumber   int
}

PRRow is the maintenance view of one tracked PR: the fields the reconciler reads to check and resolve it. It is mapped from the store's persistence model at the repository boundary, so no gorm-tagged type crosses a port.

type Reconciler

type Reconciler interface {
	Run(ctx context.Context) (Summary, error)
}

Reconciler resolves every not-yet-closed tracked PR against GitHub: a merged/closed PR is marked closed, a 404 is removed from the digest, and a draft is deleted outright (a draft must never stay in the database). Per-PR errors are logged and counted, never fatal — an unconfirmable row is left untouched so a token-scope miss never wrongly hides an open PR, and re-running is safe. Run reports the tallies in a Summary.

type ReconcilerParams

type ReconcilerParams struct {
	Lister  OpenLister
	Checker PRChecker
	Closer  Closer
	Deleter Deleter
	Logger  *slog.Logger
	DryRun  bool
	// Provider is the deployment's git host; it selects the web-URL form the
	// per-PR log lines are reconstructed in. The zero value builds github.com URLs.
	Provider kernel.Provider
}

ReconcilerParams bundles everything the reconciler needs. DryRun reports what would change without writing.

type StaleMessageCleaner

type StaleMessageCleaner interface {
	Run(ctx context.Context) error
}

StaleMessageCleaner prunes stale slack_messages rows on a fixed cadence: one pass immediately on start, then one every Interval, until its context is cancelled. It deletes only database rows — never the Slack messages themselves. A pass's error is logged and swallowed so the next tick retries; Run always returns nil (so callers can compose it with other long-running goroutines without special-casing).

type StaleMessageDeleter

type StaleMessageDeleter interface {
	DeleteStaleBefore(ctx context.Context, cutoff time.Time) (int64, error)
}

StaleMessageDeleter deletes tracked-PR rows whose message predates a cutoff. It is the persistence port the cleanup use case drives; the maintenance infrastructure layer satisfies it over the store.

type Summary

type Summary struct {
	Checked   int
	Closed    int // marked closed (in dry-run: would be marked)
	Removed   int // PR 404s or is a draft; dropped from the digest (would be, in dry-run)
	StillOpen int
	Errors    int
}

Summary tallies one reconcile run.

Jump to

Keyboard shortcuts

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