persistence

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package store owns the database schema, GORM models, repositories, and the goose-driven migration runner. Callers depend on small interfaces declared where they consume the store (handler packages); only this package needs to know about GORM.

Index

Constants

This section is empty.

Variables

View Source
var ErrActiveReviewExists = errors.New("store: active code review exists")

ErrActiveReviewExists is returned by Start when the same user already has an active review on the PR — the partial unique index rejected the insert. Callers surface the conflict UX ("already reviewing") instead of a 500.

View Source
var ErrInviteUsed = errors.New("store: access invite already used")

ErrInviteUsed is returned by Redeem when the invite was already redeemed.

ErrNotFound aliases the routing domain sentinel so all existing callers keep the same value.

Functions

func MigrateDown

func MigrateDown(ctx context.Context, db *gorm.DB) error

MigrateDown rolls back the most recent migration.

func MigrateStatus

func MigrateStatus(ctx context.Context, db *gorm.DB) (string, error)

MigrateStatus returns a human-readable list of each migration and whether it has been applied.

func MigrateUp

func MigrateUp(ctx context.Context, db *gorm.DB) error

MigrateUp applies all pending migrations.

func NewTestDB

func NewTestDB(t *testing.T) *gorm.DB

NewTestDB returns a *gorm.DB backed by a fresh on-disk SQLite database inside t.TempDir, with all migrations applied. The database is closed and removed automatically when the test completes.

We use an on-disk file rather than `:memory:` because the goose-sqlite driver expects a stable database name to record migration state, and multiple in-memory connections in the same process are not always shared.

func Open

func Open(url string) (*gorm.DB, error)

Open opens a SQLite database for production use. The url accepts either a raw file path or the "file:..." DSN form used in our config defaults.

GORM's logger is silenced for "record not found" because we treat ErrNotFound as a normal return value, not a warning condition.

func RawCreateForTest

func RawCreateForTest(db *gorm.DB, pr PullRequest) error

RawCreateForTest inserts a pull_requests row preserving the caller's CreatedAt/UpdatedAt/ClosedAt, bypassing GORM's autoCreate/UpdateTime. Used by tests that need to seed PRs with a controlled age and open/closed state. A zero CreatedAt defaults to UpdatedAt.

func SQLDB

func SQLDB(db *gorm.DB) (*sql.DB, error)

SQLDB returns the underlying *sql.DB. Useful for the migrate binary which hands the connection to goose.

Types

type AccessInvite added in v0.29.0

type AccessInvite struct {
	ID         string     `gorm:"primaryKey"`
	User       string     `gorm:"column:user;not null"`
	SecretHash string     `gorm:"column:secret_hash;not null"`
	ExpiresAt  time.Time  `gorm:"column:expires_at;not null"`
	UsedAt     *time.Time `gorm:"column:used_at"`
	CreatedAt  time.Time  `gorm:"column:created_at;not null"`
}

AccessInvite is a one-time invite; UsedAt is set when it is redeemed.

func (AccessInvite) TableName added in v0.29.0

func (AccessInvite) TableName() string

TableName pins the table name.

type AccessInvites added in v0.29.0

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

AccessInvites persists one-time invites.

func NewAccessInvites added in v0.29.0

func NewAccessInvites(db *gorm.DB) *AccessInvites

NewAccessInvites constructs an AccessInvites repository bound to db.

func (*AccessInvites) Create added in v0.29.0

func (r *AccessInvites) Create(ctx context.Context, invite AccessInvite) error

Create inserts an invite.

func (*AccessInvites) Find added in v0.29.0

func (r *AccessInvites) Find(ctx context.Context, id string) (AccessInvite, error)

Find returns the invite, or ErrNotFound.

func (*AccessInvites) Redeem added in v0.29.0

func (r *AccessInvites) Redeem(ctx context.Context, inviteID string, token AccessToken) error

Redeem marks the invite used and inserts the token in one transaction, or returns ErrInviteUsed when the invite is unknown or already used.

