List all autolinks of a repository

This returns a list of autolinks configured for the given repository. Information about autolinks are only available to repository administrators.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List all autolinks of a repository
6
 * This returns a list of autolinks configured for the given repository.
7

8
Information about autolinks are only available to repository administrators.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  page: string | undefined
15
) {
16
  const url = new URL(
17
    `https://api.github.com/repos/${owner}/${repo}/autolinks`
18
  );
19
  for (const [k, v] of [["page", page]]) {
20
    if (v !== undefined && v !== "") {
21
      url.searchParams.append(k, v);
22
    }
23
  }
24
  const response = await fetch(url, {
25
    method: "GET",
26
    headers: {
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: undefined,
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37