Set custom labels for a self-hosted runner for an organization

Remove all previous custom labels and set the new custom labels for a specific self-hosted runner configured in an organization. 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
 * Set custom labels for a self-hosted runner for an organization
6
 * Remove all previous custom labels and set the new custom labels for a specific
7
self-hosted runner configured in an organization.
8

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

21
  const response = await fetch(url, {
22
    method: "PUT",
23
    headers: {
24
      "Content-Type": "application/json",
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: JSON.stringify(body),
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