1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Find users for picker |
8 | * Returns a list of users whose attributes match the query term. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | query: string | undefined, |
13 | maxResults: string | undefined, |
14 | showAvatar: string | undefined, |
15 | exclude: string | undefined, |
16 | excludeAccountIds: string | undefined, |
17 | avatarSize: string | undefined, |
18 | excludeConnectUsers: string | undefined |
19 | ) { |
20 | const url = new URL( |
21 | `https://${auth.domain}.atlassian.net/rest/api/2/user/picker` |
22 | ); |
23 | for (const [k, v] of [ |
24 | ["query", query], |
25 | ["maxResults", maxResults], |
26 | ["showAvatar", showAvatar], |
27 | ["exclude", exclude], |
28 | ["excludeAccountIds", excludeAccountIds], |
29 | ["avatarSize", avatarSize], |
30 | ["excludeConnectUsers", excludeConnectUsers], |
31 | ]) { |
32 | if (v !== undefined && v !== "") { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "GET", |
38 | headers: { |
39 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
40 | }, |
41 | body: undefined, |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|