1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Update comment |
8 | * Updates a comment. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | issueIdOrKey: string, |
13 | id: string, |
14 | notifyUsers: string | undefined, |
15 | overrideEditableFlag: string | undefined, |
16 | expand: string | undefined, |
17 | body: { |
18 | author?: { |
19 | accountId?: string; |
20 | accountType?: string; |
21 | active?: boolean; |
22 | avatarUrls?: { |
23 | "16x16"?: string; |
24 | "24x24"?: string; |
25 | "32x32"?: string; |
26 | "48x48"?: string; |
27 | }; |
28 | displayName?: string; |
29 | emailAddress?: string; |
30 | key?: string; |
31 | name?: string; |
32 | self?: string; |
33 | timeZone?: string; |
34 | }; |
35 | body?: string; |
36 | created?: string; |
37 | id?: string; |
38 | jsdAuthorCanSeeRequest?: boolean; |
39 | jsdPublic?: boolean; |
40 | properties?: { key?: string; value?: { [k: string]: unknown } }[]; |
41 | renderedBody?: string; |
42 | self?: string; |
43 | updateAuthor?: { |
44 | accountId?: string; |
45 | accountType?: string; |
46 | active?: boolean; |
47 | avatarUrls?: { |
48 | "16x16"?: string; |
49 | "24x24"?: string; |
50 | "32x32"?: string; |
51 | "48x48"?: string; |
52 | }; |
53 | displayName?: string; |
54 | emailAddress?: string; |
55 | key?: string; |
56 | name?: string; |
57 | self?: string; |
58 | timeZone?: string; |
59 | }; |
60 | updated?: string; |
61 | visibility?: { |
62 | identifier?: string; |
63 | type?: "group" | "role"; |
64 | value?: string; |
65 | [k: string]: unknown; |
66 | }; |
67 | [k: string]: unknown; |
68 | } |
69 | ) { |
70 | const url = new URL( |
71 | `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/comment/${id}` |
72 | ); |
73 | for (const [k, v] of [ |
74 | ["notifyUsers", notifyUsers], |
75 | ["overrideEditableFlag", overrideEditableFlag], |
76 | ["expand", expand], |
77 | ]) { |
78 | if (v !== undefined && v !== "") { |
79 | url.searchParams.append(k, v); |
80 | } |
81 | } |
82 | const response = await fetch(url, { |
83 | method: "PUT", |
84 | headers: { |
85 | "Content-Type": "application/json", |
86 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
87 | }, |
88 | body: JSON.stringify(body), |
89 | }); |
90 | if (!response.ok) { |
91 | const text = await response.text(); |
92 | throw new Error(`${response.status} ${text}`); |
93 | } |
94 | return await response.json(); |
95 | } |
96 |
|