domain

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package domain defines the notification domain's ports, DTOs, enums, and policies — the contracts for keeping one chat message per (PR, channel) in sync with GitHub PR events. It imports only the standard library, the shared kernel, and the routing domain.

Index

Constants

View Source
const (
	ReasonNoHandler       = "no_handler"
	ReasonNoMapping       = "no_mapping"
	ReasonNoStoredMessage = "no_stored_message"
	ReasonAlreadySent     = "already_sent"
)

Ignored-event reason codes, logged on every silent no-op so a 200-OK delivery that changed nothing can be triaged.

Variables

View Source
var ErrNoActiveReview = errors.New("notification: no active review session")

ErrNoActiveReview marks the absence of an in-progress review session for a PR. The reaction handlers treat it as "no session to finish", not a failure.

Functions

This section is empty.

Types

type BotFormat

type BotFormat struct {
	Name     string
	Security bool
}

BotFormat carries the dependency-bot template inputs: the bot's display name and whether the PR body reads as a security advisory.

type BotKind

type BotKind int

BotKind classifies a PR author as a known dependency bot (or none). Moved from the botpr package; drives the compact dependency-bot open template.

const (
	BotKindNone BotKind = iota
	BotKindDependabot
	BotKindRenovate
)

Recognised dependency-bot kinds.

func (BotKind) Name

func (k BotKind) Name() string

Name returns the bot's display name ("dependabot"/"renovate"), or "" for none.

type ClosedRequest

type ClosedRequest struct {
	Repository  string
	PR          kernel.PR
	Merged      bool
	Emoji       string
	ReviewerIDs []string
}

ClosedRequest is the intent to update a message for a closed/merged PR. Emoji is the merged/closed reaction; ReviewerIDs, when non-empty, appends a "reviewed by" marker.

type EventDispatcher

type EventDispatcher interface {
	Dispatch(ctx context.Context, event kernel.Event) error
}

EventDispatcher routes an incoming event to the first applicable handler.

type Handler

type Handler interface {
	Applicable(event kernel.Event) bool
	Handle(ctx context.Context, event kernel.Event) error
}

Handler is implemented by each PR-lifecycle use case. Applicable inspects an event and returns true if Handle should run; the dispatcher runs the first applicable handler and skips the rest (handlers are mutually exclusive).

type Message

type Message struct {
	Channel   string
	MessageID string
}

Message is one posted chat message for a PR: the channel it lives in and the platform's id for the post. Mapped from the store's persistence model at the repository boundary.

type MessageStore

type MessageStore interface {
	AddMessage(ctx context.Context, repository string, prNumber int, channel, messageID string) error
	Messages(ctx context.Context, repository string, prNumber int) ([]Message, error)
	Touch(ctx context.Context, repository string, prNumber int) error
	MarkClosed(ctx context.Context, repository string, prNumber int) error
	Delete(ctx context.Context, repository string, prNumber int) error
}

MessageStore persists tracked PRs and their per-channel chat messages.

type Messenger

type Messenger interface {
	PostOpen(ctx context.Context, channel string, req OpenRequest) (messageID string, err error)
	UpdateClosed(ctx context.Context, channel, messageID string, req ClosedRequest) error
	UpdateReviewFinished(ctx context.Context, channel, messageID string, req ReviewFinishedRequest) error
	AddReaction(ctx context.Context, channel, messageID, emoji string) error
	Delete(ctx context.Context, channel, messageID string) error
	// HasThreadReplies reports whether anyone has replied in the message's
	// thread — the discussion a Delete would take with it.
	HasThreadReplies(ctx context.Context, channel, messageID string) (bool, error)
}

Messenger delivers notification messages to the chat platform. It receives domain intent — which notification, for which PR, with which data — and its adapter owns the message shaping (which blocks/markers). The infra Slack messenger is the only implementation.

type OpenHandlerParams added in v0.27.0

type OpenHandlerParams struct {
	Store     MessageStore
	Resolver  TargetResolver
	Messenger Messenger
	Queue     ScheduledQueue
	Logger    *slog.Logger
}

OpenHandlerParams are the OpenHandler's dependencies. Queue receives the PRs of repos on the scheduled notification strategy.

type OpenRequest

type OpenRequest struct {
	Repository string
	PR         kernel.PR
	Mentions   []string
	NewPREmoji string
	Bot        *BotFormat
}

OpenRequest is the intent to post an opened-PR notification. Bot, when non-nil, selects the compact dependency-bot template; otherwise the standard template is rendered with NewPREmoji.

type RepoBehavior

type RepoBehavior interface {
	Get(ctx context.Context, repository string) (routingdomain.RepoMapping, error)
}

