Documentation
¶
Overview ¶
Package store persists PRs, reviews and the audit trail in SQLite.
Index ¶
- Constants
- Variables
- type AuditEvent
- type LabelState
- type Review
- type Store
- func (s *Store) AddAudit(prID, reviewID int64, kind, msg string) error
- func (s *Store) ApprovalsFor(prs []github.PR, states ...string) ([]Review, error)
- func (s *Store) Audit(repo string, number, limit int) ([]AuditEvent, error)
- func (s *Store) ClaimNext() (*Review, error)
- func (s *Store) ClearOptOut(prID int64, label string) (bool, error)
- func (s *Store) Close() error
- func (s *Store) CountState(state string) (int, error)
- func (s *Store) EnqueueReview(prID int64, headSHA, agentName string, force bool) (int64, bool, error)
- func (s *Store) FailInterrupted(cap float64) ([]Review, error)
- func (s *Store) HeadApproved(prID int64, headSHA string, exceptID int64) (bool, error)
- func (s *Store) LabelState(prID int64, label string) (LabelState, error)
- func (s *Store) LatestReview(repo string, number int) (*Review, error)
- func (s *Store) MarkLabeled(prID int64, label string) error
- func (s *Store) MarkOptedOut(prID int64, label string) (bool, error)
- func (s *Store) PRRef(prID int64) (string, error)
- func (s *Store) Reviewed(prID int64, headSHA string) (bool, error)
- func (s *Store) SaveReview(r *Review) error
- func (s *Store) SchemaVersion() (int, error)
- func (s *Store) SetNow(now func() time.Time)
- func (s *Store) SpendSince(t time.Time) (float64, error)
- func (s *Store) SupersedeApprovals(prID, keepID int64, note string) ([]Review, error)
- func (s *Store) TransitionApproval(id int64, from, to string) (bool, error)
- func (s *Store) TransitionState(id int64, from, to string) (bool, error)
- func (s *Store) UpdateApproval(id int64, from, to, note string) (bool, error)
- func (s *Store) UpsertPR(pr github.PR) (int64, error)
Constants ¶
const ( Queued = "queued" Running = "running" Ready = "ready" // finished; waiting to be posted Posted = "posted" Blocked = "blocked" // never posted: possible secret in output Failed = "failed" // Posting is held while a post is in flight, so only one caller posts. Posting = "posting" // PostUnknown: the post may or may not have reached GitHub (timeout, // 5xx, or exit mid-post). Posting again first checks GitHub. PostUnknown = "post-unknown" )
Review states.
const ( ApprovalWaiting = "waiting" // not yet: CI, draft or a human's requested changes ApprovalPending = "pending" // qualifies; waiting for the operator (key a) ApprovalApproving = "approving" // approval in flight ApprovalApproved = "approved" ApprovalNo = "not eligible" // final for this commit ApprovalFailed = "failed" // GitHub refused (4xx), e.g. own PR ApprovalUnknown = "unknown" // may have reached GitHub; check before retrying )
Approval states (Review.Approval). Empty means approval wasn't considered.
Variables ¶
var ErrLocked = errors.New("another ghost is already running")
ErrLocked means another Ghost has the database open.
Functions ¶
This section is empty.
Types ¶
type AuditEvent ¶
type LabelState ¶ added in v0.3.0
type LabelState int
LabelState is what Ghost knows about a review label on a PR.
const ( LabelNever LabelState = iota // never seen on the PR or added by Ghost LabelAdded // was on the PR (added by Ghost or seen there) LabelOptedOut // removed after that: don't review )
type Review ¶
type Review struct {
ID int64
PRID int64
Repo string
Number int
HeadSHA string
Agent string
State string
Prompt string
Verdict string
Summary string
Comments string // JSON array of agent.InlineComment
Error string
CostUSD float64
Approval string
ApprovalNote string
CreatedAt time.Time
FinishedAt time.Time // set once the review stops running
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func Open ¶
Open opens (creating if needed) the database at path and applies migrations. The database holds private PR content, so new files are owner-only.
func (*Store) ApprovalsFor ¶
ApprovalsFor returns the reviews of the given PRs whose approval is in one of states.
func (*Store) Audit ¶
func (s *Store) Audit(repo string, number, limit int) ([]AuditEvent, error)
Audit returns a PR's last limit events, oldest first.
func (*Store) ClaimNext ¶
ClaimNext marks the oldest queued review running and returns it, or nil. The claim is one UPDATE so it takes SQLite's write lock up front: a read-then-write transaction would fail with SQLITE_BUSY_SNAPSHOT under concurrent writers instead of waiting on busy_timeout.
func (*Store) ClearOptOut ¶ added in v0.3.0
ClearOptOut records that the label was added back. It reports whether anything changed.
func (*Store) EnqueueReview ¶
func (s *Store) EnqueueReview(prID int64, headSHA, agentName string, force bool) (int64, bool, error)
EnqueueReview queues a review of headSHA. Unless force is set, it does nothing if any review of that head exists, whatever its state — a failed review may have cost money, so it is not retried automatically.
func (*Store) FailInterrupted ¶
FailInterrupted settles reviews a previous process left in flight. A running review may have spent money with no cost report, so it fails and is charged cap (it is not retried automatically); a posting one becomes PostUnknown. It returns the affected reviews.
func (*Store) HeadApproved ¶
HeadApproved reports whether another review of the same PR commit is approved by Ghost, or may be (in flight or unknown).
func (*Store) LabelState ¶ added in v0.3.0
func (s *Store) LabelState(prID int64, label string) (LabelState, error)
LabelState reports whether label was ever on the PR, and whether it was removed since. Labels compare case-insensitively.
func (*Store) LatestReview ¶
LatestReview returns the most recent review of a PR, or nil.
func (*Store) MarkLabeled ¶ added in v0.3.0
MarkLabeled records that label is (or was) on the PR. It never clears an opt-out; use ClearOptOut for that.
func (*Store) MarkOptedOut ¶ added in v0.3.0
MarkOptedOut records that a recorded label was removed. It reports whether anything changed, so the opt-out is audited once.
func (*Store) Reviewed ¶ added in v0.3.0
Reviewed reports whether any review (in any state) exists for the PR at headSHA. Auto-review queues each commit at most once.
func (*Store) SaveReview ¶
SaveReview writes a review's mutable fields except its approval, which only changes through compare-and-set (UpdateApproval, TransitionApproval) so a stale in-memory review can't undo a newer decision. Leaving the running state stamps finished_at once, which is when its cost counts toward the day.
func (*Store) SchemaVersion ¶
func (*Store) SpendSince ¶
SpendSince sums the cost of reviews that finished at or after t.
func (*Store) SupersedeApprovals ¶
SupersedeApprovals marks the waiting or pending approvals of a PR's other reviews not eligible (a newer review replaces them) and returns them.
func (*Store) TransitionApproval ¶
TransitionApproval moves a review's approval state only if it is still from; it reports whether it did.
func (*Store) TransitionState ¶
TransitionState moves a review from one state to another only if it is still in from; it reports whether it did.
func (*Store) UpdateApproval ¶
UpdateApproval sets a review's approval state and note only if its approval is still from; it reports whether it did.