//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})`,
}))
}
/**
* Delete Project
* Delete a project. By default it goes to the Jira recycle bin, where an admin can restore it; set `permanent` to delete it outright. Requires the Administer Jira permission.
*/
export async function main(
auth: RT.Jira,
project_id: DynSelect_project_id,
permanent: boolean | undefined
) {
const url = new URL(
`https://${auth.domain}.atlassian.net/rest/api/3/project/${project_id}`
)
url.searchParams.append("enableUndo", permanent ? "false" : "true")
const response = await fetch(url, {
method: "DELETE",
headers: {
Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
if (response.status === 204) return { success: true }
return await response.json()
}
Submitted by hugo989 8 days ago