RepoBehavior resolves a repository's per-repo behavioral config (reactions, review flags). Close/draft/reaction handlers need it but not the per-channel targets.

type ReviewFinishedRequest

type ReviewFinishedRequest struct {
	Repository  string
	PR          kernel.PR
	ReviewerIDs []string
	NewPREmoji  string
}

ReviewFinishedRequest is the intent to refresh a message after its active review session finishes: the standard message is rebuilt and, when reviewers exist, a "reviewed by" marker is appended.

type ReviewSession

type ReviewSession struct {
	SlackUserID   string
	SlackUserName string
}

ReviewSession is the notification view of one review session: who is (or was) reviewing. Mapped from the review store at the boundary.

type ReviewSessions

type ReviewSessions interface {
	GetActive(ctx context.Context, repository string, prNumber int) (ReviewSession, error)
	Finish(ctx context.Context, repository string, prNumber int) error
	Reviewers(ctx context.Context, repository string, prNumber int) ([]ReviewSession, error)
}

ReviewSessions is the review-session view the reaction and close handlers use. The review domain satisfies it in a later phase; the code-reviews store satisfies it today (via an infra adapter). GetActive returns ErrNoActiveReview when the PR has no in-progress session.

type ScheduleCalendar added in v0.27.0

type ScheduleCalendar interface {
	SkipReason(now time.Time) (reason string, skip bool)
}

ScheduleCalendar answers whether a tick falls on a day the team is off, and names the reason (weekend, holiday). A skipped tick keeps the queue.

type ScheduledEntry added in v0.27.0

type ScheduledEntry struct {
	ID         uint
	Repository string
	PR         kernel.PR
	Channel    string
	Mentions   []string
	QueuedAt   time.Time
}

ScheduledEntry is one queued PR announcement for one channel. PR carries the fields the list shows: Number, Title, URL, Author.

type ScheduledListRequest added in v0.27.0

type ScheduledListRequest struct {
	Mentions []string
	Entries  []ScheduledEntry
}

ScheduledListRequest is the intent to post one channel's list of queued PRs, pinging Mentions once.

type ScheduledPoster added in v0.27.0

type ScheduledPoster interface {
	PostScheduledList(ctx context.Context, channel string, req ScheduledListRequest) error
}

ScheduledPoster posts one channel's list of queued PRs. The list message holds many PRs, so it is never stored, updated, reacted on, or deleted.

type ScheduledQueue added in v0.27.0

type ScheduledQueue interface {
	Enqueue(ctx context.Context, entry ScheduledEntry) error
	Pending(ctx context.Context) ([]ScheduledEntry, error)
	MarkSent(ctx context.Context, ids []uint, sentAt time.Time) error
}

ScheduledQueue holds the new PRs of repos on the scheduled notification strategy until a tick posts them. Enqueue tracks the PR (so close and draft events find it) and is idempotent per (PR, channel), also after the send: a webhook redelivery never lists a PR twice in a channel. Pending returns the unsent entries of open PRs, oldest first.

type ScheduledRunner added in v0.27.0

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

ScheduledRunner fires the ScheduledSender on every configured spec until ctx is cancelled, skipping the days the calendar marks off.

type ScheduledRunnerParams added in v0.27.0

type ScheduledRunnerParams struct {
	Specs    []string
	Sender   ScheduledSender
	Calendar ScheduleCalendar
	TZ       *time.Location
	Logger   *slog.Logger
	Now      func() time.Time
}

ScheduledRunnerParams are the ScheduledRunner's dependencies. Specs are standard 5-field cron specs read in TZ (nil = UTC); Calendar may be nil.

type ScheduledSender added in v0.27.0

type ScheduledSender interface {
	SendSchedule(ctx context.Context, spec string) error
}

ScheduledSender is the scheduled-strategy send use case: for one cron spec it posts, per channel, one list of the queued PRs whose repo sends on that spec, then marks them sent. A channel whose post fails keeps its entries for the next tick.

type ScheduledSenderParams added in v0.27.0

type ScheduledSenderParams struct {
	Queue    ScheduledQueue
	Behavior RepoBehavior
	Poster   ScheduledPoster
	Logger   *slog.Logger
	Now      func() time.Time
}

ScheduledSenderParams are the ScheduledSender's dependencies. Behavior gives each repo's current schedule; Now stamps the sent entries (nil = time.Now).

type TargetResolver

type TargetResolver interface {
	ResolveTargets(ctx context.Context, repository string, prNumber int) (routingdomain.RepoMapping, []routingdomain.Target, error)
}

TargetResolver resolves the open fan-out: per-repo behavior plus the per-channel targets a newly opened PR is announced to.

Jump to

Keyboard shortcuts

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