0
Get an environment secret
One script reply has been approved by the moderators Verified

Gets a single environment secret without revealing its encrypted value. You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have the secrets repository permission to use this endpoint.

Created by hugo697 406 days ago Viewed 9021 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 406 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get an environment secret
6
 * Gets a single environment secret without revealing its encrypted value. You must authenticate using an access token with the `repo` scope to use this endpoint. GitHub Apps must have the `secrets` repository permission to use this endpoint.
7
 */
8
export async function main(
9
  auth: Github,
10
  repository_id: string,
11
  environment_name: string,
12
  secret_name: string
13
) {
14
  const url = new URL(
15
    `https://api.github.com/repositories/${repository_id}/environments/${environment_name}/secrets/${secret_name}`
16
  );
17

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