Set custom labels for a self-hosted runner for a repository

Remove all previous custom labels and set the new custom labels for a specific self-hosted runner configured in a repository. 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 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Set custom labels for a self-hosted runner for a repository
6
 * Remove all previous custom labels and set the new custom labels for a specific
7
self-hosted runner configured in a repository.
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
  body: { labels: string[]; [k: string]: unknown }
18
) {
19
  const url = new URL(
20
    `https://api.github.com/repos/${owner}/${repo}/actions/runners/${runner_id}/labels`
21
  );
22

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