Remove all custom labels from a self-hosted runner for a repository

Remove all custom labels from a self-hosted runner configured in a repository. Returns the remaining read-only labels from the runner. You must authenticate using an access token with the `repo` scope to use this endpoint.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Remove all custom labels from a self-hosted runner for a repository
6
 * Remove all custom labels from a self-hosted runner configured in a
7
repository. Returns the remaining read-only labels from the runner.
8

9
You must authenticate using an access token with the `repo` scope to use this
10
endpoint.
11
 */
12
export async function main(
13
  auth: Github,
14
  owner: string,
15
  repo: string,
16
  runner_id: string
17
) {
18
  const url = new URL(
19
    `https://api.github.com/repos/${owner}/${repo}/actions/runners/${runner_id}/labels`
20
  );
21

22
  const response = await fetch(url, {
23
    method: "DELETE",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
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.json();
34
}
35