tracker

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tracker manages projects and tickets held in one GitHub repository.

Index

Constants

View Source
const (
	ReasonCompleted  = "completed"
	ReasonNotPlanned = "not-planned"
	ReasonDuplicate  = "duplicate"
)

CloseReason values for closing a ticket without a pull request.

View Source
const (
	StatusTodo  = "Todo"
	StatusDoing = "Doing"
	StatusDone  = "Done"
)

Ticket statuses, which are the columns of every project board.

View Source
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.

View Source
const StateClosed = "CLOSED"

StateClosed is GitHub's state of a closed ticket.

Variables

View Source
var ErrAlreadyClaimed = errors.New("ticket is already claimed")

ErrAlreadyClaimed reports that another agent holds the claim.

View Source
var ErrNoHandoff = errors.New("no open handoff")

ErrNoHandoff reports that a project has no open handoff.

View Source
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
	// 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 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

func New(opts Options) (*Client, error)

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

func (c *Client) AddComment(ctx context.Context, number int, body string, files []string) error

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

func (c *Client) AddLabels(ctx context.Context, number int, labels []string) error

AddLabels adds labels to a ticket. GitHub creates a name it does not know yet.

func (*Client) AddProject

func (c *Client) AddProject(ctx context.Context, repo Repo) (Project, error)

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) ClaimNext

func (c *Client) ClaimNext(ctx context.Context, project string, tally *Tally) (Ticket, bool, error)

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

func (c *Client) ClaimTicket(ctx context.Context, number int) (Ticket, error)

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

func (c *Client) CloseParent(ctx context.Context, number int) (bool, error)

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

func (c *Client) CloseTicket(ctx context.Context, number int, opts CloseOptions) error

CloseTicket closes a ticket after confirming every pull request merged.

func (*Client) CreateHandoff added in v1.8.0

func (c *Client) CreateHandoff(ctx context.Context, opts HandoffOptions) (Handoff, error)

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

func (c *Client) CreateTicket(ctx context.Context, opts CreateOptions) (Ticket, error)

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) DropHandoff added in v1.8.0

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

func (c *Client) EditTicket(ctx context.Context, number int, opts EditOptions) error

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

func (c *Client) InspectTicket(ctx context.Context, number int) (TicketDetail, error)

InspectTicket reads a ticket with everything an agent needs to work on it.

func (*Client) InspectTickets added in v1.4.0

func (c *Client) InspectTickets(ctx context.Context, numbers []int) ([]TicketDetail, error)

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

func (c *Client) ListSubIssues(ctx context.Context, number int) ([]SubIssue, error)

ListSubIssues returns a ticket's sub-issues.

func (*Client) ListTickets

func (c *Client) ListTickets(ctx context.Context, opts ListOptions) ([]Ticket, int, error)

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 oldest first, so that the next claim takes the most urgent work.

func (*Client) MoveTicket

func (c *Client) MoveTicket(ctx context.Context, number int, target string) error

MoveTicket reassigns a ticket to another project and keeps its status.

func (*Client) ProjectIn added in v1.6.0

func (c *Client) ProjectIn(ctx context.Context, current Repo, refresh bool) (Project, bool, error)

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 added in v1.6.0

func (c *Client) ProjectName(repo Repo) string

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 added in v1.6.0

func (c *Client) ProjectRepo(ctx context.Context, name string) (string, bool, error)

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

func (c *Client) ProjectSummary(ctx context.Context, project Project) (ProjectSummary, error)

ProjectSummary counts a project's tickets. A repository's counts include its components' tickets.

func (*Client) Projects

func (c *Client) Projects(ctx context.Context) ([]Project, error)

Projects lists registered projects from GitHub.

func (*Client) PruneAttachments added in v1.5.0

func (c *Client) PruneAttachments(ctx context.Context, remove bool) ([]string, error)

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

func (c *Client) PullAttachments(ctx context.Context, number int, dir string) ([]string, error)

PullAttachments downloads a ticket's attachments into dir and returns their paths.

func (*Client) ReleaseTicket

func (c *Client) ReleaseTicket(ctx context.Context, number int) error

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

func (c *Client) RemoveLabels(ctx context.Context, number int, labels []string) error

RemoveLabels removes labels from a ticket, one request per label.

func (*Client) RemoveProject

func (c *Client) RemoveProject(ctx context.Context, name string) error

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

func (c *Client) ReopenTicket(ctx context.Context, number int) error

ReopenTicket reopens a closed ticket with status Todo.

func (*Client) Repo

func (c *Client) Repo() Repo

Repo returns the tracker repository.

func (*Client) ResolveProject

func (c *Client) ResolveProject(ctx context.Context, name string) (Project, error)

ResolveProject looks up a registered project by name.

func (*Client) ScanRepos added in v1.1.0

func (c *Client) ScanRepos(ctx context.Context, authors []string) ([]RepoScan, error)

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

