1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Update permission scheme |
8 | * Updates a permission scheme. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | schemeId: string, |
13 | expand: string | undefined, |
14 | body: { |
15 | description?: string; |
16 | expand?: string; |
17 | id?: number; |
18 | name: string; |
19 | permissions?: { |
20 | holder?: { |
21 | expand?: string; |
22 | parameter?: string; |
23 | type: string; |
24 | value?: string; |
25 | }; |
26 | id?: number; |
27 | permission?: string; |
28 | self?: string; |
29 | [k: string]: unknown; |
30 | }[]; |
31 | scope?: { |
32 | project?: { |
33 | avatarUrls?: { |
34 | "16x16"?: string; |
35 | "24x24"?: string; |
36 | "32x32"?: string; |
37 | "48x48"?: string; |
38 | }; |
39 | id?: string; |
40 | key?: string; |
41 | name?: string; |
42 | projectCategory?: { |
43 | description?: string; |
44 | id?: string; |
45 | name?: string; |
46 | self?: string; |
47 | }; |
48 | projectTypeKey?: "software" | "service_desk" | "business"; |
49 | self?: string; |
50 | simplified?: boolean; |
51 | }; |
52 | type?: "PROJECT" | "TEMPLATE"; |
53 | [k: string]: unknown; |
54 | }; |
55 | self?: string; |
56 | [k: string]: unknown; |
57 | } |
58 | ) { |
59 | const url = new URL( |
60 | `https://${auth.domain}.atlassian.net/rest/api/2/permissionscheme/${schemeId}` |
61 | ); |
62 | for (const [k, v] of [["expand", expand]]) { |
63 | if (v !== undefined && v !== "") { |
64 | url.searchParams.append(k, v); |
65 | } |
66 | } |
67 | const response = await fetch(url, { |
68 | method: "PUT", |
69 | headers: { |
70 | "Content-Type": "application/json", |
71 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
72 | }, |
73 | body: JSON.stringify(body), |
74 | }); |
75 | if (!response.ok) { |
76 | const text = await response.text(); |
77 | throw new Error(`${response.status} ${text}`); |
78 | } |
79 | return await response.json(); |
80 | } |
81 |
|