1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Search for dashboards |
8 | * Returns a [paginated](#pagination) list of dashboards. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | dashboardName: string | undefined, |
13 | accountId: string | undefined, |
14 | owner: string | undefined, |
15 | groupname: string | undefined, |
16 | groupId: string | undefined, |
17 | projectId: string | undefined, |
18 | orderBy: |
19 | | "description" |
20 | | "-description" |
21 | | "+description" |
22 | | "favorite_count" |
23 | | "-favorite_count" |
24 | | "+favorite_count" |
25 | | "id" |
26 | | "-id" |
27 | | "+id" |
28 | | "is_favorite" |
29 | | "-is_favorite" |
30 | | "+is_favorite" |
31 | | "name" |
32 | | "-name" |
33 | | "+name" |
34 | | "owner" |
35 | | "-owner" |
36 | | "+owner" |
37 | | undefined, |
38 | startAt: string | undefined, |
39 | maxResults: string | undefined, |
40 | status: "active" | "archived" | "deleted" | undefined, |
41 | expand: string | undefined |
42 | ) { |
43 | const url = new URL( |
44 | `https://${auth.domain}.atlassian.net/rest/api/2/dashboard/search` |
45 | ); |
46 | for (const [k, v] of [ |
47 | ["dashboardName", dashboardName], |
48 | ["accountId", accountId], |
49 | ["owner", owner], |
50 | ["groupname", groupname], |
51 | ["groupId", groupId], |
52 | ["projectId", projectId], |
53 | ["orderBy", orderBy], |
54 | ["startAt", startAt], |
55 | ["maxResults", maxResults], |
56 | ["status", status], |
57 | ["expand", expand], |
58 | ]) { |
59 | if (v !== undefined && v !== "") { |
60 | url.searchParams.append(k, v); |
61 | } |
62 | } |
63 | const response = await fetch(url, { |
64 | method: "GET", |
65 | headers: { |
66 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
67 | }, |
68 | body: undefined, |
69 | }); |
70 | if (!response.ok) { |
71 | const text = await response.text(); |
72 | throw new Error(`${response.status} ${text}`); |
73 | } |
74 | return await response.json(); |
75 | } |
76 |
|