//native
type Circleci = {
token: string
}
/**
* Get a pipeline's workflows
* Returns a paginated list of workflows by pipeline ID.
*/
export async function main(auth: Circleci, pipeline_id: string, page_token: string | undefined) {
const url = new URL(`https://circleci.com/api/v2/pipeline/${pipeline_id}/workflow`)
for (const [k, v] of [['page-token', page_token]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + 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