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