1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Label |
7 | * Update a label by ID. |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | name: string | undefined, |
13 | color: |
14 | | "yellow" |
15 | | "purple" |
16 | | "blue" |
17 | | "red" |
18 | | "green" |
19 | | "orange" |
20 | | "black" |
21 | | "sky" |
22 | | "pink" |
23 | | "lime" |
24 | | undefined |
25 | ) { |
26 | const url = new URL(`https://api.trello.com/1/labels/${id}`); |
27 | for (const [k, v] of [ |
28 | ["name", name], |
29 | ["color", color], |
30 | ["key", auth.key], |
31 | ["token", auth.token], |
32 | ]) { |
33 | if (v !== undefined && v !== "") { |
34 | url.searchParams.append(k, v); |
35 | } |
36 | } |
37 | const response = await fetch(url, { |
38 | method: "PUT", |
39 | headers: { |
40 | Authorization: undefined, |
41 | }, |
42 | body: undefined, |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.text(); |
49 | } |
50 |
|