//native
/**
* Search Issues with JQL
* 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.
*/
export async function main(
auth: RT.Jira,
jql: string,
fields: string[] | undefined,
expand: string | undefined,
max_results: number | undefined,
next_page_token: string | undefined
) {
const url = new URL(
`https://${auth.domain}.atlassian.net/rest/api/3/search/jql`
)
const body: { [key: string]: any } = {
jql,
fields: fields?.length ? fields : ["*navigable"],
}
if (expand != null && expand !== "") {
body.expand = expand
}
if (max_results != null) {
body.maxResults = max_results
}
if (next_page_token != null && next_page_token !== "") {
body.nextPageToken = next_page_token
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(body),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 5 hours ago