func (c *Client) SetBlockers(ctx context.Context, number int, blockers []int, add bool) error

SetRelations adds or removes blockers of a ticket.

func (*Client) SetStatus

func (c *Client) SetStatus(ctx context.Context, number int, status string) error

SetStatus moves an unclaimed ticket to Todo or Done. Doing belongs to claims.

func (*Client) SetSubIssues

func (c *Client) SetSubIssues(ctx context.Context, parent int, children []int, add bool) error

SetSubIssues attaches or detaches sub-issues of a parent ticket.

func (*Client) ShowHandoff added in v1.8.0

func (c *Client) ShowHandoff(ctx context.Context, name string) (Handoff, error)

ShowHandoff reads a project's open handoff, or reports ErrNoHandoff.

func (*Client) SyncDescriptions added in v1.7.0

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 added in v1.8.0

func (c *Client) TakeHandoff(ctx context.Context, name string) (TakenHandoff, error)

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 added in v1.9.0

func (c *Client) UntakeHandoff(ctx context.Context, number int, reason string) (Handoff, error)

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

type CloseOptions struct {
	PRs      []string
	LandedPR string
	Reason   string
	Comment  string
}

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
	Parent         int
	BlockedBy      []int
	Blocking       []int
	Labels         []string
	Attachments    []string
	// contains filtered or unexported fields
}

CreateOptions describes a new ticket.

type DescriptionResult added in v1.7.0

type DescriptionResult struct {
	Boards   int
	Updated  []string
	Problems []string
}

DescriptionResult reports a description sync. Problems name the boards that were left unchanged and why; the other boards are synced regardless.

type EditOptions

type EditOptions struct {
	Title       *string
	Body        *string
	Attachments []string
}

EditOptions holds ticket fields to change. Nil fields stay unchanged.

type Handoff added in v1.8.0

type Handoff struct {
	Ticket  Ticket
	Branch  string
	SHA     string
	Related int
	Text    string
}

Handoff is a ticket that hands work to the next agent: where the work stopped and what it needs.

type HandoffOptions added in v1.8.0

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 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

type ImportResult struct {
	Moved     int
	Remaining int
	Skipped   int
}

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
	Handoff   bool
	Stale     bool
	StaleDays int
	Limit     int
	Now       time.Time
	// Tally, when set, counts every ticket the listing reads, before filtering.
	Tally *Tally
}

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 added in v1.4.0

func (p Project) Component() bool

Component reports a project registered for one directory of its repository.

func (Project) Label

func (p Project) Label() string

Label returns the routing label for the project.

func (Project) Root added in v1.4.0

func (p Project) Root() string

Root names the repository project whose board this project uses, which is the project itself unless it is a component.

type ProjectSummary

type ProjectSummary struct {
	Project Project
	Open    int
	Closed  int
}

ProjectSummary describes a project and its ticket counts.

type Repo

type Repo struct {
	Owner string
	Name  string
}

Repo identifies a GitHub repository.

func CurrentRepo

func CurrentRepo() (Repo, error)

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.

func ParseRepo

func ParseRepo(value string) (Repo, error)

ParseRepo reads an owner/name repository reference.

func (Repo) String

func (r Repo) String() string

type RepoScan added in v1.1.0

type RepoScan struct {
	Repo    string
	Private bool
	Open    int
	Movable int
	Others  int
}

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 SubIssue

type SubIssue struct {
	Number int
	Title  string
	State  string
}

SubIssue is a child ticket.

type TakenHandoff added in v1.8.0

type TakenHandoff struct {
	Handoff
	Moved     bool
	Unchecked error
}

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 added in v1.6.0

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
	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

func (t Ticket) Closable() bool

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) Created added in v1.8.0

func (t Ticket) Created() time.Time

Created is when the ticket was created.

func (Ticket) Handoff added in v1.8.0

func (t Ticket) Handoff() bool

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 added in v1.6.0

func (t Ticket) OtherLabels() []string

OtherLabels are the ticket's labels without its priority labels, which lists show in a column of their own.

func (Ticket) Priority added in v1.6.0

func (t Ticket) Priority() string

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 added in v1.6.0

func (t Ticket) PriorityConflicts() []string

PriorityConflicts lists the ticket's priorities when it has more than one, most urgent first, and nothing otherwise.

func (Ticket) Ready

func (t Ticket) Ready() bool

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 not a handoff. 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.

func (Ticket) Stale

func (t Ticket) Stale(days int, now time.Time) bool

Stale reports a Doing ticket with no activity for the given number of days.

type TicketDetail

type TicketDetail struct {
	Ticket
	Body        string
	Comments    []Comment
	Blocking    []int
	SubIssues   []SubIssue
	Attachments []string
	PublicRepo  bool
}

TicketDetail is a ticket with its text, relations, and attachment URLs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL