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) ClaimNext(ctx context.Context, project string) (Ticket, bool, error)
- func (c *Client) ClaimTicket(ctx context.Context, number int) (Ticket, error)
- func (c *Client) CloseParent(ctx context.Context, number int) (bool, error)
- func (c *Client) CloseTicket(ctx context.Context, number int, opts CloseOptions) error
- func (c *Client) CreateTicket(ctx context.Context, opts CreateOptions) (Ticket, error)
- func (c *Client) CurrentProject(ctx context.Context, refresh bool) (Project, 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) InspectTicket(ctx context.Context, number int) (TicketDetail, error)
- func (c *Client) InspectTickets(ctx context.Context, numbers []int) ([]TicketDetail, error)
- func (c *Client) ListSubIssues(ctx context.Context, number int) ([]SubIssue, 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) ProjectSummary(ctx context.Context, project Project) (ProjectSummary, error)
- func (c *Client) Projects(ctx context.Context) ([]Project, 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) 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) SetSubIssues(ctx context.Context, parent int, children []int, add bool) error
- type CloseOptions
- type Comment
- type CreateOptions
- type EditOptions
- type ImportOptions
- type ImportResult
- type ListOptions
- type Options
- type Project
- type ProjectSummary
- type Repo
- type RepoScan
- type SubIssue
- type Ticket
- 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 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 ¶ added in v1.2.0
type BoardAccessError struct {
Detail 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 ¶ added in v1.2.0
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 ¶ added in v1.4.0
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.
func (*Client) ClaimNext ¶
ClaimNext claims the oldest ready ticket, moving on when another agent wins a candidate. It reports false when no ticket is ready. Project may be empty.
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) CloseParent ¶ added in v1.2.0
CloseParent closes a parent as completed and reports whether it did. The list that found the parent can be out of date, so this decides from a fresh read.
func (*Client) CloseTicket ¶
CloseTicket closes a ticket after confirming every pull request merged.
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) CurrentProject ¶
CurrentProject maps the working directory's GitHub remote, and its directory in the checkout, to a project without calling GitHub unless refresh is set and the cached metadata has no match.
func (*Client) EditTicket ¶
EditTicket changes a ticket's title or body, and attaches files to the body.
func (*Client) ImportIssues ¶ added in v1.1.0
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) InspectTicket ¶
InspectTicket reads a ticket with everything an agent needs to work on it.
func (*Client) InspectTickets ¶ added in v1.4.0
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) ListSubIssues ¶ added in v1.2.0
ListSubIssues returns a ticket's sub-issues.
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.
func (*Client) MoveTicket ¶
MoveTicket reassigns a ticket to another project and keeps its status.
func (*Client) ProjectSummary ¶
ProjectSummary counts a project's tickets. A repository's counts include its components' tickets.
func (*Client) PruneAttachments ¶ added in v1.5.0
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 ¶ added in v1.5.0
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) RemoveLabels ¶
RemoveLabels removes labels from a ticket, one request per label.
func (*Client) RemoveProject ¶
RemoveProject unregisters a project with no open tickets and clears its label's registration, so closed tickets keep their label. 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 ¶ added in v1.1.0
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.
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.
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
Parent int
BlockedBy []int
Blocking []int
Labels []string
Attachments []string
}
CreateOptions describes a new ticket.
type EditOptions ¶
EditOptions holds ticket fields to change. Nil fields stay unchanged.
type ImportOptions ¶ added in v1.1.0
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 ¶ added in v1.1.0
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
Search string
Ready bool
Closable bool
Stale bool
StaleDays int
Limit int
Now time.Time
}
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
}
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 ¶ added in v1.4.0
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 repository.
type RepoScan ¶ added in v1.1.0
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 Ticket ¶
type Ticket struct {
ID string
Number int
Title string
State string
URL string
Project string
Labels []string
Status string
Parent int
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 ¶ added in v1.2.0
Closable reports an open parent whose sub-issues are all closed. A claimed parent 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) 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, and not in progress. 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. The blocked label covers waits with no ticket to name, such as a person's input.