0
Update remote issue link by ID
One script reply has been approved by the moderators Verified

Updates a remote issue link for an issue.

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

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