//native
type Circleci = {
token: string
}
/**
* List contexts
* List all contexts for an owner.
*/
export async function main(
auth: Circleci,
owner_id: string | undefined,
owner_slug: string | undefined,
owner_type: 'account' | 'organization' | undefined,
page_token: string | undefined
) {
const url = new URL(`https://circleci.com/api/v2/context`)
for (const [k, v] of [
['owner-id', owner_id],
['owner-slug', owner_slug],
['owner-type', owner_type],
['page-token', page_token]
]) {
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