//native
type Circleci = {
token: string
}
/**
* List webhooks
* Get a list of outbound webhooks that match the given scope-type and scope-id
*/
export async function main(
auth: Circleci,
scope_id: string | undefined,
scope_type: 'project' | undefined
) {
const url = new URL(`https://circleci.com/api/v2/webhook`)
for (const [k, v] of [
['scope-id', scope_id],
['scope-type', scope_type]
]) {
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