1 | |
2 | type Circleci = { |
3 | token: string |
4 | } |
5 | |
6 | * Retrieves the owner's decision audit logs. |
7 | * This endpoint will return a list of decision audit logs that were made using this owner's policies. |
8 | */ |
9 | export async function main( |
10 | auth: Circleci, |
11 | ownerID: string, |
12 | context: string, |
13 | status: string | undefined, |
14 | after: string | undefined, |
15 | before: string | undefined, |
16 | branch: string | undefined, |
17 | project_id: string | undefined, |
18 | build_number: string | undefined, |
19 | offset: string | undefined |
20 | ) { |
21 | const url = new URL(`https://circleci.com/api/v2/owner/${ownerID}/context/${context}/decision`) |
22 | for (const [k, v] of [ |
23 | ['status', status], |
24 | ['after', after], |
25 | ['before', before], |
26 | ['branch', branch], |
27 | ['project_id', project_id], |
28 | ['build_number', build_number], |
29 | ['offset', offset] |
30 | ]) { |
31 | if (v !== undefined && v !== '' && k !== undefined) { |
32 | url.searchParams.append(k, v) |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: 'GET', |
37 | headers: { |
38 | 'Circle-Token': auth.token |
39 | }, |
40 | body: undefined |
41 | }) |
42 | if (!response.ok) { |
43 | const text = await response.text() |
44 | throw new Error(`${response.status} ${text}`) |
45 | } |
46 | return await response.json() |
47 | } |
48 |
|