1 | type Jira = { |
2 | username: string; |
3 | password: string; |
4 | domain: string; |
5 | }; |
6 | |
7 | * Get projects paginated |
8 | * Returns a [paginated](#pagination) list of projects visible to the user. |
9 | */ |
10 | export async function main( |
11 | auth: Jira, |
12 | startAt: string | undefined, |
13 | maxResults: string | undefined, |
14 | orderBy: |
15 | | "category" |
16 | | "-category" |
17 | | "+category" |
18 | | "key" |
19 | | "-key" |
20 | | "+key" |
21 | | "name" |
22 | | "-name" |
23 | | "+name" |
24 | | "owner" |
25 | | "-owner" |
26 | | "+owner" |
27 | | "issueCount" |
28 | | "-issueCount" |
29 | | "+issueCount" |
30 | | "lastIssueUpdatedDate" |
31 | | "-lastIssueUpdatedDate" |
32 | | "+lastIssueUpdatedDate" |
33 | | "archivedDate" |
34 | | "+archivedDate" |
35 | | "-archivedDate" |
36 | | "deletedDate" |
37 | | "+deletedDate" |
38 | | "-deletedDate" |
39 | | undefined, |
40 | id: string | undefined, |
41 | keys: string | undefined, |
42 | query: string | undefined, |
43 | typeKey: string | undefined, |
44 | categoryId: string | undefined, |
45 | action: "view" | "browse" | "edit" | "create" | undefined, |
46 | expand: string | undefined, |
47 | status: string | undefined, |
48 | properties: string | undefined, |
49 | propertyQuery: string | undefined |
50 | ) { |
51 | const url = new URL( |
52 | `https://${auth.domain}.atlassian.net/rest/api/2/project/search` |
53 | ); |
54 | for (const [k, v] of [ |
55 | ["startAt", startAt], |
56 | ["maxResults", maxResults], |
57 | ["orderBy", orderBy], |
58 | ["id", id], |
59 | ["keys", keys], |
60 | ["query", query], |
61 | ["typeKey", typeKey], |
62 | ["categoryId", categoryId], |
63 | ["action", action], |
64 | ["expand", expand], |
65 | ["status", status], |
66 | ["properties", properties], |
67 | ["propertyQuery", propertyQuery], |
68 | ]) { |
69 | if (v !== undefined && v !== "") { |
70 | url.searchParams.append(k, v); |
71 | } |
72 | } |
73 | const response = await fetch(url, { |
74 | method: "GET", |
75 | headers: { |
76 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
77 | }, |
78 | body: undefined, |
79 | }); |
80 | if (!response.ok) { |
81 | const text = await response.text(); |
82 | throw new Error(`${response.status} ${text}`); |
83 | } |
84 | return await response.json(); |
85 | } |
86 |
|