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