classify

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package classify provides pure, stateless classification of strings into one of four link kinds: a bare Jira issue key, a Jira issue URL, a GitHub pull request URL, or an unclassified external link.

It is a public leaf package: it imports nothing from the gojira module and has no I/O. Any package in the module (or any third-party Go program) may import it without pulling in crawl semantics, network code, or filesystem operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind identifies the classification of a string passed to Classify.

const (
	// KindJiraKey means the input is a bare Jira issue key such as "EXAMPLE-1".
	// The key matches [A-Z][A-Z0-9]+-[0-9]+ and is the whole input string.
	KindJiraKey Kind = iota

	// KindJiraURL means the input is a URL whose host matches the configured
	// Jira site and whose path is /browse/<KEY> for a valid issue key.
	KindJiraURL

	// KindGitHubPR means the input is a GitHub pull request URL of the form
	// https://github.com/<owner>/<repo>/pull/<N>.
	KindGitHubPR

	// KindExternal means the input did not match any of the above patterns.
	// It may be any other URL or an unrecognised string.
	KindExternal
)

func (Kind) String

func (k Kind) String() string

String returns a human-readable label for the Kind, useful for debugging and logging.

type Result

type Result struct {
	Kind Kind

	// IssueKey is the Jira issue key (e.g. "EXAMPLE-1").
	// Set for KindJiraKey and KindJiraURL.
	IssueKey string

	// URL is the raw input string when it was recognised as a URL.
	// Set for KindJiraURL, KindGitHubPR, and KindExternal (when parseable).
	URL string

	// Owner is the GitHub repository owner.
	// Set for KindGitHubPR.
	Owner string

	// Repo is the GitHub repository name.
	// Set for KindGitHubPR.
	Repo string

	// PRNumber is the pull request number.
	// Set for KindGitHubPR.
	PRNumber int
}

Result holds the outcome of a Classify call.

Fields that are not applicable to the returned Kind are left at their zero values (empty string / 0).

  • KindJiraKey: IssueKey is set.
  • KindJiraURL: IssueKey and URL are set.
  • KindGitHubPR: Owner, Repo, PRNumber, and URL are set.
  • KindExternal: URL is set when the input parses as a URL; otherwise URL is empty.

func Classify

func Classify(input string, jiraSite string) Result

Classify determines the kind of link represented by input.

jiraSite is the base URL of the configured Jira Cloud site, for example "https://mycompany.atlassian.net". Only the host portion is used for matching; the scheme and path are ignored. An empty or unparseable jiraSite means no input will be classified as KindJiraURL.

Classification rules, applied in order:

  1. If input matches the bare issue-key pattern ([A-Z][A-Z0-9]+-[0-9]+, whole string), return KindJiraKey.
  2. If input parses as a URL whose host equals the jiraSite host (case-insensitive) and whose path is /browse/<KEY> for a valid key, return KindJiraURL.
  3. If input parses as a URL with host "github.com" (case-insensitive) and path /owner/repo/pull/N, return KindGitHubPR.
  4. Otherwise return KindExternal. URL is filled when the input parses as a URL; otherwise URL is empty.

Jump to

Keyboard shortcuts

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