Documentation
¶
Overview ¶
Package search finds the external references a person types into a search box: Jira-style issues, pull requests and commits of a GitHub, GitLab or Azure DevOps repository. Classify detects what the text names (an issue key, a commit SHA, a pull request number or URL, a commit URL); each Source looks the detected references up live and matches the rest as free text; Search runs the sources a caller may see and ranks the hits.
Index ¶
- Variables
- func IsIssueKey(text string) bool
- func JiraLookup(client *jira.Client) func(ctx context.Context, key string) (Hit, error)
- func Matches(text string, values ...string) bool
- type CommitSource
- type Hit
- type IssueSource
- type Kind
- type Options
- type PullRequestSource
- type Query
- type Ref
- type RefKind
- type Repository
- type Result
- type Source
- type SourceResult
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("not supported by this provider")
ErrUnsupported is a source's error when its provider cannot answer the kind at all (pull requests on a plain git remote): the source is reported as skipped, not failed.
var Kinds = []Kind{KindIssue, KindPullRequest, KindCommit}
Kinds are every kind, in the order results are grouped.
var NotIssueKeyProjects = []string{"UTF", "ISO", "SHA", "MD", "CP", "WINDOWS", "RFC", "HTTP", "TLS", "SSL", "AES", "RSA", "X"}
NotIssueKeyProjects are "projects" that match the key grammar but are encodings, hashes or standards (UTF-8, SHA-256, ...); text naming one is not an issue key. Kept equal to gavel's externalissues list.
Functions ¶
func IsIssueKey ¶
IsIssueKey reports whether text is exactly one Jira-style issue key (PROJECT-123, any case) of a project that is not in NotIssueKeyProjects.
func JiraLookup ¶
JiraLookup reads an issue straight from Jira for a host with no cache of its own: its summary, status and status category (todo, in_progress, done), and its browse URL.
Types ¶
type CommitSource ¶
type CommitSource struct {
Repository
Scan int
}
CommitSource searches the history of a repository's Ref in the cached mirror: a SHA, or a commit URL of this repository, matches the commits whose SHA starts with it (a full SHA off the branch is read directly); any text is matched against the subject and body of the newest Scan commits (default 500).
func (CommitSource) Kind ¶
func (CommitSource) Kind() Kind
func (CommitSource) Name ¶
func (s CommitSource) Name() string
type Hit ¶
type Hit struct {
Kind Kind `json:"kind"`
Source string `json:"source"`
ID string `json:"id"`
Title string `json:"title,omitempty"`
Status string `json:"status,omitempty"`
StatusCategory string `json:"statusCategory,omitempty"`
Author string `json:"author,omitempty"`
Date *time.Time `json:"date,omitempty"`
URL string `json:"url,omitempty"`
Repository string `json:"repository,omitempty"`
Number int `json:"number,omitempty"`
SHA string `json:"sha,omitempty"`
Base string `json:"base,omitempty"`
Head string `json:"head,omitempty"`
Known bool `json:"known,omitempty"`
Live bool `json:"live,omitempty"`
Error string `json:"error,omitempty"`
// Labels are what the host attached to the hit's source (e.g. the connection a repository was opened from), so
// it can link the hit into its own pages.
Labels map[string]string `json:"labels,omitempty"`
}
Hit is one thing a source found. ID is how it is written (an issue key, #12, a short SHA). Known marks a hit the host already knew about (an issue its specs cite); Live a hit read from the provider because the text named it exactly. A live lookup that failed is kept as a hit carrying its Error.
type IssueSource ¶
type IssueSource struct {
SourceName string
Known func(ctx context.Context) ([]Hit, error)
Lookup func(ctx context.Context, key string) (Hit, error)
}
IssueSource searches Jira-style issues. Known lists the issues the host already knows (with their cached titles), matched as free text by key and title; Lookup reads one key live and runs when the text is an issue key, so an issue nobody knows is still found. Either may be nil, not both.
func (IssueSource) Kind ¶
func (IssueSource) Kind() Kind
func (IssueSource) Name ¶
func (s IssueSource) Name() string
type Kind ¶
type Kind string
Kind is the kind of thing a hit is, and what a caller filters and authorizes by.
type Options ¶
type Options struct {
Text string
Kinds []Kind
Limit int
Authorize func(context.Context, Kind) error
}
Options are one search. Kinds limits the kinds searched (nil = all). Authorize, when set, is asked once per kind; a refused kind is skipped with the refusal as the reason. Limit caps each kind's hits (<= 0 means 20).
type PullRequestSource ¶
type PullRequestSource struct {
Repository
ListLimit int
}
PullRequestSource searches a repository's pull requests through its provider: a pull request number, or a pull request URL of this repository, is read live; any text is matched against the titles of up to ListLimit open pull requests (default 100). A plain git remote has no pull requests and is skipped.
func (PullRequestSource) Kind ¶
func (PullRequestSource) Kind() Kind
func (PullRequestSource) Name ¶
func (s PullRequestSource) Name() string
type Query ¶
Query is what a source is asked: the text, the references Classify detected in it, and how many hits to keep.
type Ref ¶
Ref is one reference Classify detected. Value is the normalised key (upper case), SHA (lower case) or pull request number; Repo is the repository a URL names, nil otherwise.
type Repository ¶
type Repository struct {
Name string
Repository *git.Repository
Cache *git.Cache
Ref string
Labels map[string]string
}
Repository is one repository to search: Ref is the branch whose history commits are matched in (empty is the remote HEAD), Name labels its sources (default the repository's host and full name), Labels are copied onto every hit.
type Result ¶
type Result struct {
Hits []Hit `json:"hits"`
Sources []SourceResult `json:"sources"`
}
Result is a search's hits, grouped by kind in Kinds order, and every source's outcome.
func Search ¶
Search classifies the text once, runs every source of an admitted kind concurrently, and ranks each kind's hits: live lookups first, then exact ID, ID prefix, ID or title substring, anything else a source kept, ties by ID. A source's failure is recorded on its SourceResult and never fails the others; text under two characters searches nothing.
type Source ¶
type Source interface {
Name() string
Kind() Kind
Search(ctx context.Context, query Query) ([]Hit, error)
}
Source searches one kind of thing in one place.
type SourceResult ¶
type SourceResult struct {
Name string `json:"name"`
Kind Kind `json:"kind"`
Hits int `json:"hits"`
Skipped string `json:"skipped,omitempty"`
Error string `json:"error,omitempty"`
}
SourceResult is how one source fared: Skipped says why it was not searched (filtered out, not authorized, not supported), Error why its search failed.