search

package
v0.1.113 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 14 Imported by: ? 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 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

Constants

This section is empty.

Variables

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

Kinds are every kind, in the order results are grouped.

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

func IsIssueKey(text string) bool

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

func JiraLookup(client *jira.Client) func(ctx context.Context, key string) (Hit, error)

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.

func Matches

func Matches(text string, values ...string) bool

Matches reports whether any value holds text, case-insensitively: the free-text filter sources apply.

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

func (CommitSource) Search

func (s CommitSource) Search(ctx context.Context, query Query) ([]Hit, error)

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

func (IssueSource) Search

func (s IssueSource) Search(ctx context.Context, query Query) ([]Hit, error)

Search answers the live lookup first (Known when the host knows the key too; a failed read is the hit's Error), then every known issue whose key or title holds the text.

type Kind

type Kind string

Kind is the kind of thing a hit is, and what a caller filters and authorizes by.

const (
	KindIssue       Kind = "issue"
	KindPullRequest Kind = "pull-request"
	KindCommit      Kind = "commit"
)

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

func (PullRequestSource) Search

func (s PullRequestSource) Search(ctx context.Context, query Query) ([]Hit, error)

type Query

type Query struct {
	Text  string
	Refs  []Ref
	Limit int
}

Query is what a source is asked: the text, the references Classify detected in it, and how many hits to keep.

func (Query) Ref

func (q Query) Ref(kinds ...RefKind) (Ref, bool)

Ref returns the first detected reference of one of kinds.

type Ref

type Ref struct {
	Kind   RefKind
	Value  string
	Number int
	Repo   *git.RepoURL
}

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.

func Classify

func Classify(text string) []Ref

Classify detects the references text names: an issue key, a 7–40 character hex SHA, a pull request number (#12, !12, PR 12, PR#12), a pull request URL or a commit URL. Text naming none of them yields no refs and is matched as free text only.

type RefKind

type RefKind string

RefKind is what a piece of text was detected to name.

const (
	RefIssueKey       RefKind = "issue-key"
	RefSHA            RefKind = "sha"
	RefPullRequest    RefKind = "pull-request"
	RefPullRequestURL RefKind = "pull-request-url"
	RefCommitURL      RefKind = "commit-url"
)

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(ctx context.Context, sources []Source, options Options) Result

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.

func Failed

func Failed(name string, kind Kind, err error) Source

Failed is a source that could not be opened (a repository the host could not resolve): searching it fails with err, so the failure is reported on its SourceResult instead of hiding the source.

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.

Directories

Path Synopsis
Package httpapi serves search.Search over HTTP for a host to mount: GET ?q=&kind=&limit=.
Package httpapi serves search.Search over HTTP for a host to mount: GET ?q=&kind=&limit=.

Jump to

Keyboard shortcuts

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