Remove a custom label from a self-hosted runner for a repository

Remove a custom label from a self-hosted runner configured in a repository. Returns the remaining labels from the runner. This endpoint returns a `404 Not Found` status if the custom label is not present on 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 a custom label from a self-hosted runner for a repository
6
 * Remove a custom label from a self-hosted runner configured
7
in a repository. Returns the remaining labels from the runner.
8

9
This endpoint returns a `404 Not Found` status if the custom label is not
10
present on the runner.
11

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

26
  const response = await fetch(url, {
27
    method: "DELETE",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39