type AccessToken added in v0.29.0

type AccessToken struct {
	ID         string     `gorm:"primaryKey"`
	User       string     `gorm:"column:user;not null"`
	SecretHash string     `gorm:"column:secret_hash;not null"`
	CreatedAt  time.Time  `gorm:"column:created_at;not null"`
	LastUsedAt *time.Time `gorm:"column:last_used_at"`
}

AccessToken is a long-lived agent token stored as a hash.

func (AccessToken) TableName added in v0.29.0

func (AccessToken) TableName() string

TableName pins the table name.

type AccessTokens added in v0.29.0

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

AccessTokens persists agent tokens.

func NewAccessTokens added in v0.29.0

func NewAccessTokens(db *gorm.DB) *AccessTokens

NewAccessTokens constructs an AccessTokens repository bound to db.

func (*AccessTokens) Delete added in v0.29.0

func (r *AccessTokens) Delete(ctx context.Context, id string) error

Delete removes the token, or returns ErrNotFound.

func (*AccessTokens) Find added in v0.29.0

func (r *AccessTokens) Find(ctx context.Context, id string) (AccessToken, error)

Find returns the token, or ErrNotFound.

func (*AccessTokens) List added in v0.29.0

func (r *AccessTokens) List(ctx context.Context) ([]AccessToken, error)

List returns all tokens ordered by creation time.

func (*AccessTokens) TouchLastUsed added in v0.29.0

func (r *AccessTokens) TouchLastUsed(ctx context.Context, id string, usedAt time.Time) error

TouchLastUsed records when the token was last used.

type CodeReview

type CodeReview struct {
	ID            uint       `gorm:"primaryKey"`
	PullRequestID uint       `gorm:"column:pull_request_id;not null"`
	SlackUserID   string     `gorm:"column:slack_user_id;not null"`
	SlackUserName string     `gorm:"column:slack_user_name"`
	StartedAt     time.Time  `gorm:"column:started_at;not null"`
	FinishedAt    *time.Time `gorm:"column:finished_at"`
}

CodeReview is one review "session" for a PR: who started reviewing it and when, with FinishedAt nil while the review is in progress and set once the reviewer's GitHub review lands. It hangs off a PullRequest (cascade-deleted with it) and a partial unique index enforces at most one active (FinishedAt IS NULL) review per PR — finished rows accumulate as history.

func (CodeReview) TableName

func (CodeReview) TableName() string

TableName pins the table name.

type CodeReviews

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

CodeReviews persists per-PR review sessions and enforces at most one active review per (PR, user); multiple distinct users may review a PR concurrently. A review is identified to callers by its PR's natural key (repository, prNumber); the surrogate pull_request_id is resolved internally.

func NewCodeReviews

func NewCodeReviews(db *gorm.DB) *CodeReviews

NewCodeReviews constructs a CodeReviews repository bound to db.

func (*CodeReviews) ActiveForUser

func (r *CodeReviews) ActiveForUser(ctx context.Context, repository string, prNumber int, slackUserID string) (CodeReview, error)

ActiveForUser returns the user's active (unfinished) review on the PR, or ErrNotFound when that user has no review in progress here. It is the app-level guard the click handler checks before Start; the DB's partial unique index on (pull_request_id, slack_user_id) is the race-safe backstop.

func (*CodeReviews) Finish

func (r *CodeReviews) Finish(ctx context.Context, repository string, prNumber int) error

Finish marks the PR's active review finished. It is idempotent: no active review (or an untracked PR) is a no-op, mirroring MarkClosed.

func (*CodeReviews) GetActive

func (r *CodeReviews) GetActive(ctx context.Context, repository string, prNumber int) (CodeReview, error)

GetActive returns the PR's active (unfinished) review, or ErrNotFound when the PR is untracked or has no review in progress.

func (*CodeReviews) Reviewers

func (r *CodeReviews) Reviewers(ctx context.Context, repository string, prNumber int) ([]CodeReview, error)

