Remove a selected repository from a user secret

Removes a repository from the selected repositories for a user's codespace secret. You must authenticate using an access token with the `codespace` or `codespace:secrets` scope to use this endpoint. User must have Codespaces access to use this endpoint. GitHub Apps must have write access to the `codespaces_user_secrets` user permission 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 selected repository from a user secret
6
 * Removes a repository from the selected repositories for a user's codespace secret.
7
You must authenticate using an access token with the `codespace` or `codespace:secrets` scope to use this endpoint. User must have Codespaces access to use this endpoint.
8
GitHub Apps must have write access to the `codespaces_user_secrets` user permission to use this endpoint.
9
 */
10
export async function main(
11
  auth: Github,
12
  secret_name: string,
13
  repository_id: string
14
) {
15
  const url = new URL(
16
    `https://api.github.com/user/codespaces/secrets/${secret_name}/repositories/${repository_id}`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "DELETE",
21
    headers: {
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.text();
31
}
32