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