Reviewers returns all code-review sessions for the PR ordered by started_at ascending (earliest first). An untracked PR or a PR with no reviews returns an empty slice and nil error.

func (*CodeReviews) Start

func (r *CodeReviews) Start(ctx context.Context, repository string, prNumber int, slackUserID, slackUserName string) error

Start opens a review on the PR for the given Slack user. It returns ErrNotFound when the PR is not tracked, and ErrActiveReviewExists when the PR already has an active review — the DB's partial unique index is the source of truth, so two near-simultaneous Starts can't both win.

type FeedClaim added in v0.29.0

type FeedClaim struct {
	TokenID      string
	Repositories []string
	DeliveredAt  time.Time
}

FeedClaim asks for the pull requests a token has not received yet.

type FeedDeliveries added in v0.29.0

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

FeedDeliveries records which pull requests each token has received.

func NewFeedDeliveries added in v0.29.0

func NewFeedDeliveries(db *gorm.DB) *FeedDeliveries

NewFeedDeliveries constructs a FeedDeliveries repository bound to db.

func (*FeedDeliveries) Claim added in v0.29.0

func (r *FeedDeliveries) Claim(ctx context.Context, claim FeedClaim) ([]FeedPullRequest, error)

Claim writes first so SQLite never upgrades a read lock, which fails at once with SQLITE_BUSY.

func (*FeedDeliveries) ClaimParty added in v0.32.0

ClaimParty reads the snapshot and records what Choose picks in one transaction that writes first, so members that fetch at the same moment never pass the cap.

type FeedDelivery added in v0.29.0

type FeedDelivery struct {
	TokenID     string    `gorm:"column:token_id;primaryKey"`
	Repository  string    `gorm:"column:repository;primaryKey"`
	Number      int       `gorm:"column:number;primaryKey"`
	DeliveredAt time.Time `gorm:"column:delivered_at;not null;autoCreateTime:false"`
	Party       bool      `gorm:"column:party;not null;default:false"`
}

FeedDelivery records that a token already received a pull request.

func (FeedDelivery) TableName added in v0.29.0

func (FeedDelivery) TableName() string

TableName pins the table name.

type FeedFetch added in v0.32.0

type FeedFetch struct {
	TokenID   string    `gorm:"column:token_id;primaryKey"`
	FetchedAt time.Time `gorm:"column:fetched_at;not null"`
}

FeedFetch is the last time a token fetched its pull requests.

func (FeedFetch) TableName added in v0.32.0

func (FeedFetch) TableName() string

TableName pins the table name.

type FeedFetchRecord added in v0.32.0

type FeedFetchRecord struct {
	TokenID       string
	FetchedAt     time.Time
	ReplaceBefore time.Time
}

FeedFetchRecord is a fetch time to store. A stored fetch time at or after ReplaceBefore stays.

type FeedFetches added in v0.32.0

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

FeedFetches records when each token last fetched its pull requests.

func NewFeedFetches added in v0.32.0

func NewFeedFetches(db *gorm.DB) *FeedFetches

NewFeedFetches constructs a FeedFetches repository bound to db.

func (*FeedFetches) Record added in v0.32.0

func (r *FeedFetches) Record(ctx context.Context, record FeedFetchRecord) error

Record stores the fetch time of the token, replacing a stored time before ReplaceBefore.

type FeedPartyClaim added in v0.32.0

type FeedPartyClaim struct {
	TokenID      string
	Repositories []string
	DeliveredAt  time.Time
	Day          string
	ActiveSince  time.Time
	Choose       func(FeedPartySnapshot) []FeedPullRequestKey
}

FeedPartyClaim asks for the party pull requests that Choose picks for a token.

type FeedPartyClaimResult added in v0.32.0

type FeedPartyClaimResult struct {
	Claimed []FeedPullRequest
	Taken   int
}

FeedPartyClaimResult is what a party claim delivered, and how many pull requests the token did not receive are already at their cap.

type FeedPartyLoad added in v0.32.0

