1 | |
2 |
|
3 | |
4 | * Search Issues with JQL |
5 | * Search issues with a JQL query, e.g. `project = PROJ AND status = "In Progress" ORDER BY created DESC`. The query must be bounded (name a project, assignee, date range...). Returns `*navigable` fields unless `fields` says otherwise; when the response has a `nextPageToken`, pass it back to get the next page. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Jira, |
9 | jql: string, |
10 | fields: string[] | undefined, |
11 | expand: string | undefined, |
12 | max_results: number | undefined, |
13 | next_page_token: string | undefined |
14 | ) { |
15 | const url = new URL( |
16 | `https://${auth.domain}.atlassian.net/rest/api/3/search/jql` |
17 | ) |
18 |
|
19 | const body: { [key: string]: any } = { |
20 | jql, |
21 | fields: fields?.length ? fields : ["*navigable"], |
22 | } |
23 | if (expand != null && expand !== "") { |
24 | body.expand = expand |
25 | } |
26 | if (max_results != null) { |
27 | body.maxResults = max_results |
28 | } |
29 | if (next_page_token != null && next_page_token !== "") { |
30 | body.nextPageToken = next_page_token |
31 | } |
32 |
|
33 | const response = await fetch(url, { |
34 | method: "POST", |
35 | headers: { |
36 | Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`, |
37 | "Content-Type": "application/json", |
38 | Accept: "application/json", |
39 | }, |
40 | body: JSON.stringify(body), |
41 | }) |
42 |
|
43 | if (!response.ok) { |
44 | throw new Error(`${response.status} ${await response.text()}`) |
45 | } |
46 |
|
47 | return await response.json() |
48 | } |
49 |
|