labels

package
v0.0.0-...-e4cf005 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Overview

Package labels classifies issues.

The categories it uses are stored in static/*-categories.yaml files, one file per project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Categories

func Categories(db storage.DB, project string, issueNumber int64) ([]string, bool)

Categories returns the list of categories in the db associated with the given issue. If there is no association, it returns nil, false.

Types

type Category

type Category struct {
	Name        string // internal unique name
	Label       string // issue tracker label
	Description string // should match issue tracker
	Extra       string // additional description, not in issue tracker
}

A Category is a classification for an issue.

func CategoriesForProject

func CategoriesForProject(project string) []Category

CategoriesForProject returns the categories used for the given project, or nil if there are none.

func IssueCategory

func IssueCategory(ctx context.Context, db storage.DB, cgen llm.ContentGenerator, iss *github.Issue) (_ Category, explanation string, err error)

IssueCategory returns the category chosen by the LLM for the issue, along with an explanation of why it was chosen. It uses the built-in list of categories for the issue's project.

If there are examples associated with the issue's project, they are added to the prompt. The first time this happens for each project, the issues are fetched from the db.

func IssueCategoryFromLists

func IssueCategoryFromLists(ctx context.Context, cgen llm.ContentGenerator, iss *github.Issue, cats []Category, exs []Example) (_ Category, explanation string, err error)

IssueCategoryFromLists is like IssueCategory, but uses the given lists of Categories and examples.

type Example

type Example struct {
	Title    string
	Body     string
	Category string
}

An Example is a GitHub issue along with its correct category.

type Labeler

type Labeler struct {
	// contains filtered or unexported fields
}

A Labeler labels GitHub issues. It uses the following database keys: - ["labels.Labeler"] for the action log. - ["labels.Categories", Project, Issue] to record the categories assigned to an issue.

func New

func New(lg *slog.Logger, db storage.DB, gh *github.Client, cgen llm.ContentGenerator, name string) *Labeler

New creates and returns a new Labeler. It logs to lg, stores state in db, manipulates GitHub issues using gh, and classifies issues using cgen.

For the purposes of storing its own state, it uses the given name. Future calls to New with the same name will use the same state.

Use the Labeler methods to configure the posting parameters (especially Labeler.EnableProject and Labeler.EnableLabels) before calling Labeler.Run.

func (*Labeler) EnableLabels

func (l *Labeler) EnableLabels()

EnableLabels enables the Labeler to label GitHub issues. If EnableLabels has not been called, Labeler.Run logs what it would post but does not post the messages. See also Labeler.EnableProject, which must also be called to set the projects being considered.

func (*Labeler) EnableProject

func (l *Labeler) EnableProject(project string)

EnableProject enables the Labeler to post on issues in the given GitHub project (for example "golang/go"). See also Labeler.EnableLabels, which must also be called to post anything to GitHub.

func (*Labeler) LabelIssue

func (l *Labeler) LabelIssue(ctx context.Context, project string, issue int64) error

LabelIssue labels a single issue.

It follows the same logic as Labeler.Run for a single issue, except that it does not rely on or modify the Labeler's watcher. This means that Labeler.LabelIssue can be called on any issue without affecting the starting point of future calls to Labeler.Run.

It requires that there be a database entry for the given issue.

func (*Labeler) Latest

func (l *Labeler) Latest() timed.DBTime

Latest returns the latest known DBTime marked old by the Poster's Watcher.

func (*Labeler) RequireApproval

func (l *Labeler) RequireApproval()

RequireApproval configures the Labeler to log actions that require approval.

func (*Labeler) Run

func (l *Labeler) Run(ctx context.Context) error

Run runs a single round of labeling to GitHub. It scans all open issues that have been created since the last call to Labeler.Run using a Labeler with the same name (see New). Run skips closed issues, and it also skips pull requests.

func (*Labeler) SetTimeLimit

func (l *Labeler) SetTimeLimit(t time.Time)

SetTimeLimit controls how old an issue can be for the Labeler to label it. Issues created before time t will be skipped. The default is not to post to issues that are more than 48 hours old at the time of the call to New.

func (*Labeler) SkipAuthor

func (l *Labeler) SkipAuthor(author string)

Jump to

Keyboard shortcuts

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