type FeedPartyLoad struct {
	TokenID    string `gorm:"column:token_id;primaryKey"`
	Repository string `gorm:"column:repository;primaryKey"`
	Day        string `gorm:"column:day;primaryKey"`
	Taken      int    `gorm:"column:taken;not null"`
}

FeedPartyLoad counts the party deliveries of a token for a repository on a day.

func (FeedPartyLoad) TableName added in v0.32.0

func (FeedPartyLoad) TableName() string

TableName pins the table name.

type FeedPartySnapshot added in v0.32.0

type FeedPartySnapshot struct {
	Waiting    []FeedWaitingPullRequest
	Deliveries []FeedDelivery
	Members    map[string][]string
	Loads      []FeedPartyLoad
}

FeedPartySnapshot is what a party claim reads before Choose: the pull requests the token did not receive that are below their cap, in feed order, every delivery of them, and the other active party members and the loads of the day for their repositories.

type FeedPullRequest added in v0.29.0

type FeedPullRequest struct {
	Repository   string     `gorm:"column:repository;primaryKey"`
	Number       int        `gorm:"column:number;primaryKey"`
	Title        string     `gorm:"column:title"`
	Description  string     `gorm:"column:description"`
	URL          string     `gorm:"column:url"`
	AuthorID     string     `gorm:"column:author_id"`
	SourceBranch string     `gorm:"column:source_branch"`
	TargetBranch string     `gorm:"column:target_branch"`
	HeadSHA      string     `gorm:"column:head_sha;not null"`
	CreatedAt    *time.Time `gorm:"column:created_at;autoCreateTime:false"`
	UpdatedAt    time.Time  `gorm:"column:updated_at;not null;autoUpdateTime:false"`

	PartyReviewers  int        `gorm:"column:party_reviewers;not null;default:1"`
	RecordedAt      *time.Time `gorm:"column:recorded_at;autoCreateTime:false"`
	PartyDeadlineAt *time.Time `gorm:"column:party_deadline_at;autoCreateTime:false"`
	KeepStoredParty bool       `gorm:"-"`
}

FeedPullRequest is the latest known state of an open pull request.

func (FeedPullRequest) TableName added in v0.29.0

func (FeedPullRequest) TableName() string

TableName pins the table name.

type FeedPullRequestKey added in v0.32.0

type FeedPullRequestKey struct {
	Repository string `json:"repository"`
	Number     int    `json:"number"`
}

FeedPullRequestKey names one feed pull request.

type FeedPullRequests added in v0.29.0

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

FeedPullRequests persists the latest state of open pull requests.

func NewFeedPullRequests added in v0.29.0

func NewFeedPullRequests(db *gorm.DB) *FeedPullRequests

NewFeedPullRequests constructs a FeedPullRequests repository bound to db.

func (*FeedPullRequests) ChangedSince added in v0.29.0

func (r *FeedPullRequests) ChangedSince(ctx context.Context, query FeedSinceQuery) ([]FeedPullRequest, error)

ChangedSince returns pull requests of the repositories updated at or after since, or delivered to the token at or after since.

func (*FeedPullRequests) Delete added in v0.29.0

func (r *FeedPullRequests) Delete(ctx context.Context, repository string, number int) error

Delete removes the pull request and its deliveries; a missing row is fine.

func (*FeedPullRequests) DeleteAll added in v0.29.0

func (r *FeedPullRequests) DeleteAll(ctx context.Context) (int, error)

DeleteAll removes every pull request and its deliveries and returns how many pull requests went.

func (*FeedPullRequests) DeleteRepositories added in v0.29.0

func (r *FeedPullRequests) DeleteRepositories(ctx context.Context, repositories []string) (int, error)

DeleteRepositories removes the pull requests of the repositories and their deliveries.

func (*FeedPullRequests) Find added in v0.32.0

func (r *FeedPullRequests) Find(ctx context.Context, repository string, number int) (FeedPullRequest, error)

Find returns the pull request, or ErrNotFound.

