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
- func Subjects(d Draft) []unit.Unit
- type Approval
- type ApprovalMode
- type Broadcast
- type Condition
- type Decision
- type Delivery
- type Draft
- type Evidence
- type ID
- type Kind
- type Origin
- type OriginKind
- type Placed
- type Policy
- type Rule
- type State
- type Subject
Constants ¶
const ( WithdrawAssigned = "assigned" WithdrawMoot = "moot" WithdrawOutside = "outside" WithdrawJoined = "joined" WithdrawEnded = "ended" WithdrawSkipped = "skipped" WithdrawSuperseded = "superseded" )
The reasons a draft is withdrawn, as Reason of the discarded draft: a workflow's, its person was assigned the items or it is moot; a verb ended the task the draft served; the user skipped its workflow on its unit; or one draft to the whole conversation replaced it. Outside: it addresses someone who cannot read the conversation it posts in. Joined: the person it was written to in their own conversation joined the one it came from.
const ReasonClosedSilently = "closed_silently"
ReasonClosedSilently is the Reason of a draft the user discarded and closed without its message: its effects apply as if it was sent.
Variables ¶
var ApprovalModes = []ApprovalMode{Send, Delay, Wait, DryRun}
ApprovalModes are the draft approval's modes.
ConversationKinds are the kinds slack_draft offers on a conversation: all but a review comment, an edit and a deletion, which slack_edit and slack_delete make at once.
var ErrTransition = errors.New("draft: transition not allowed")
ErrTransition is wrapped by Can.
var Open = []State{Held, Queued, Sending}
Open are the states in which a draft may still be posted.
var SettledStates = []State{Sent, Dropped}
SettledStates are the states of a settled draft.
var WithdrawReasons = []string{WithdrawAssigned, WithdrawMoot, WithdrawOutside, WithdrawJoined, WithdrawEnded, WithdrawSkipped, WithdrawSuperseded}
WithdrawReasons are every reason a draft is withdrawn with.
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 dropped (withdrawn ones included; a failed draft may still be approved again); zero when none. A draft is on a task subject when it serves that task, 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 ModeOf ¶ added in v0.3.0
func ModeOf(m gate.Mode) ApprovalMode
ModeOf is a gate's approval mode as a draft's: send and run send it.
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 Broadcast ¶ added in v0.4.0
type Broadcast string
Broadcast says whether a thread reply is also posted to its conversation. It is NoBroadcast when the draft replies in no thread, as its publisher places it when it is proposed.
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
// PostReleased says that a rule naming d's delivery released a draft
// whose delivery posts, the only way one is sent with no person
// approving it.
PostReleased bool
}
Decision is the approval Decide picked and why.
type Delivery ¶ added in v0.2.0
type Delivery string // "message", "reaction", "comment", "edit", "delete"
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
Task string // the task it serves, "" none; the Outbox row of the draft 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 "task.nudged"
Target string // plugin target grammar; "" means the unit itself (its thread, its PR)
Broadcast Broadcast // a thread reply also posted to its conversation; NoBroadcast when it replies in no thread
Text string // standard Markdown with mentions as @{<person key>}; the Effects implementation converts both; Kind "delete": the text of the message it removed, as Slack held it
Reaction string // Kind "react" only: emoji name without colons
Replaced string // Kind "edit" only: the text the edit replaced
Original string // Text as proposed
Edited bool // Text != Original
Origin Origin
State State
Evidence Evidence // State "sent" only
Error string // State "failed" only, never a token
Reason string // State "dropped": "user", "assigned", "moot", "dry_run", ...
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
// Why is why it was proposed, in the user's language when it was;
// Language is the locale Text is written in. Both "" for a draft no
// workflow step wrote.
Why, Language string
CreatedAt, UpdatedAt, SendingAt time.Time
}
func (Draft) Can ¶
Can says why d cannot move to s, nil when it can: held->queued|failed|dropped; queued->sending|failed|dropped; sending->sent|failed; failed->queued (by hand only)|dropped.
func (Draft) EffectsDue ¶ added in v0.4.0
EffectsDue says whether d's effects are owed: it was sent, or closed without its message.
type Kind ¶
type Kind string // "reply", "nudge", "close", "react", "ask_owner", "comment", "edit", "delete"
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:<task>:<person key>"
// Unit is the unit of the proposing turn when it is not the draft's, such
// as a pull request whose turn drafts in a Slack thread; zero when it is.
Unit unit.Unit
// Session is the session that proposed it through its tools, which never
// resolves its gate; "" when no session did.
Session string
}
type OriginKind ¶
type OriginKind string // "turn", "session", "auto", "user"
const ( OriginTurn OriginKind = "turn" OriginSession OriginKind = "session" OriginAuto OriginKind = "auto" OriginUser OriginKind = "user" )
type Placed ¶ added in v0.4.0
Placed is where its publisher puts a draft when it is proposed: the target a draft with none posts to, "" for its unit, and its Broadcast.
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; posts says that d's delivery reaches people, as its plugin's manifest declares it. A rule applies only when the facts it reads are of s's slot, a rule that releases applies to a draft that posts only when it names d's delivery, and a draft that posts 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
// Names is the delivery When holds for alone, which its top-level
// conjunction pins; "" for none. A rule releases a draft whose delivery
// posts only when it names that delivery.
Names Delivery
// 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 [gates.approval] rule of a draft gate.