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 )
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 ¶
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:
- If input matches the bare issue-key pattern ([A-Z][A-Z0-9]+-[0-9]+, whole string), return KindJiraKey.
- 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.
- If input parses as a URL with host "github.com" (case-insensitive) and path /owner/repo/pull/N, return KindGitHubPR.
- Otherwise return KindExternal. URL is filled when the input parses as a URL; otherwise URL is empty.