func (*FeedPullRequests) ReceivedSince added in v0.32.0

func (r *FeedPullRequests) ReceivedSince(ctx context.Context, query FeedSinceQuery) ([]FeedPullRequest, error)

ReceivedSince returns pull requests of the repositories that the token received, updated or delivered at or after since.

func (*FeedPullRequests) Repositories added in v0.29.0

func (r *FeedPullRequests) Repositories(ctx context.Context) ([]string, error)

Repositories returns the distinct repositories that have a pull request, sorted.

func (*FeedPullRequests) Upsert added in v0.29.0

func (r *FeedPullRequests) Upsert(ctx context.Context, pullRequest FeedPullRequest) error

Upsert inserts or updates the pull request in place, keeping its deliveries, a known created_at and the first recorded_at, and replacing the party settings unless KeepStoredParty guards a recorded row.

type FeedSinceQuery added in v0.32.0

type FeedSinceQuery struct {
	TokenID      string
	Repositories []string
	Since        time.Time
}

FeedSinceQuery asks for the pull requests of the repositories that changed, or reached the token, at or after Since.

type FeedSubscription added in v0.29.0

type FeedSubscription struct {
	ID         int64     `gorm:"primaryKey;autoIncrement"`
	TokenID    string    `gorm:"column:token_id;not null"`
	Repository string    `gorm:"column:repository;not null"`
	Type       string    `gorm:"column:type;not null;default:solo"`
	CreatedAt  time.Time `gorm:"column:created_at;not null;autoCreateTime:false"`
}

FeedSubscription is one repository (or "*") an agent token follows.

func (FeedSubscription) TableName added in v0.29.0

func (FeedSubscription) TableName() string

TableName pins the table name.

type FeedSubscriptionBatch added in v0.29.0

type FeedSubscriptionBatch struct {
	TokenID      string
	Repositories []string
	CreatedAt    time.Time
	Type         string
}

FeedSubscriptionBatch is a set of repositories to subscribe a token to.

type FeedSubscriptions added in v0.29.0

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

FeedSubscriptions persists which repositories each token follows.

func NewFeedSubscriptions added in v0.29.0

func NewFeedSubscriptions(db *gorm.DB) *FeedSubscriptions

NewFeedSubscriptions constructs a FeedSubscriptions repository bound to db.

func (*FeedSubscriptions) Add added in v0.29.0

Add inserts the repositories not yet subscribed and returns how many were new.

func (*FeedSubscriptions) Delete added in v0.29.0

func (r *FeedSubscriptions) Delete(ctx context.Context, tokenID string, id int64) (FeedSubscription, error)

Delete removes the token's subscription and returns it, or ErrNotFound.

func (*FeedSubscriptions) DeleteRepositories added in v0.29.0

func (r *FeedSubscriptions) DeleteRepositories(ctx context.Context, repositories []string) (int, error)

DeleteRepositories removes the repositories' subscriptions of every token and returns how many rows went.

func (*FeedSubscriptions) List added in v0.29.0

func (r *FeedSubscriptions) List(ctx context.Context, tokenID string) ([]FeedSubscription, error)

List returns the token's subscriptions in id order.

func (*FeedSubscriptions) Repositories added in v0.29.0

func (r *FeedSubscriptions) Repositories(ctx context.Context) ([]string, error)

Repositories returns the distinct repositories that have a subscription, sorted.

func (*FeedSubscriptions) SetType added in v0.32.0

func (r *FeedSubscriptions) SetType(ctx context.Context, change FeedTypeChange) (int, error)

SetType changes the type of the token's subscriptions and returns how many rows it changed.

type FeedTypeChange added in v0.32.0

type FeedTypeChange struct {
	TokenID      string
	Repositories []string
	Type         string
}

FeedTypeChange sets the type of a token's subscriptions; nil Repositories means every subscription.

type FeedWaitingPullRequest added in v0.32.0

type FeedWaitingPullRequest struct {
	Repository      string
	Number          int
	UpdatedAt       time.Time
	PartyReviewers  int
	PartyDeadlineAt *time.Time
}

