Assign issue

Assigns an issue to a user.

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
 * Assign issue
8
 * Assigns an issue to a user.
9
 */
10
export async function main(
11
  auth: Jira,
12
  issueIdOrKey: string,
13
  body: {
14
    accountId?: string;
15
    accountType?: "atlassian" | "app" | "customer" | "unknown";
16
    active?: boolean;
17
    applicationRoles?: {
18
      callback?: {};
19
      items?: {
20
        defaultGroups?: string[];
21
        defaultGroupsDetails?: {
22
          groupId?: string;
23
          name?: string;
24
          self?: string;
25
        }[];
26
        defined?: boolean;
27
        groupDetails?: { groupId?: string; name?: string; self?: string }[];
28
        groups?: string[];
29
        hasUnlimitedSeats?: boolean;
30
        key?: string;
31
        name?: string;
32
        numberOfSeats?: number;
33
        platform?: boolean;
34
        remainingSeats?: number;
35
        selectedByDefault?: boolean;
36
        userCount?: number;
37
        userCountDescription?: string;
38
      }[];
39
      "max-results"?: number;
40
      pagingCallback?: {};
41
      size?: number;
42
    };
43
    avatarUrls?: {
44
      "16x16"?: string;
45
      "24x24"?: string;
46
      "32x32"?: string;
47
      "48x48"?: string;
48
    };
49
    displayName?: string;
50
    emailAddress?: string;
51
    expand?: string;
52
    groups?: {
53
      callback?: {};
54
      items?: { groupId?: string; name?: string; self?: string }[];
55
      "max-results"?: number;
56
      pagingCallback?: {};
57
      size?: number;
58
    };
59
    key?: string;
60
    locale?: string;
61
    name?: string;
62
    self?: string;
63
    timeZone?: string;
64
  }
65
) {
66
  const url = new URL(
67
    `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/assignee`
68
  );
69

70
  const response = await fetch(url, {
71
    method: "PUT",
72
    headers: {
73
      "Content-Type": "application/json",
74
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
75
    },
76
    body: JSON.stringify(body),
77
  });
78
  if (!response.ok) {
79
    const text = await response.text();
80
    throw new Error(`${response.status} ${text}`);
81
  }
82
  return await response.json();
83
}
84