Remove a custom label from a self-hosted runner for an organization

Remove a custom label from a self-hosted runner configured in an organization. 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 `admin:org` scope to use this endpoint.

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
 * Remove a custom label from a self-hosted runner for an organization
6
 * Remove a custom label from a self-hosted runner configured
7
in an organization. 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 `admin:org` scope to use this endpoint.
13
 */
14
export async function main(
15
  auth: Github,
16
  org: string,
17
  runner_id: string,
18
  name: string
19
) {
20
  const url = new URL(
21
    `https://api.github.com/orgs/${org}/actions/runners/${runner_id}/labels/${name}`
22
  );
23

24
  const response = await fetch(url, {
25
    method: "DELETE",
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