Delete version

Deletes a project version.

Script jira Verified

by hugo697 ยท 11/2/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Delete version
8
 * Deletes a project version.
9
 */
10
export async function main(
11
  auth: Jira,
12
  id: string,
13
  moveFixIssuesTo: string | undefined,
14
  moveAffectedIssuesTo: string | undefined
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/api/2/version/${id}`
18
  );
19
  for (const [k, v] of [
20
    ["moveFixIssuesTo", moveFixIssuesTo],
21
    ["moveAffectedIssuesTo", moveAffectedIssuesTo],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "DELETE",
29
    headers: {
30
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.text();
39
}
40