//native
type Circleci = {
token: string
}
/**
* Get summary metrics and trends for a project across it's workflows and branches
* Get summary metrics and trends for a project at workflow and branch level.
*/
export async function main(
auth: Circleci,
project_slug: string,
reporting_window:
| 'last-7-days'
| 'last-90-days'
| 'last-24-hours'
| 'last-30-days'
| 'last-60-days'
| undefined,
branches: string | undefined,
workflow_names: string | undefined
) {
const url = new URL(`https://circleci.com/api/v2/insights/pages/${project_slug}/summary`)
for (const [k, v] of [
['reporting-window', reporting_window],
['branches', branches],
['workflow-names', workflow_names]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
'Circle-Token': auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 536 days ago