0
Create or update remote issue link
One script reply has been approved by the moderators Verified

Creates or updates a remote issue link for an issue.

Created by hugo697 622 days ago Viewed 22485 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 622 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Create or update remote issue link
8
 * Creates or updates a remote issue link for an issue.
9
 */
10
export async function main(
11
  auth: Jira,
12
  issueIdOrKey: string,
13
  body: {
14
    application?: { name?: string; type?: string; [k: string]: unknown };
15
    globalId?: string;
16
    object: {
17
      icon?: {
18
        link?: string;
19
        title?: string;
20
        url16x16?: string;
21
        [k: string]: unknown;
22
      };
23
      status?: {
24
        icon?: {
25
          link?: string;
26
          title?: string;
27
          url16x16?: string;
28
          [k: string]: unknown;
29
        };
30
        resolved?: boolean;
31
        [k: string]: unknown;
32
      };
33
      summary?: string;
34
      title: string;
35
      url: string;
36
      [k: string]: unknown;
37
    };
38
    relationship?: string;
39
    [k: string]: unknown;
40
  }
41
) {
42
  const url = new URL(
43
    `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/remotelink`
44
  );
45

46
  const response = await fetch(url, {
47
    method: "POST",
48
    headers: {
49
      "Content-Type": "application/json",
50
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
51
    },
52
    body: JSON.stringify(body),
53
  });
54
  if (!response.ok) {
55
    const text = await response.text();
56
    throw new Error(`${response.status} ${text}`);
57
  }
58
  return await response.json();
59
}
60