tracker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 8 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 is the interface every issue tracker implements: Linear, Jira Cloud and Asana. A ticket there starts a session on a code repository, and the result is posted back to the ticket.

Everything a ticket holds (its title, description and comments) and every name on it is data written by people: the core puts it inside the untrusted fence, never into a model's instructions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadSignature is returned by ParseWebhook for a delivery whose
	// signature does not verify, or that is too old to be fresh.
	ErrBadSignature = errors.New("tracker: webhook signature does not verify")
	// ErrIgnored is returned by ParseWebhook for a delivery kōjō has no use
	// for: a heartbeat, an event type it does not handle, its own comment.
	ErrIgnored = errors.New("tracker: event ignored")
	// ErrNotFound is a ticket the tracker does not know, or that kōjō's
	// account cannot see.
	ErrNotFound = errors.New("tracker: not found")
)

Errors a tracker returns for the cases the core handles.

Functions

func SignHMAC

func SignHMAC(secret string, body []byte) string

SignHMAC is the hex HMAC-SHA256 of body under secret. Tests sign the deliveries they send with it.

func ValidHMAC

func ValidHMAC(secret string, body []byte, sig string) bool

ValidHMAC reports whether sig is the lowercase or uppercase hex HMAC-SHA256 of body under secret: how Linear, Jira and Asana sign their webhooks. The comparison takes the same time whatever sig holds.

Types

type Comment

type Comment struct {
	ID        string    `json:"id"`
	Author    Person    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
}

Comment is a comment on a ticket.

type Delivery

type Delivery struct {
	Events []Event
	// Reply holds headers to set on the answer (Asana's handshake echoes
	// X-Hook-Secret).
	Reply http.Header
}

Delivery is one verified webhook request: the events it carries, and the headers its answer must carry.

type Event

type Event struct {
	Kind     EventKind `json:"kind"`
	TicketID string    `json:"ticket_id"`
	// Actor is who assigned the ticket, added the label or wrote the
	// comment.
	Actor Person `json:"actor"`
	// CommentID, Text and URL are the comment of an EventMentioned.
	CommentID string `json:"comment_id,omitempty"`
	Text      string `json:"text,omitempty"`
	URL       string `json:"url,omitempty"`
	// Label is the label of an EventLabeled.
	Label string `json:"label,omitempty"`
	// DeliveryID names the change, so the same change delivered twice is
	// handled once.
	DeliveryID string `json:"delivery_id"`
}

Event is one change on a tracker that is addressed to kōjō.

type EventKind

type EventKind string

EventKind is what happened to a ticket.

const (
	// EventAssigned is a ticket assigned to kōjō's account, or created
	// with kōjō as its assignee.
	EventAssigned EventKind = "assigned"
	// EventMentioned is a comment that mentions kōjō's account. Text holds
	// the comment.
	EventMentioned EventKind = "mentioned"
	// EventLabeled is one of the labels kojo.yaml names (labels) added to
	// a ticket, or a ticket created with one.
	EventLabeled EventKind = "labeled"
)

Event kinds kōjō acts on.

type Person

type Person struct {
	// ID is the tracker's ID of the account.
	ID   string `json:"id"`
	Name string `json:"name,omitempty"`
	// Email is an address the adapter vouches for: the one kojo.yaml maps
	// the account to (users), or, on a tracker whose addresses are
	// verified (Linear), the one the tracker reports. Empty otherwise: the
	// person then has no role in kōjō, and their requests are read-only.
	Email string `json:"email,omitempty"`
}

Person is someone on the tracker.

type Stage

type Stage string

Stage is a point in a session's life a ticket's status can follow.

const (
	// StageStarted: a session that may change code was queued for the
	// ticket.
	StageStarted Stage = "started"
	// StageReview: the session opened a pull request.
	StageReview Stage = "review"
)

Stages a ticket can be moved at.

type Ticket

type Ticket struct {
	// Tracker is linear, jira or asana.
	Tracker string `json:"tracker"`
	// ID is the tracker's own ID.
	ID string `json:"id"`
	// Key is the ticket's key (ENG-123, PAY-7). Asana tasks have none.
	Key string `json:"key,omitempty"`
	URL string `json:"url,omitempty"`
	// Title, Description and the comments' bodies are what people wrote,
	// as Markdown or plain text.
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	// Team is the Linear team's key. Empty on the other trackers.
	Team string `json:"team,omitempty"`
	// Projects are the projects the ticket belongs to, as the repos
	// object names them (tickets): a Linear project's name and ID, the
	// Jira project's key, Asana project IDs.
	Projects []string `json:"projects,omitempty"`
	// Labels are its labels (Asana: tags).
	Labels []string `json:"labels,omitempty"`
	// Status is its workflow state (Asana: the section it is in).
	Status   string    `json:"status,omitempty"`
	Comments []Comment `json:"comments,omitempty"`
}

Ticket is an issue (Linear, Jira) or a task (Asana).

type Tracker

type Tracker interface {
	// Name is linear, jira or asana.
	Name() string
	// ParseWebhook verifies and decodes one webhook delivery. It returns
	// ErrBadSignature for a delivery that does not verify and ErrIgnored
	// for one with nothing for kōjō.
	ParseWebhook(r *http.Request, body []byte) (*Delivery, error)
	// GetTicket reads a ticket with its comments.
	GetTicket(ctx context.Context, id string) (*Ticket, error)
	// Comment posts text (Markdown) on a ticket, in the tracker's own
	// format, and returns the comment's URL when the tracker gives one.
	Comment(ctx context.Context, id, text string) (string, error)
	// Move sets a ticket's status to the one kojo.yaml names for stage
	// (status), and does nothing when it names none, which is the
	// default. A ticket already in that status is left as it is.
	Move(ctx context.Context, id string, stage Stage) error
	// Check verifies the credentials work. It is what kojo doctor runs.
	Check(ctx context.Context) error
}

Tracker is one configured issue tracker.

Directories

Path Synopsis
Package trackertest is an in-memory issue tracker for the core's tests, as forgetest is for forges.
Package trackertest is an in-memory issue tracker for the core's tests, as forgetest is for forges.

Jump to

Keyboard shortcuts

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