//native
type Circleci = {
token: string
}
/**
* Job timeseries data
* Get timeseries data for all jobs within a workflow. Hourly granularity data is only retained for 48 hours while daily granularity data is retained for 90 days.
*/
export async function main(
auth: Circleci,
project_slug: string,
workflow_name: string,
branch: string | undefined,
granularity: 'daily' | 'hourly' | undefined,
start_date: string | undefined,
end_date: string | undefined
) {
const url = new URL(
`https://circleci.com/api/v2/insights/time-series/${project_slug}/workflows/${workflow_name}/jobs`
)
for (const [k, v] of [
['branch', branch],
['granularity', granularity],
['start-date', start_date],
['end-date', end_date]
]) {
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