-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathissue-identifier.ts
More file actions
65 lines (54 loc) · 1.52 KB
/
issue-identifier.ts
File metadata and controls
65 lines (54 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const LINEAR_IDENTIFIER_RE = /^([a-zA-Z0-9]+)-([1-9][0-9]*)$/
const LINEAR_IDENTIFIER_IN_TEXT_RE = /\b([a-zA-Z0-9]+)-([1-9][0-9]*)\b/
export interface ParsedIssueIdentifier {
identifier: string
teamKey: string
issueNumber: string
}
function buildParsedIssueIdentifier(
teamKey: string,
issueNumber: string,
): ParsedIssueIdentifier {
const normalizedTeamKey = teamKey.toUpperCase()
return {
identifier: `${normalizedTeamKey}-${issueNumber}`,
teamKey: normalizedTeamKey,
issueNumber,
}
}
export function parseIssueIdentifier(
value: string,
): ParsedIssueIdentifier | undefined {
const match = value.match(LINEAR_IDENTIFIER_RE)
if (!match) {
return undefined
}
const teamKey = match[1]
const issueNumber = match[2]
if (teamKey == null || issueNumber == null) {
return undefined
}
return buildParsedIssueIdentifier(teamKey, issueNumber)
}
export function findIssueIdentifierInText(
value: string,
): ParsedIssueIdentifier | undefined {
const match = value.match(LINEAR_IDENTIFIER_IN_TEXT_RE)
if (!match) {
return undefined
}
const teamKey = match[1]
const issueNumber = match[2]
if (teamKey == null || issueNumber == null) {
return undefined
}
return buildParsedIssueIdentifier(teamKey, issueNumber)
}
export function getTeamKeyFromIssueIdentifier(
value: string,
): string | undefined {
return parseIssueIdentifier(value)?.teamKey
}
export function normalizeIssueIdentifier(value: string): string | undefined {
return parseIssueIdentifier(value)?.identifier
}