Documentation
¶
Overview ¶
Package issues is the issue sheet: it shows one issue the user is assigned (its description, its conversation, where it stands, and the details beside it) and acts on it at the user's click: comment on it, or close it as completed or as not planned.
Open shows what the sheet read before, from its own cache, with no request; Refresh reads the issue again with one GraphQL request when it may have changed, and ReadAgain whenever the user asks; Earlier reads an earlier page of the conversation. Every read and action goes through the inbox's Actor (the item's lock and the account check), so the card is rewritten from the same answer, and every action is decided again (decide.go) before anything is sent. A close is pinned to the comments the user saw: it reads the newest comments first, and closes nothing over one someone else wrote since.
The package reaches the inbox only through the interfaces it declares, which the app's core adapts. It owns issue_views, the bounded cache of what it read.
Index ¶
- Variables
- type ActRequest
- type Acted
- type Action
- type Candidate
- type ChecksWord
- type Config
- type EditRequest
- type EditResult
- type Facts
- type Fix
- type FixFacts
- type GitHub
- type Inbox
- type Issue
- type IssueRead
- type IssueType
- type Milestone
- type Offer
- type Outcome
- type Person
- type Pictures
- type Plan
- type Project
- type ProjectField
- type Replies
- type Reply
- type RepoLabel
- type RepoLabels
- type Result
- type ReviewWord
- type Seen
- type Service
- func (s *Service) Act(ctx context.Context, req ActRequest) (Result, error)
- func (s *Service) Assignable(ctx context.Context, id int64, query string) ([]Candidate, error)
- func (s *Service) Avatars(ctx context.Context, logins []string) (map[string]string, error)
- func (s *Service) Earlier(ctx context.Context, id int64, before string) (timeline.Page, error)
- func (s *Service) Edit(ctx context.Context, req EditRequest) (EditResult, error)
- func (s *Service) FillReply(ctx context.Context, itemID, replyID int64) (string, error)
- func (s *Service) Labels(ctx context.Context, id int64) (RepoLabels, error)
- func (s *Service) Open(ctx context.Context, id int64) (Issue, error)
- func (s *Service) ReadAgain(ctx context.Context, id int64) (Issue, error)
- func (s *Service) Refresh(ctx context.Context, id int64) (Issue, error)
- func (s *Service) Replies(ctx context.Context) ([]Reply, error)
- type Standing
- type StandingState
- type StoredIssue
- type Target
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotOffered is returned for an action the sheet does not offer for the issue now; // nothing is sent. ErrNotOffered = errors.New("the action isn't available for the issue now") // ErrNewActivity is a close stopped, after its comment was posted, by a comment someone // else wrote since the user opened the issue. ErrNewActivity = errors.New("someone commented since the user opened the issue") )
var ErrCannotEdit = errors.New("the issue's labels or assignees can't be changed that way")
ErrCannotEdit is returned for an edit of an issue's labels or assignees the user can't make: their account has less than triage access, the sheet hasn't read the issue or read it closed, or the edit takes the user off it, which is Unassign me.
var ErrNotIssue = errors.New("the item is not an issue")
ErrNotIssue is returned for an item that is not an issue.
Functions ¶
This section is empty.
Types ¶
type ActRequest ¶
type ActRequest struct {
ItemID int64 `json:"itemId"`
Action Action `json:"action"`
Seen Seen `json:"seen"`
Body string `json:"body"`
}
ActRequest asks for an action on the issue with ItemID, pinned to Seen, the comments as of the read the user saw, with the user's text.
type Acted ¶
type Acted struct {
// Closed reports a close GitHub made, or found made: the issue leaves every list.
Closed bool
// Own reports that the close was the user's own and went through, not one someone
// made first that the action found.
Own bool
}
Acted is what an action made happen on GitHub. Its fields match inbox.IssueActed's.
type Action ¶
type Action string
Action is something the issue sheet can do with an issue.
const ( // ActionNone is no action: the primary of a sheet that can do nothing now. ActionNone Action = "" // ActionComment posts the user's text as a comment. ActionComment Action = "comment" // ActionCloseCompleted closes the issue as completed, posting the user's text first // when there is any. It always asks first. ActionCloseCompleted Action = "close_completed" // ActionCloseNotPlanned closes the issue as not planned, posting the user's text first // when there is any. It always asks first. ActionCloseNotPlanned Action = "close_not_planned" )
The sheet's actions.
type Candidate ¶
type Candidate struct {
Login string `json:"login"`
Name string `json:"name"`
Mine bool `json:"mine"`
}
Candidate is someone the issue can be assigned to: their login, their name or "", and whether they are the user.
type ChecksWord ¶
type ChecksWord string
ChecksWord is a pull request's checks, in a word.
const ( ChecksNone ChecksWord = "" ChecksPassing ChecksWord = "passing" ChecksFailing ChecksWord = "failing" ChecksRunning ChecksWord = "running" )
The checks' words.
type Config ¶
type Config struct {
// Pool is the database, which holds the sheet's cache.
Pool *sql.DB
Inbox Inbox
GitHub GitHub
Replies Replies
// Pictures serves the people's profile pictures; without it the sheet shows none.
Pictures Pictures
// Events hears what an action is doing as it goes (event.IssueProgress), for the sheet
// to show while the user waits.
Events event.Sink
Clock clock.Clock
Logger *slog.Logger
}
Config holds a Service's dependencies. Every one but Pictures, Events, Clock, and Logger is required.
type EditRequest ¶
type EditRequest struct {
ItemID int64 `json:"itemId"`
AddLabels []string `json:"addLabels"`
RemoveLabels []string `json:"removeLabels"`
AddAssignees []string `json:"addAssignees"`
RemoveAssignees []string `json:"removeAssignees"`
}
EditRequest asks to change the labels and assignees of the issue with ItemID: the labels to add and to take off, by name, and the people to assign and to unassign, by login. Taking the user off is Unassign me, never an edit.
type EditResult ¶
EditResult is what an edit made of an issue on GitHub: Sent counts the requests GitHub made, and Failed says why the one after them failed, or "" when every one went.
type Facts ¶
type Facts struct {
// Read reports that the sheet has read the issue from GitHub; Gone that GitHub can't
// find it any more.
Read bool
Gone bool
// Closed reports a closed issue: StateReason why, ClosedBy who or what closed it
// ("octo-other", "acme-org/api#14"), ClosedAt when, and DuplicateOf what it duplicates.
Closed bool
StateReason timeline.StateReason
ClosedBy string
ClosedAt string
DuplicateOf string
// Locked reports a locked conversation, LockReason why; CanWrite that the user has
// write access, so may comment on it anyway; CanClose that GitHub lets them close it.
Locked bool
LockReason string
CanWrite bool
CanClose bool
// Fixes are the pull requests that close it once merged, and MoreFixes how many others.
Fixes []FixFacts
MoreFixes int
// RepliedLast reports that the newest comment is the user's, written at RepliedAt.
RepliedLast bool
RepliedAt string
// Assigned reports that it is assigned to the user; OpenedAt when it opened.
Assigned bool
OpenedAt string
}
Facts are what the sheet knows of an issue, from its card and its last read, for Decide.
type Fix ¶
type Fix struct {
PR timeline.Ref `json:"pr"`
Base string `json:"base"`
MergedAt string `json:"mergedAt"`
Checks ChecksWord `json:"checks"`
Review ReviewWord `json:"review"`
}
Fix is a pull request that closes the issue once merged: where it merges, when it did, and its checks and review.
type FixFacts ¶
type FixFacts struct {
Ref string
Base string
Merged bool
MergedAt string
Open bool
Draft bool
Checks ChecksWord
}
FixFacts is a pull request that closes the issue: its name, as in "acme-org/api#14", the branch it merges into, whether it merged and when, whether it is a draft, and its checks.
type GitHub ¶
type GitHub interface {
FetchIssueView(ctx context.Context, tok github.Token, id string, opts github.DetailOptions) (*github.IssueView, error)
FetchIssueState(ctx context.Context, tok github.Token, id string) (*github.IssueState, error)
FetchTimeline(ctx context.Context, tok github.Token, kind item.Kind, id, before string) (*github.TimelinePage, error)
AddComment(ctx context.Context, tok github.Token, ref item.Ref, body string) (*github.Comment, error)
CloseIssue(ctx context.Context, tok github.Token, ref item.Ref, reason string) (*github.IssueClosed, error)
FetchRepoLabels(ctx context.Context, tok github.Token, id string) (*github.RepoLabels, error)
FetchAssignable(ctx context.Context, tok github.Token, id, query string) ([]github.Assignable, error)
AddLabels(ctx context.Context, tok github.Token, ref item.Ref, names []string) ([]github.Label, error)
RemoveLabel(ctx context.Context, tok github.Token, ref item.Ref, name string) ([]github.Label, error)
AddAssignees(ctx context.Context, tok github.Token, ref item.Ref, logins []string) (*github.Edited, error)
RemoveAssignee(ctx context.Context, tok github.Token, ref item.Ref, login string) (*github.Edited, error)
}
GitHub is the GitHub client's reads and writes the sheet uses. *github.Client implements it.
type Inbox ¶
type Inbox interface {
Issue(ctx context.Context, id int64) (StoredIssue, error)
Read(ctx context.Context, id int64, read func(context.Context, github.Token, Target) (IssueRead, error)) error
Act(ctx context.Context, id int64, act func(context.Context, github.Token, Target) (Acted, error)) error
Peek(ctx context.Context, id int64, peek func(context.Context, github.Token, Target) error) error
}
Inbox is what the sheet needs of the inbox: a stored issue, and reads and actions run with the inbox's footing (inbox.Actor): the item's lock, the account check, and a token, borrowed again once when GitHub refuses one.
type Issue ¶
type Issue struct {
ID int64 `json:"id"`
Repo string `json:"repo"`
Number int `json:"number"`
Title string `json:"title"`
URL string `json:"url"`
State timeline.RefState `json:"state"`
StateReason timeline.StateReason `json:"stateReason"`
ClosedAt string `json:"closedAt"`
// Author opened it; IsBot says it is a bot, and Mine that it is the user.
Author string `json:"author"`
IsBot bool `json:"isBot"`
Mine bool `json:"mine"`
// OpenedAt is when it was opened, and UpdatedAt GitHub's time of its newest activity,
// as of the read: the window compares the card's with it.
OpenedAt string `json:"openedAt"`
UpdatedAt string `json:"updatedAt"`
// Assigned reports that it is assigned to the user.
Assigned bool `json:"assigned"`
// Locked reports a locked conversation, and LockReason why, as GitHub says it.
Locked bool `json:"locked"`
LockReason string `json:"lockReason"`
// CanEdit reports that the user may change its labels and assignees: an open issue the
// sheet has read, so its assignees are known, with triage access or more to its
// repository.
CanEdit bool `json:"canEdit"`
// Body is the description, BodyTrimmed whether the cache cut it short (its page has
// all of it), and EditedAt when it was last edited, or "".
Body string `json:"body"`
BodyTrimmed bool `json:"bodyTrimmed"`
EditedAt string `json:"editedAt"`
Reactions []timeline.Reaction `json:"reactions"`
Type *IssueType `json:"type"`
Milestone *Milestone `json:"milestone"`
Labels []timeline.Label `json:"labels"`
Projects []Project `json:"projects"`
// Assignees and Participants are the first few of each, and More how many others.
Assignees []Person `json:"assignees"`
MoreAssignees int `json:"moreAssignees"`
Participants []Person `json:"participants"`
MoreParticipants int `json:"moreParticipants"`
Parent *timeline.Ref `json:"parent"`
DuplicateOf *timeline.Ref `json:"duplicateOf"`
// SubIssues are the first sub-issues, of SubIssuesTotal, SubIssuesDone of them done.
SubIssues []timeline.Ref `json:"subIssues"`
SubIssuesTotal int `json:"subIssuesTotal"`
SubIssuesDone int `json:"subIssuesDone"`
// Fixes are the pull requests that close it once merged, MoreFixes how many others;
// Mentioned the pull requests and issues that mentioned it, in the timeline read.
Fixes []Fix `json:"fixes"`
MoreFixes int `json:"moreFixes"`
Mentioned []timeline.Ref `json:"mentioned"`
Timeline timeline.Page `json:"timeline"`
// LastSeenAt is GitHub's time of the newest activity in the read the sheet showed when
// the user last opened the issue, "" before then: what is newer is new to them.
LastSeenAt string `json:"lastSeenAt"`
// Seen is what an action pins: the comments as of the read the sheet shows.
Seen Seen `json:"seen"`
Standing Standing `json:"standing"`
Offers []Offer `json:"offers"`
Primary Action `json:"primary"`
// FetchedAt is when the sheet last read it from GitHub, "" before then; Stale says a
// read is due.
FetchedAt string `json:"fetchedAt"`
Stale bool `json:"stale"`
}
Issue is one issue as the sheet shows it. Its labels, projects, and counts come from the inbox card; the rest from the sheet's last read of GitHub, or are empty before one. No list is ever nil.
type IssueRead ¶
type IssueRead struct {
Update *github.ItemUpdate
}
IssueRead is what a read found: the item as GitHub answered, which rewrites the inbox card. Its fields match inbox.IssueRead's.
type IssueType ¶
type IssueType struct {
Name string `json:"name"`
Color string `json:"color"`
Description string `json:"description"`
}
IssueType is an issue's type, with its color as "#rrggbb" or "".
type Milestone ¶
type Milestone struct {
Title string `json:"title"`
URL string `json:"url"`
DueOn string `json:"dueOn"`
State string `json:"state"`
Progress float64 `json:"progress"`
}
Milestone is the milestone an issue is in. DueOn is its due day at midnight UTC, or "".
type Offer ¶
type Offer struct {
Action Action `json:"action"`
Label string `json:"label"`
Enabled bool `json:"enabled"`
Reason string `json:"reason"`
Confirm bool `json:"confirm"`
CommentsFirst bool `json:"commentsFirst"`
CommentBlocked string `json:"commentBlocked"`
}
Offer is one action the sheet offers: its words, whether it can run now and why not, whether it asks first, whether it posts the user's text as a comment first, and, when GitHub can't take that comment now, why.
type Outcome ¶
type Outcome string
Outcome is what an action came to.
const ( // OutcomeCommented is a comment GitHub took. OutcomeCommented Outcome = "commented" // OutcomeClosed is a close GitHub made, with the user's comment first when there was // one. OutcomeClosed Outcome = "closed" // OutcomeCommentedNotClosed is a close whose comment GitHub took and whose close it // didn't make: the comment stands, so the sheet drops it from the draft. OutcomeCommentedNotClosed Outcome = "commented_not_closed" // OutcomeNewActivity is a close refused before anything was sent: someone commented // since the user opened the issue. OutcomeNewActivity Outcome = "new_activity" // OutcomeAlreadyClosed is a close of an issue someone closed first. OutcomeAlreadyClosed Outcome = "already_closed" )
The outcomes.
type Pictures ¶
type Pictures interface {
Pictures(ctx context.Context, logins []string) (map[string]string, error)
}
Pictures serves the profile pictures of the people the sheet shows, as data: URLs keyed by login. *avatars.Service implements it.
type Project ¶
type Project struct {
Title string `json:"title"`
URL string `json:"url"`
Status string `json:"status"`
StatusColor string `json:"statusColor"`
Fields []ProjectField `json:"fields"`
}
Project is the issue's place in a project, as its card shows it.
type ProjectField ¶
type ProjectField struct {
Name string `json:"name"`
Value string `json:"value"`
Color string `json:"color"`
}
ProjectField is the issue's value in one of a project's fields.
type Replies ¶
type Replies interface {
Offered(ctx context.Context) ([]Reply, error)
Fill(ctx context.Context, replyID, itemID int64) (string, error)
}
Replies is the prompt library's replies the composer offers: the comment replies that apply to issues, each filled in for an issue as a launch on it fills a prompt.
type Reply ¶
type Reply struct {
ID int64 `json:"id"`
Name string `json:"name"`
Nickname string `json:"nickname"`
}
Reply is a reply from the prompt library the composer offers: its ID, its title, and the nickname the menu shows.
type RepoLabel ¶
type RepoLabel struct {
Name string `json:"name"`
Color string `json:"color"`
Description string `json:"description"`
}
RepoLabel is one of a repository's labels, with its color as "#rrggbb" or "", and what it says it is for.
type RepoLabels ¶
RepoLabels are the labels of the issue's repository the label picker offers: the first hundred in name order, and how many it has.
type Result ¶
type Result struct {
Outcome Outcome `json:"outcome"`
Message string `json:"message"`
Reason string `json:"reason"`
Steps []string `json:"steps"`
Commented bool `json:"commented"`
LeftInbox bool `json:"leftInbox"`
}
Result is what an action came to: its outcome, the toast's words, why a close didn't happen, the steps GitHub made, whether the user's text is on GitHub now (Commented), and whether the issue left the inbox.
type ReviewWord ¶
type ReviewWord string
ReviewWord is a pull request's review decision, in a word.
const ( ReviewNone ReviewWord = "" ReviewApproved ReviewWord = "approved" ReviewChangesRequested ReviewWord = "changes_requested" ReviewRequired ReviewWord = "review_required" )
The review decisions' words.
type Seen ¶
type Seen struct {
Comments int `json:"comments"`
Latest string `json:"latest"`
LatestAt string `json:"latestAt"`
}
Seen is the comments the user saw: how many, and the newest by ID and time ("" for none). A close checks nobody commented since.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the issue sheet as the window binds it. It is safe for concurrent use.
func (*Service) Act ¶
Act runs the action the user asked for on an issue, and returns what it came to. It runs only what the sheet offers now, decided again on what the sheet read. A close is pinned to the comments the user saw (the earlier of what the request says and what the read holds): every try first reads the issue's state and its newest comments, and closes nothing over a comment someone else wrote since (OutcomeNewActivity, with nothing sent) nor an issue someone closed first (OutcomeAlreadyClosed, which leaves the inbox); then it posts the user's text as a comment, once, and closes. A step GitHub made stands: once a close's comment is posted, nothing that fails after it is an error, but OutcomeCommentedNotClosed, so the sheet drops the text and never posts it twice.
func (*Service) Assignable ¶
Assignable returns the people the issue can be assigned to whose login or name matches query, the first twenty: read with one GraphQL point a search, one at a time for the same words in the same repository, then kept ten minutes. The user is marked.
func (*Service) Avatars ¶
Avatars returns the profile pictures of the people with logins, as the sheets show them beside their names (the review sheet's window asks through this one method too), as data: URLs keyed by login, leaving out anyone without one (see avatars.Service.Pictures). Each picture is downloaded from GitHub's avatar host once and kept, so the window loads nothing remote itself.
func (*Service) Earlier ¶
Earlier reads the page of the issue's timeline before the cursor before, which a page the sheet holds gave: one GraphQL request, which stores nothing, not even in the cache.
func (*Service) Edit ¶
func (s *Service) Edit(ctx context.Context, req EditRequest) (EditResult, error)
Edit changes the labels and assignees of the issue with req.ItemID as req asks, with one REST request for the labels added, one for each label taken off, one for the people assigned, and one for each person unassigned, through the inbox's Actor (the item's lock, the account check, and a token borrowed again once when GitHub refuses one, which never sends a step twice). GitHub ignores a change an account can't make rather than refusing it, so every answer is checked. It stops at the first step that fails, and those before it stand: once GitHub made any, the result counts them and says why the next failed, while a failure before any is the error. A name given twice is sent once, and one both added and taken off not at all. The sheet's copy of the issue is marked out of date, for the read the sheet makes next.
func (*Service) FillReply ¶
FillReply fills in the reply with replyID for the issue with itemID, as the text the comment starts with.
func (*Service) Labels ¶
Labels returns the labels of the issue's repository the picker offers, the first hundred in name order: read with one GraphQL point, one read per repository at a time, then kept ten minutes.
func (*Service) Open ¶
Open returns the issue with id as the sheet last read it, from its cache and the inbox, with no request: at once, and offline. It starts a visit: LastSeenAt is GitHub's time of the newest activity in the read it shows, so what a refresh brings that is newer is new to the user, and every Refresh and ReadAgain returns the same until the next Open. Stale says a Refresh is due.
func (*Service) ReadAgain ¶
ReadAgain reads the issue with id from GitHub as Refresh does, however recently it was read: the user asked for it, from the sheet's refresh button. A read already under way for the issue is joined rather than run beside it.
func (*Service) Refresh ¶
Refresh reads the issue with id from GitHub, stores it, and returns it: one GraphQL request, whose answer rewrites the inbox card too. An issue read in the last 20 seconds is not read again, unless its card shows activity since. Two reads of one issue never run side by side. An issue the read finds closed, or that GitHub can't find any more, is returned as read this once, and the sheet forgets it.
type Standing ¶
type Standing struct {
State StandingState `json:"state"`
Sentence string `json:"sentence"`
At string `json:"at"`
Opened bool `json:"opened"`
}
Standing is where the issue stands: its state, a sentence, the time it is about ("" for none), and Opened when that time is the issue's opening, as in "opened 3 days ago".
type StandingState ¶
type StandingState string
StandingState is where an issue stands: the sheet's one sentence above its details.
const ( StandingGone StandingState = "gone" StandingClosed StandingState = "closed" StandingLocked StandingState = "locked" StandingFixMerged StandingState = "fix_merged" StandingFixOpen StandingState = "fix_open" StandingRepliedLast StandingState = "replied_last" StandingAssigned StandingState = "assigned" StandingOpen StandingState = "open" )
The standings, highest first: the first that holds is the issue's.
type StoredIssue ¶
type StoredIssue struct {
ID int64
Kind item.Kind
Number int
NodeID string
Title string
URL string
AuthorLogin string
AuthorType string
AuthorAssociation string
CreatedAt time.Time
UpdatedAt time.Time
// Assigned reports that the issue is assigned to the user, the only reason an issue is
// in the inbox.
Assigned bool
Owner string
Name string
DefaultBranch string
// ViewerPermission is the user's access to the repository: ADMIN, MAINTAIN, WRITE,
// TRIAGE, or READ.
ViewerPermission string
// Viewer is the account whose inbox lists the issue.
Viewer string
HasDetails bool
Labels []github.Label
Comments int
Projects []github.ProjectItem
SubIssues github.SubIssues
DetailsAt time.Time
}
StoredIssue is an issue as the inbox stored it, with its repository's default branch and the user's access to it. Its fields match inbox.IssueItem's, so the core converts one to the other.
type Target ¶
type Target struct {
ID int64
Ref item.Ref
NodeID string
Login string
UpdatedAt time.Time
Assigned bool
// Projects says to read the issue's projects, as the inbox's last whole refresh could.
Projects bool
}
Target is the issue a read or an action is for, as the inbox's Actor hands it over. Its fields match inbox.IssueTarget's.