Documentation
¶
Overview ¶
Package draft holds the Outbox drafts: posts the loop proposes and the user approves before they reach a provider.
Index ¶
- Constants
- Variables
- func SettledAt(ds []Draft, workflow string, subject unit.Unit) time.Time
- type Approval
- type ApprovalMode
- type Condition
- type Decision
- type Delivery
- type Draft
- type Evidence
- type ID
- type Kind
- type Origin
- type OriginKind
- type Outcome
- type Policy
- type Rule
- type State
- type Subject
- type Would
- type WouldPolicy
Constants ¶
const ( WithdrawAssigned = "assigned" WithdrawMoot = "moot" )
The reasons a workflow withdraws a draft it proposed, as Reason of the discarded draft: its person was assigned the items, or it is moot.
Variables ¶
var ApprovalModes = []ApprovalMode{Send, Delay, Wait, DryRun}
ApprovalModes are the draft approval's modes.
ConversationKinds are the kinds a draft on a conversation takes, as an agent names them: all but a review comment.
var ErrTransition = errors.New("draft: transition not allowed")
ErrTransition is wrapped by Can.
var Open = []State{Proposed, Approved, Sending}
Open are the states in which a draft may still be posted.
Functions ¶
func SettledAt ¶ added in v0.2.0
SettledAt is the newest UpdatedAt of the drafts of ds that workflow proposed on subject and that settled, sent or discarded (withdrawn ones included; a failed draft may still be approved again); zero when none. A draft is on an entry subject when it serves that entry, and on any other subject when it is on that unit.
Types ¶
type Approval ¶
type Approval struct {
Mode ApprovalMode
Window time.Duration // Mode "delay" only, > 0
}
type ApprovalMode ¶
type ApprovalMode string // "wait" (default), "delay", "send", "dry_run"
const ( Wait ApprovalMode = "wait" Delay ApprovalMode = "delay" Send ApprovalMode = "send" DryRun ApprovalMode = "dry_run" )
func (ApprovalMode) Releases ¶ added in v0.2.0
func (m ApprovalMode) Releases() bool
Releases says whether m sends a draft with no person approving it.
type Condition ¶ added in v0.2.0
Condition is a rule's compiled when over the facts RuleFacts and the unit's facts give.
type Decision ¶ added in v0.2.0
type Decision struct {
Approval Approval
// Rule is the index of the rule that matched; -1 for none.
Rule int
// CommentReleased says that a rule naming comment delivery released a
// comment draft, the only way one is sent with no person approving it.
CommentReleased bool
}
Decision is the approval Decide picked and why.
type Delivery ¶ added in v0.2.0
type Delivery string // "message", "reaction", "comment"
Delivery is how a draft reaches the provider.
type Draft ¶
type Draft struct {
ID ID
Unit unit.Unit
Items []string // item ids of Unit; may be empty
Entry string // the entry it serves, "" none; the Outbox entry itself is "draft:<ID>"
Kind Kind
Purpose string // what it is for: "nudge", "close", "ask_owner", or any label its proposer names
Delivery Delivery // how it is posted
Effects []string // applied when it is sent, such as "entry.nudged"
Target string // plugin target grammar; "" means the unit itself (its thread, its PR)
Text string // standard Markdown with mentions as @{<person key>}; the Effects implementation converts both
Reaction string // Kind "react" only: emoji name without colons
Original string // Text as proposed
Edited bool // Text != Original
Origin Origin
Approval Approval // fixed at proposal
Deadline time.Time // Approval.Mode "delay": when Tick approves it; zero otherwise
State State
Evidence Evidence // State "sent" only
Error string // State "failed" only, never a token
Reason string // State "discarded": "user", "assigned", "dry_run", ...
Would Would
Rev int64 // the stored row's version; every Update bumps it
// EffectsAppliedAt is when the Effects of a sent draft were applied;
// zero while they are not.
EffectsAppliedAt time.Time
CreatedAt, UpdatedAt, SendingAt time.Time
}
type Kind ¶
type Kind string // "reply", "nudge", "close", "react", "ask_owner", "comment"
type Origin ¶
type Origin struct {
Kind OriginKind
TurnSeq int64 // Kind "turn": the turn (session or headless) that proposed it; Kind "session": the handle's newest turn on the unit, 0 none
Intent string // the proposing turn's intent ("" for auto and user)
Workflow string // the workflow that started the proposing turn (turn.Turn.Workflow), "" none
Rule string // Kind "auto": the core or plugin rule, e.g. "stalled-nudge", "closure", "ask-owner", "github-nudge"
Key string // Kind "auto": the rule's dedupe key, e.g. "stalled-nudge:<entry>:<person key>"
}
type OriginKind ¶
type OriginKind string // "turn", "session", "auto", "user"
const ( OriginTurn OriginKind = "turn" OriginSession OriginKind = "session" OriginAuto OriginKind = "auto" OriginUser OriginKind = "user" )
type Outcome ¶
type Outcome string // "", "as_is", "edited", "discarded", "released" (approved by its policy), "dry_run" (stored, never sent)
type Policy ¶ added in v0.2.0
type Policy struct {
Default Approval
Rules []Rule
// Scope is the workflow whose scoped facts of the subject the rules
// read; "" reads the unit's facts unscoped.
Scope string
}
Policy is the approval of a proposer's drafts: the first Rule whose When holds, else Default.
func (Policy) Decide ¶ added in v0.2.0
Decide is d's approval under p over the facts of its subject s: a rule applies only when the facts it reads are of s's slot, a rule that releases applies to a comment draft only when it names comment delivery, and a comment draft no such rule releases waits for a person unless the approval is dry_run.
func (Policy) ReadsSubject ¶ added in v0.2.0
ReadsSubject says whether a rule of p reads a fact of the draft's subject.
type Rule ¶ added in v0.2.0
type Rule struct {
When Condition
Approval Approval
// NamesComment says that When holds only for a draft whose delivery is
// comment, so the rule may release one.
NamesComment bool
// Subjects are the slots of the subject facts When reads; the rule
// applies only to a draft whose subject is of that slot.
Subjects []string
}
Rule is one [drafts.approval] rule.
type Subject ¶ added in v0.2.0
Subject is the facts a policy's rules read beside the draft's own, and the slot they are of.
type Would ¶
type Would struct {
Policy WouldPolicy // what auto-send would have done, fixed at proposal
Reason string // why, one line
Outcome Outcome // what the user (or the policy) did, set at approve or discard
}
type WouldPolicy ¶
type WouldPolicy string // "release", "wait"
const ( WouldRelease WouldPolicy = "release" WouldWait WouldPolicy = "wait" )