0
List linker values for a linker
One script reply has been approved by the moderators Verified

Gets a list of all linker values for the specified linker of the authenticated application.

A linker value lets applications supply values to modify its regular expression.

The base regular expression must use a Bitbucket-specific match group (?K) which will be translated to ([\w\-]+). A value must match this pattern.

Read more about linker values

Created by hugo697 197 days ago Viewed 5857 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 197 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List linker values for a linker
7
 * Gets a list of all linker values for the
8
specified linker of the authenticated application.
9

10
A linker value lets applications supply values to modify its regular expression.
11

12
The base regular expression must use a Bitbucket-specific match group `(?K)`
13
which will be translated to `([\w\-]+)`. A value must match this pattern.
14

15
Read more about linker values
16
 */
17
export async function main(auth: Bitbucket, linker_key: string) {
18
  const url = new URL(
19
    `https://api.bitbucket.org/2.0/addon/linkers/${linker_key}/values`
20
  );
21

22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.text();
34
}
35