Create a registration token for a repository

Returns a token that you can pass to the `config` script. The token expires after one hour. You must authenticate using an access token with the `repo` scope to use this endpoint. #### Example using registration token Configure your self-hosted runner, replacing `TOKEN` with the registration token provided by this endpoint. ``` ./config.sh --url https://github.com/octo-org/octo-repo-artifacts --token TOKEN ```

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
 * Create a registration token for a repository
6
 * Returns a token that you can pass to the `config` script. The token expires after one hour. You must authenticate
7
using an access token with the `repo` scope to use this endpoint.
8

9
#### Example using registration token
10
 
11
Configure your self-hosted runner, replacing `TOKEN` with the registration token provided by this endpoint.
12

13
```
14
./config.sh --url https://github.com/octo-org/octo-repo-artifacts --token TOKEN
15
```
16
 */
17
export async function main(auth: Github, owner: string, repo: string) {
18
  const url = new URL(
19
    `https://api.github.com/repos/${owner}/${repo}/actions/runners/registration-token`
20
  );
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
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