1 | type Github = { |
2 | token: string; |
3 | }; |
4 | |
5 | * List code scanning analyses for a repository |
6 | * Lists the details of all code scanning analyses for a repository, |
7 | starting with the most recent. |
8 | */ |
9 | export async function main( |
10 | auth: Github, |
11 | owner: string, |
12 | repo: string, |
13 | tool_name: string | undefined, |
14 | tool_guid: string | undefined, |
15 | page: string | undefined, |
16 | per_page: string | undefined, |
17 | ref: string | undefined, |
18 | sarif_id: string | undefined, |
19 | direction: "asc" | "desc" | undefined, |
20 | sort: "created" | undefined |
21 | ) { |
22 | const url = new URL( |
23 | `https://api.github.com/repos/${owner}/${repo}/code-scanning/analyses` |
24 | ); |
25 | for (const [k, v] of [ |
26 | ["tool_name", tool_name], |
27 | ["tool_guid", tool_guid], |
28 | ["page", page], |
29 | ["per_page", per_page], |
30 | ["ref", ref], |
31 | ["sarif_id", sarif_id], |
32 | ["direction", direction], |
33 | ["sort", sort], |
34 | ]) { |
35 | if (v !== undefined && v !== "") { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "GET", |
41 | headers: { |
42 | Authorization: "Bearer " + auth.token, |
43 | }, |
44 | body: undefined, |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|