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