FeedWaitingPullRequest holds the columns of a waiting pull request that the turn rule reads.

type Message

type Message struct {
	ID            uint   `gorm:"primaryKey"`
	PullRequestID uint   `gorm:"column:pull_request_id;not null"`
	Channel       string `gorm:"column:channel;not null"`
	MessageID     string `gorm:"column:message_id;not null"`
}

Message is one posted messenger message for a PR. (PullRequestID, Channel) is unique — at most one message per channel per PR. Channel is a room in the messenger; MessageID is the messenger's id for the post (Slack's ts).

func (Message) TableName

func (Message) TableName() string

TableName pins the table name.

type PullRequest

type PullRequest struct {
	ID         uint       `gorm:"primaryKey"`
	Repository string     `gorm:"column:gh_repository;not null"`
	PRNumber   int        `gorm:"column:pr_number;not null"`
	CreatedAt  time.Time  `gorm:"column:created_at;not null"`
	UpdatedAt  time.Time  `gorm:"column:updated_at;not null"`
	ClosedAt   *time.Time `gorm:"column:closed_at"`
	Messages   []Message  `gorm:"foreignKey:PullRequestID;constraint:OnDelete:CASCADE"`
}

PullRequest is one tracked PR. (Repository, PRNumber) is the natural key; CreatedAt is kept for later statistics, UpdatedAt is the activity clock (bumped on open and every review/comment) driving digest idle-detection and cleanup, and ClosedAt (nil = open) marks merged/closed so the digest skips it.

func (PullRequest) TableName

func (PullRequest) TableName() string

TableName pins the table name; do not rely on GORM pluralization.

type PullRequests

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

PullRequests persists tracked PRs and their per-channel messenger messages.

func NewPullRequests

func NewPullRequests(db *gorm.DB) *PullRequests

NewPullRequests constructs a PullRequests repository bound to db.

func (*PullRequests) AddMessage

func (r *PullRequests) AddMessage(ctx context.Context, repository string, prNumber int, channel, messageID string) error

AddMessage records one posted message, creating the PR row on first sight. Insertion is idempotent on (pull_request_id, channel): re-adding the same channel for the same PR is a no-op, which makes the open fan-out safe to replay after a partial failure or GitHub redelivery.

func (*PullRequests) Delete

func (r *PullRequests) Delete(ctx context.Context, repository string, prNumber int) error

Delete removes the PR and (by cascade) its messages. Missing PR is a no-op.

func (*PullRequests) DeleteStaleBefore

func (r *PullRequests) DeleteStaleBefore(ctx context.Context, cutoff time.Time) (int64, error)

DeleteStaleBefore removes PRs idle since before cutoff (messages cascade).

func (*PullRequests) FindStuck

func (r *PullRequests) FindStuck(ctx context.Context, cutoff time.Time) ([]PullRequest, error)

FindStuck returns open PRs idle since before cutoff, oldest first. Messages are deliberately not preloaded: the digest routes from config, not from where a PR's message happens to live.

func (*PullRequests) ListOpen

func (r *PullRequests) ListOpen(ctx context.Context) ([]PullRequest, error)

ListOpen returns every not-yet-closed PR, ordered for stable output.

func (*PullRequests) ListOpenWithMessages added in v0.25.0

func (r *PullRequests) ListOpenWithMessages(ctx context.Context) ([]PullRequest, error)

ListOpenWithMessages returns every not-yet-closed PR with its messages preloaded, ordered for stable output. It backs the relocate tooling, which needs to see where each open PR's messages currently live.

func (*PullRequests) MarkClosed

func (r *PullRequests) MarkClosed(ctx context.Context, repository string, prNumber int) error

MarkClosed sets closed_at. Missing PR is a no-op.

func (*PullRequests) Messages

func (r *PullRequests) Messages(ctx context.Context, repository string, prNumber int) ([]Message, error)

