-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jira.ts
51 lines (44 loc) · 1.45 KB
/
jira.ts
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
const root = "https://jira.sil.org";
const apiRoot = `${root}/rest/api/2`;
const jiraPersonalAccessToken = Deno.env.get("JIRA_ACCESS_TOKEN");
if (jiraPersonalAccessToken == null) {
console.warn("JIRA_ACCESS_TOKEN not set, Jira functions will not work");
}
export function getLinkForJiraIssue(issueKey: string): string {
return `${root}/browse/${issueKey}`;
}
export type JiraIssueInfo = {
key: string;
summary: string;
iconUrl: string;
resolution: string;
};
export async function getJiraIssueInfos(
keys: string[]
): Promise<JiraIssueInfo[]> {
if (keys.length === 0) {
// Jira API doesn't like empty searches
return Promise.resolve([]);
}
const searchUrl = `${apiRoot}/search?jql=${encodedJiraIssueSearch(
keys
)}&fields=summary,issuetype,resolution`;
const response = await fetch(searchUrl, {
headers: { Authorization: `Bearer ${jiraPersonalAccessToken}` },
});
const json = await response.json();
return json.issues.map((issue: any) => ({
key: issue.key,
summary: issue.fields.summary,
iconUrl: issue.fields.issuetype.iconUrl,
resolution: issue.fields.resolution?.name ?? "Unresolved",
}));
}
export function searchLinkForIssueKeys(keys: string[]): string {
const encodedSearch = encodedJiraIssueSearch(keys);
return `${root}/issues/?jql=${encodedSearch}`;
}
function encodedJiraIssueSearch(keys: string[]): string {
const search = `key in (${keys.join(",")})`;
return encodeURIComponent(search);
}