Documentation
¶
Overview ¶
Package tracker manages projects and tickets held in one GitHub repository.
Index ¶
- Constants
- Variables
- type BoardAccessError
- type Client
- func (c *Client) AddAttachments(ctx context.Context, number int, body *string, files []string) error
- func (c *Client) AddComment(ctx context.Context, number int, body string, files []string) error
- func (c *Client) AddComponent(ctx context.Context, repo Repo, dir, component string) (Project, error)
- func (c *Client) AddLabels(ctx context.Context, number int, labels []string) error
- func (c *Client) AddProject(ctx context.Context, repo Repo) (Project, error)
- func (c *Client) AddToEpic(ctx context.Context, epic int, tickets []int, move bool) (int, error)
- func (c *Client) ClaimNext(ctx context.Context, project string, tally *Tally) (Ticket, bool, error)
- func (c *Client) ClaimTicket(ctx context.Context, number int) (Ticket, error)
- func (c *Client) CloseEligibleEpic(ctx context.Context, number int) (bool, error)
- func (c *Client) CloseEpic(ctx context.Context, number int, reason string) error
- func (c *Client) CloseTicket(ctx context.Context, number int, opts CloseOptions) (Ticket, error)
- func (c *Client) CreateEpic(ctx context.Context, opts EpicOptions) (Ticket, error)
- func (c *Client) CreateHandoff(ctx context.Context, opts HandoffOptions) (Handoff, error)
- func (c *Client) CreateTicket(ctx context.Context, opts CreateOptions) (Ticket, error)
- func (c *Client) DemoteEpic(ctx context.Context, number int) error
- func (c *Client) DropHandoff(ctx context.Context, name, reason string, freeSlot bool) (Handoff, bool, error)
- func (c *Client) EditTicket(ctx context.Context, number int, opts EditOptions) error
- func (c *Client) ImportIssues(ctx context.Context, opts ImportOptions) (ImportResult, error)
- func (c *Client) InspectEpic(ctx context.Context, number int) (EpicDetail, error)
- func (c *Client) InspectTicket(ctx context.Context, number int) (TicketDetail, error)
- func (c *Client) InspectTickets(ctx context.Context, numbers []int) ([]TicketDetail, error)
- func (c *Client) ListTickets(ctx context.Context, opts ListOptions) ([]Ticket, int, error)
- func (c *Client) MoveTicket(ctx context.Context, number int, target string) error
- func (c *Client) ProjectIn(ctx context.Context, current Repo, refresh bool) (Project, bool, error)
- func (c *Client) ProjectName(repo Repo) string
- func (c *Client) ProjectRepo(ctx context.Context, name string) (string, bool, error)
- func (c *Client) ProjectSummary(ctx context.Context, project Project) (ProjectSummary, error)
- func (c *Client) Projects(ctx context.Context) ([]Project, error)
- func (c *Client) PromoteEpic(ctx context.Context, number int) error
- func (c *Client) PruneAttachments(ctx context.Context, remove bool) ([]string, error)
- func (c *Client) PullAttachments(ctx context.Context, number int, dir string) ([]string, error)
- func (c *Client) ReleaseTicket(ctx context.Context, number int) error
- func (c *Client) RemoveAttachments(ctx context.Context, number int, files []string) ([]string, error)
- func (c *Client) RemoveFromEpic(ctx context.Context, epic int, tickets []int) error
- func (c *Client) RemoveLabels(ctx context.Context, number int, labels []string) error
- func (c *Client) RemoveProject(ctx context.Context, name string) error
- func (c *Client) ReopenTicket(ctx context.Context, number int) error
- func (c *Client) Repo() Repo
- func (c *Client) ResolveProject(ctx context.Context, name string) (Project, error)
- func (c *Client) ScanRepos(ctx context.Context, authors []string) ([]RepoScan, error)
- func (c *Client) SetBlockers(ctx context.Context, number int, blockers []int, add bool) error
- func (c *Client) SetStatus(ctx context.Context, number int, status string) error
- func (c *Client) ShowHandoff(ctx context.Context, name string) (Handoff, error)
- func (c *Client) SyncDescriptions(ctx context.Context, projects []Project) (DescriptionResult, error)
- func (c *Client) TakeHandoff(ctx context.Context, name string) (TakenHandoff, error)
- func (c *Client) UntakeHandoff(ctx context.Context, number int, reason string) (Handoff, error)
- type CloseOptions
- type Comment
- type CreateOptions
- type DescriptionResult
- type EditOptions
- type EpicDetail
- type EpicOptions
- type Handoff
- type HandoffOptions
- type ImportOptions
- type ImportResult
- type ListOptions
- type Options
- type Project
- type ProjectSummary
- type Repo
- type RepoScan
- type SubIssue
- type TakenHandoff
- type Tally
- type Ticket
- func (t Ticket) Closable() bool
- func (t Ticket) Created() time.Time
- func (t Ticket) Epic() bool
- func (t Ticket) Handoff() bool
- func (t Ticket) OtherLabels() []string
- func (t Ticket) Priority() string
- func (t Ticket) PriorityConflicts() []string
- func (t Ticket) Ready() bool
- func (t Ticket) Stale(days int, now time.Time) bool
- type TicketDetail
Constants ¶
const ( ReasonCompleted = "completed" ReasonNotPlanned = "not-planned" ReasonDuplicate = "duplicate" )
CloseReason values for closing a ticket without a pull request.
const ( StatusTodo = "Todo" StatusDoing = "Doing" StatusDone = "Done" )
Ticket statuses, which are the columns of every project board.
const MaxInspect = 50
MaxInspect is the most tickets InspectTickets reads in one call. GitHub charges 2 points for 20 of them and 5 points for 50.
const StateClosed = "CLOSED"
StateClosed is GitHub's state of a closed ticket.
Variables ¶
var ErrAlreadyClaimed = errors.New("ticket is already claimed")
ErrAlreadyClaimed reports that another agent holds the claim.
var ErrNoHandoff = errors.New("no open handoff")
ErrNoHandoff reports that a project has no open handoff.
var ErrRateLimited = errors.New("GitHub rate limit reached")
ErrRateLimited reports that GitHub refused a request because of a rate limit.
Functions ¶
This section is empty.
Types ¶
type BoardAccessError ¶
type BoardAccessError struct {
Detail string
// Account is the configured login, which gh auth refresh reaches only while it
// is gh's active account.
Account string
}
BoardAccessError reports a GitHub login without the project scope. Its message names the fix; Detail holds GitHub's own explanation for agents.
func (*BoardAccessError) Error ¶
func (e *BoardAccessError) Error() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the tracker repository.
func New ¶
New builds a Client. It leaves go-gh's response cache disabled because that cache can replay GraphQL mutations and stored 429 responses.
func (*Client) AddAttachments ¶
func (c *Client) AddAttachments(ctx context.Context, number int, body *string, files []string) error
AddAttachments uploads files to a ticket's body. With body set, it replaces the body and the body's references to the files are pointed at them; otherwise the files are appended to the current body. Images and video go through gh, the one operation that runs it, because GitHub's attachment endpoint is undocumented.
func (*Client) AddComment ¶
AddComment adds a comment to a ticket, with files attached where its text references them, or after it.
func (*Client) AddComponent ¶
func (c *Client) AddComponent(ctx context.Context, repo Repo, dir, component string) (Project, error)
AddComponent registers a directory of a registered repository as a project of its own, named repository/component after the directory unless component is given. It uses the repository's board, so registering it writes only its label.
func (*Client) AddLabels ¶
AddLabels adds labels to a ticket. GitHub creates a name it does not know yet.
func (*Client) AddProject ¶
AddProject registers a code repository. Writing the label comes last, so a failed run leaves nothing registered and can simply be repeated. A repository already registered under another name, as other owners' repositories once were, keeps that name.
func (*Client) AddToEpic ¶
AddToEpic makes tickets the epic's tickets and reports how many it added. A ticket already in the epic is left alone, and an epic never holds more than GitHub's limit of sub-issues per parent. Move takes a ticket from another parent; without it, such a ticket fails the command before anything changes.
func (*Client) ClaimNext ¶
ClaimNext claims the most urgent ready ticket, oldest first within a priority, moving on when another agent wins a candidate. It reports false when no ticket is ready. Project may be empty. Tally, when set, counts the tickets it read.
func (*Client) ClaimTicket ¶
ClaimTicket takes a ticket for the caller. GitHub rejects a second create of the same ref, which makes the claim atomic where labels, assignees, and project fields would accept both writers. GraphQL cannot see this namespace, so claims use REST.
func (*Client) CloseEligibleEpic ¶
CloseEligibleEpic closes an epic whose tickets are all closed, as completed, and reports whether it did. The list that found the epic can be out of date, so this decides from a fresh read.
func (*Client) CloseEpic ¶
CloseEpic closes an epic. Completed needs every ticket of the epic closed; not-planned leaves its open tickets as they are.
func (*Client) CloseTicket ¶
CloseTicket closes a ticket after confirming every pull request merged. When it was the last open ticket of its epic, the epic closes too, as completed, unless it is claimed or blocked. It returns that epic, or a zero ticket.
func (*Client) CreateEpic ¶
CreateEpic creates an epic on its project's board with status Todo. The epic label is set by the create itself, so the epic is never ready work.
func (*Client) CreateHandoff ¶
CreateHandoff opens a project's one handoff. The slot ref is created first, so a second handoff fails before anything else is written, and is deleted again when the ticket cannot be created.
func (*Client) CreateTicket ¶
CreateTicket creates a ticket on its project board with status Todo. A failure after creation names the ticket so the caller can finish it instead of duplicating it.
func (*Client) DemoteEpic ¶
DemoteEpic makes an epic an ordinary ticket. It must have no tickets left.
func (*Client) DropHandoff ¶
func (c *Client) DropHandoff(ctx context.Context, name, reason string, freeSlot bool) (Handoff, bool, error)
DropHandoff closes a project's open handoff as not planned without claiming it, and frees the slot. With no open handoff, freeSlot frees a slot that a failed create left behind and reports false. A slot without a handoff can also belong to a create still running, so it is freed only when asked. It reports ErrNoHandoff when there was nothing to drop or free.
func (*Client) EditTicket ¶
EditTicket changes a ticket's title or body, and attaches files to the body.
func (*Client) ImportIssues ¶
func (c *Client) ImportIssues(ctx context.Context, opts ImportOptions) (ImportResult, error)
ImportIssues transfers a repository's movable issues into the tracker. A public issue cannot move back, so the tracker must be private, and only issues written entirely by trusted authors move.
func (*Client) InspectEpic ¶
InspectEpic reads an epic and its tickets in one request, plus one per further 100 comments on the epic.
func (*Client) InspectTicket ¶
InspectTicket reads a ticket with everything an agent needs to work on it.
func (*Client) InspectTickets ¶
InspectTickets reads tickets in the order given, each repeated number once, in one request plus one per further 100 comments on a ticket.
func (*Client) ListTickets ¶
ListTickets returns matching tickets, oldest first, and how many tickets match in all, which exceeds the tickets returned when Limit cuts the list. GitHub counts what it filters on the first page. A client-side filter has no such count, so it reads every page whatever the limit. A repository's list includes its components' tickets. Ready tickets come most urgent first, then within a priority the tickets of an epic with a ticket in Doing, then oldest first, so that the next claim takes the most urgent work and finishes a started epic.
func (*Client) MoveTicket ¶
MoveTicket reassigns a ticket to another project and keeps its status.
func (*Client) ProjectIn ¶
ProjectIn maps a repository, and the working directory's place in its checkout, to a project without calling GitHub unless refresh is set and the cached metadata has no match. The deepest component holding the directory wins.
func (*Client) ProjectName ¶
ProjectName is the name a repository is registered under: its short name when the tracker's owner owns it, and owner/name for any other owner, so that repositories of the same name under different owners can both be projects.
func (*Client) ProjectRepo ¶
ProjectRepo returns the repository registered under a project name from the cached IDs, which it reads from GitHub only when there is no cache.
func (*Client) ProjectSummary ¶
ProjectSummary counts a project's tickets. A repository's counts include its components' tickets.
func (*Client) PromoteEpic ¶
PromoteEpic makes a ticket an epic. Its sub-issues become the epic's tickets, so none of them may be an epic, and the ticket may not belong to another ticket, because epics do not nest.
func (*Client) PruneAttachments ¶
PruneAttachments lists the assets of the attachments release that their ticket no longer links to, and deletes them when remove is set. A failed write after an upload, or an edit that drops a link, leaves such an asset. Assets whose names this tool did not write are left alone.
func (*Client) PullAttachments ¶
PullAttachments downloads a ticket's attachments into dir and returns their paths.
func (*Client) ReleaseTicket ¶
ReleaseTicket gives up a claim and returns the ticket to Todo.
func (*Client) RemoveAttachments ¶
func (c *Client) RemoveAttachments(ctx context.Context, number int, files []string) ([]string, error)
RemoveAttachments deletes a ticket's files from the attachments release, then marks their links in its body and comments as removed. Deleting comes first, because removing a leaked secret matters more than tidy text. It takes asset names or links.
func (*Client) RemoveFromEpic ¶
RemoveFromEpic detaches tickets from an epic. Every ticket must belong to it.
func (*Client) RemoveLabels ¶
RemoveLabels removes labels from a ticket, one request per label.
func (*Client) RemoveProject ¶
RemoveProject unregisters a project with no open tickets and marks its label removed, so closed tickets keep their label and only this repository can take it back. A repository also loses its board, so closed tickets that were only on the board get the label first, or they would lose their project with it. A repository with components keeps them until they are removed, because they use its board.
func (*Client) ReopenTicket ¶
ReopenTicket reopens a closed ticket with status Todo.
func (*Client) ResolveProject ¶
ResolveProject looks up a registered project by name.
func (*Client) ScanRepos ¶
ScanRepos reports every unarchived, non-fork repository of the tracker's owner with open issues. The owner's text is always trusted; authors adds more logins.
func (*Client) SetBlockers ¶
SetRelations adds or removes blockers of a ticket.
func (*Client) SetStatus ¶
SetStatus moves an unclaimed ticket to Todo or Done. Doing belongs to claims.
func (*Client) ShowHandoff ¶
ShowHandoff reads a project's open handoff, or reports ErrNoHandoff.
func (*Client) SyncDescriptions ¶
func (c *Client) SyncDescriptions(ctx context.Context, projects []Project) (DescriptionResult, error)
SyncDescriptions sets each project's board description from its repository. A component shares its repository's board, so it syncs that board. It reads every board and repository in one request per 50 boards and writes only the boards whose description differs, in one request per 50.
func (*Client) TakeHandoff ¶
TakeHandoff picks up a project's open handoff: it claims the ticket through the atomic claim ref, so one of two agents wins, then closes it as completed and frees the slot. It reports whether the branch still contains the commit. Once the handoff is closed, an error comes back with the handoff, so its contents are never lost.
func (*Client) UntakeHandoff ¶
UntakeHandoff gives back a handoff that take closed, so the next agent can take it again. It takes the project's slot first, so it fails before writing anything when the project already holds another open handoff. It then deletes any claim that take left behind, and reopens the ticket in Todo, posting reason as a comment. When either step fails, it frees the slot again.
type CloseOptions ¶
CloseOptions gives the evidence for closing a ticket: merged pull requests, a pull request whose head landed without GitHub marking it merged, or a reason. Comment, when set, is posted with the close.
type Comment ¶
type Comment struct {
Author string
CreatedAt time.Time
Body string
// contains filtered or unexported fields
}
Comment is one comment on a ticket.
type CreateOptions ¶
type CreateOptions struct {
Project string
Title string
Body string
DiscoveredFrom int
// Epic is the epic the ticket belongs to, or zero.
Epic int
BlockedBy []int
Blocking []int
Labels []string
Attachments []string
// contains filtered or unexported fields
}
CreateOptions describes a new ticket.
type DescriptionResult ¶
DescriptionResult reports a description sync. Problems name the boards that were left unchanged and why; the other boards are synced regardless.
type EditOptions ¶
EditOptions holds ticket fields to change. Nil fields stay unchanged.
type EpicDetail ¶
type EpicDetail struct {
TicketDetail
Tickets []Ticket
}
EpicDetail is an epic with everything about it and its tickets, each routed to its project with its board status.
func (EpicDetail) Done ¶
func (d EpicDetail) Done() int
Done counts the epic's closed tickets, closed for any reason.
type EpicOptions ¶
type EpicOptions struct {
Project string
Title string
Body string
Add []int
BlockedBy []int
Labels []string
Attachments []string
}
EpicOptions describes a new epic. Add holds existing tickets that become its tickets.
type Handoff ¶
Handoff is a ticket that hands work to the next agent: where the work stopped and what it needs.
type HandoffOptions ¶
type HandoffOptions struct {
Project string
Title string
Text string
Branch string
SHA string
Related int
}
HandoffOptions describe a handoff to create. Related is a ticket the work belongs to, or zero.
type ImportOptions ¶
type ImportOptions struct {
Repo Repo
Authors []string
DryRun bool
Limit int
// OnMove reports each transfer as it finishes, because a run can take an hour.
OnMove func(source, ticket int) error
}
ImportOptions describes moving a repository's open issues into the tracker.
type ImportResult ¶
ImportResult counts a run. Remaining is what a later run would still move.
type ListOptions ¶
type ListOptions struct {
Project string
Unrouted bool
State string
Status string
Label string
Priority string
Search string
Ready bool
Closable bool
Epic bool
Handoff bool
Stale bool
StaleDays int
Limit int
Now time.Time
// Tally, when set, counts every ticket the listing reads, before filtering.
Tally *Tally
// contains filtered or unexported fields
}
ListOptions filters tickets. Project is empty for all projects. Unrouted lists only tickets with no project, and excludes Project.
type Options ¶
type Options struct {
Repo Repo
CacheDir string
RequirePrivate bool
Transport http.RoundTripper
Token string
// Account is a login in gh's keyring to use instead of the active one, or
// GH_TOKEN. Empty keeps gh's own choice.
Account string
}
Options configures a Client. Transport and Token exist for tests; zero values use the live GitHub configuration.
type Project ¶
type Project struct {
Name string `json:"name"`
Repo string `json:"repo"`
Path string `json:"path,omitempty"`
Public bool `json:"public"`
LabelID string `json:"label_id"`
BoardID string `json:"board_id,omitempty"`
BoardURL string `json:"board_url,omitempty"`
StatusFieldID string `json:"status_field_id,omitempty"`
StatusOptions map[string]string `json:"status_options,omitempty"`
// ComponentFieldID and ComponentOptions are the board's Component field and its
// option IDs by component name, empty until a component is registered.
ComponentFieldID string `json:"component_field_id,omitempty"`
ComponentOptions map[string]string `json:"component_options,omitempty"`
}
Project is a code repository registered with the tracker, or a component: one directory of a registered repository with its own label on the repository's board.
func (Project) Component ¶
Component reports a project registered for one directory of its repository.
type ProjectSummary ¶
ProjectSummary describes a project and its ticket counts.
type Repo ¶
Repo identifies a GitHub repository.
func CurrentRepo ¶
CurrentRepo returns the working directory's github.com repository, or why it has none: no git checkout, no remote on a known GitHub host, or a repository on another host.
type RepoScan ¶
RepoScan counts one repository's open issues by who wrote them. It holds no issue text, because public issues are untrusted input. Others counts issues with text from anyone untrusted, including in a private repository where they can move.
type TakenHandoff ¶
TakenHandoff is a handoff that was picked up. Moved reports that its branch no longer contains its commit; Unchecked holds why that could not be checked.
type Tally ¶
type Tally struct {
Open map[string]int
Closed int
OpenRead bool
ClosedRead bool
Handoffs []Ticket
}
Tally counts the tickets a listing read before filtering them: open tickets by board status, and closed tickets. OpenRead and ClosedRead report that the listing read every ticket in that state, which needs no search text and a read to the end. Handoffs holds the open handoffs it read.
type Ticket ¶
type Ticket struct {
ID string
Number int
Title string
State string
URL string
Project string
Labels []string
Status string
Parent int
ParentEpic bool
Blockers []int
ParentBlocked bool
SubIssues int
OpenSubIssues int
Activity time.Time
// contains filtered or unexported fields
}
Ticket is one issue in the tracker.
func (Ticket) Closable ¶
Closable reports an open epic whose tickets are all closed. A claimed epic stays open, because closing it would take the ticket from whoever holds it, and so does a blocked one, because something still has to happen first.
func (Ticket) Epic ¶
Epic reports a ticket that groups other tickets. Agents claim its tickets, never the epic itself.
func (Ticket) Handoff ¶
Handoff reports a ticket that hands work to the next agent. It is picked up with handoff take, not claimed as ready work.
func (Ticket) OtherLabels ¶
OtherLabels are the ticket's labels without its priority labels, which lists show in a column of their own.
func (Ticket) Priority ¶
Priority is the most urgent of the ticket's priorities, such as P1, or empty when it has none. A ticket with several counts as its most urgent one.
func (Ticket) PriorityConflicts ¶
PriorityConflicts lists the ticket's priorities when it has more than one, most urgent first, and nothing otherwise.
func (Ticket) Ready ¶
Ready reports whether a ticket can be picked up: routed to a project, open, unblocked, with no blocked ancestor and no open sub-issues, not in progress, and neither a handoff nor an epic. An unrouted ticket waits for someone to give it a project. A parent waits for its children, so the work gets claimed rather than its container, and an epic is a container even before it has tickets. The blocked label covers waits with no ticket to name, such as a person's input.