Messages returns the PR's messages, or ErrNotFound when the PR is unknown.

func (*PullRequests) MoveMessage added in v0.25.0

func (r *PullRequests) MoveMessage(ctx context.Context, repository string, prNumber int, fromChannel, toChannel, messageID string) error

MoveMessage retargets the PR's message row in fromChannel at toChannel and the newly posted messageID. Retargeting the existing row rather than deleting and re-inserting keeps the (pull_request_id, channel) uniqueness a single statement. ErrNotFound when the PR has no message in fromChannel.

func (*PullRequests) RemoveMessage added in v0.25.0

func (r *PullRequests) RemoveMessage(ctx context.Context, repository string, prNumber int, channel string) error

RemoveMessage drops the PR's message row for channel, leaving the Slack message itself alone. ErrNotFound when there is no such row.

func (*PullRequests) Touch

func (r *PullRequests) Touch(ctx context.Context, repository string, prNumber int) error

Touch bumps updated_at, recording activity. Missing PR is a no-op.

type Reactions

type Reactions = routingdomain.Reactions

Reactions aliases the routing domain value object during the migration.

type RepoMapping

type RepoMapping = routingdomain.RepoMapping

RepoMapping aliases the routing domain value object during the migration.

type ScheduledItem added in v0.27.0

type ScheduledItem struct {
	ID         uint
	Repository string
	PRNumber   int
	Channel    string
	Mentions   []string
	Title      string
	URL        string
	Author     string
	QueuedAt   time.Time
}

ScheduledItem is a scheduled notification with its PR's natural key.

type ScheduledNotification added in v0.27.0

type ScheduledNotification struct {
	ID            uint       `gorm:"primaryKey"`
	PullRequestID uint       `gorm:"column:pull_request_id;not null"`
	Channel       string     `gorm:"column:channel;not null"`
	Mentions      []string   `gorm:"column:mentions;serializer:json;not null"`
	Title         string     `gorm:"column:title;not null"`
	URL           string     `gorm:"column:url;not null"`
	Author        string     `gorm:"column:author;not null"`
	QueuedAt      time.Time  `gorm:"column:queued_at;not null"`
	SentAt        *time.Time `gorm:"column:sent_at"`
}

ScheduledNotification is one queued PR announcement for one channel under the scheduled notification strategy. SentAt nil means it waits for the next tick. (PullRequestID, Channel) is unique, so a PR is announced in a channel once; it is cascade-deleted with its PullRequest.

func (ScheduledNotification) TableName added in v0.27.0

func (ScheduledNotification) TableName() string

TableName pins the table name.

type ScheduledNotifications added in v0.27.0

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

ScheduledNotifications persists the queue of the scheduled notification strategy. Callers name a PR by its natural key; the pull_request_id is resolved internally.

func NewScheduledNotifications added in v0.27.0

func NewScheduledNotifications(db *gorm.DB) *ScheduledNotifications

NewScheduledNotifications constructs a ScheduledNotifications repository bound to db.

func (*ScheduledNotifications) AnnouncedSince added in v0.27.0

func (r *ScheduledNotifications) AnnouncedSince(ctx context.Context, cutoff time.Time) ([]ScheduledItem, error)

AnnouncedSince returns the items still waiting for a send or sent at or after cutoff.

func (*ScheduledNotifications) Enqueue added in v0.27.0

Enqueue queues the item, creating the PR row on first sight so the close and draft handlers find it. It is idempotent on (PR, channel), also after the row was sent: a webhook redelivery never announces a PR twice in a channel.

func (*ScheduledNotifications) MarkSent added in v0.27.0

func (r *ScheduledNotifications) MarkSent(ctx context.Context, ids []uint, sentAt time.Time) error

MarkSent stamps the items as sent at sentAt.

func (*ScheduledNotifications) Pending added in v0.27.0

Pending returns the unsent items of open PRs, oldest first.

type Target

type Target = routingdomain.Target

Target aliases the routing domain value object during the migration.

Jump to

Keyboard shortcuts

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