//native
async function get(auth: RT.Jira, path: string) {
const response = await fetch(`https://${auth.domain}.atlassian.net${path}`, {
headers: {
Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
export type DynSelect_project_id = string
// Resolver: the site's projects (first 100).
export async function project_id(auth: RT.Jira) {
const { values } = await get(
auth,
"/rest/api/3/project/search?maxResults=100"
)
return values.map((p: { id: string; key: string; name: string }) => ({
value: p.id,
label: `${p.name} (${p.key})`,
}))
}
/**
* Create Version
* Create a version (release) in a project. Dates are `yyyy-mm-dd`.
*/
export async function main(
auth: RT.Jira,
project_id: DynSelect_project_id,
name: string,
description: string | undefined,
start_date: string | undefined,
release_date: string | undefined,
archived: boolean | undefined
) {
const url = new URL(`https://${auth.domain}.atlassian.net/rest/api/3/version`)
const body: { [key: string]: any } = { projectId: Number(project_id), name }
if (description != null && description !== "") {
body.description = description
}
if (start_date != null && start_date !== "") {
body.startDate = start_date
}
if (release_date != null && release_date !== "") {
body.releaseDate = release_date
}
if (archived) {
body.archived = true
}
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 14 days ago