Delete worklog

Deletes a worklog from an issue.

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 worklog
8
 * Deletes a worklog from an issue.
9
 */
10
export async function main(
11
  auth: Jira,
12
  issueIdOrKey: string,
13
  id: string,
14
  notifyUsers: string | undefined,
15
  adjustEstimate: "new" | "leave" | "manual" | "auto" | undefined,
16
  newEstimate: string | undefined,
17
  increaseBy: string | undefined,
18
  overrideEditableFlag: string | undefined
19
) {
20
  const url = new URL(
21
    `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/worklog/${id}`
22
  );
23
  for (const [k, v] of [
24
    ["notifyUsers", notifyUsers],
25
    ["adjustEstimate", adjustEstimate],
26
    ["newEstimate", newEstimate],
27
    ["increaseBy", increaseBy],
28
    ["overrideEditableFlag", overrideEditableFlag],
29
  ]) {
30
    if (v !== undefined && v !== "") {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "DELETE",
36
    headers: {
37
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.text();
46
}
47