Add custom labels to a self-hosted runner for a repository

Add custom labels to a 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 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Add custom labels to a self-hosted runner for a repository
6
 * Add custom labels to a self-hosted runner configured in a repository.
7

8
You must authenticate using an access token with the `repo` scope to use this
9
endpoint.
10
 */
11
export async function main(
12
  auth: Github,
13
  owner: string,
14
  repo: string,
15
  runner_id: string,
16
  body: { labels: string[]; [k: string]: unknown }
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: "POST",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36