List locations for a secret scanning alert

Lists all locations for a given secret scanning alert for an eligible repository. To use this endpoint, you must be an administrator for the repository or for the organization that owns the repository, and you must use a personal access token with the `repo` scope or `security_events` scope. For public repositories, you may instead use the `public_repo` scope. GitHub Apps must have the `secret_scanning_alerts` read 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
 * List locations for a secret scanning alert
6
 * Lists all locations for a given secret scanning alert for an eligible repository.
7
To use this endpoint, you must be an administrator for the repository or for the organization that owns the repository, and you must use a personal access token with the `repo` scope or `security_events` scope.
8
For public repositories, you may instead use the `public_repo` scope.
9

10
GitHub Apps must have the `secret_scanning_alerts` read permission to use this endpoint.
11
 */
12
export async function main(
13
  auth: Github,
14
  owner: string,
15
  repo: string,
16
  alert_number: string,
17
  page: string | undefined,
18
  per_page: string | undefined
19
) {
20
  const url = new URL(
21
    `https://api.github.com/repos/${owner}/${repo}/secret-scanning/alerts/${alert_number}/locations`
22
  );
23
  for (const [k, v] of [
24
    ["page", page],
25
    ["per_page", per_page],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44