1 | type Github = { |
2 | token: string; |
3 | }; |
4 | |
5 | * List secret scanning alerts for an organization |
6 | * Lists secret scanning alerts for eligible repositories in an organization, from newest to oldest. |
7 | To use this endpoint, you must be an administrator or security manager for the organization, and you must use an 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 | org: string, |
15 | state: "open" | "resolved" | undefined, |
16 | secret_type: string | undefined, |
17 | resolution: string | undefined, |
18 | sort: "created" | "updated" | undefined, |
19 | direction: "asc" | "desc" | undefined, |
20 | page: string | undefined, |
21 | per_page: string | undefined, |
22 | before: string | undefined, |
23 | after: string | undefined |
24 | ) { |
25 | const url = new URL( |
26 | `https://api.github.com/orgs/${org}/secret-scanning/alerts` |
27 | ); |
28 | for (const [k, v] of [ |
29 | ["state", state], |
30 | ["secret_type", secret_type], |
31 | ["resolution", resolution], |
32 | ["sort", sort], |
33 | ["direction", direction], |
34 | ["page", page], |
35 | ["per_page", per_page], |
36 | ["before", before], |
37 | ["after", after], |
38 | ]) { |
39 | if (v !== undefined && v !== "") { |
40 | url.searchParams.append(k, v); |
41 | } |
42 | } |
43 | const response = await fetch(url, { |
44 | method: "GET", |
45 | headers: { |
46 | Authorization: "Bearer " + auth.token, |
47 | }, |
48 | body: undefined, |
49 | }); |
50 | if (!response.ok) { |
51 | const text = await response.text(); |
52 | throw new Error(`${response.status} ${text}`); |
53 | } |
54 | return await response.json(); |
55 | } |
56 |
|