//native
type Circleci = {
token: string
}
/**
* Create a new checkout key
* Not available to projects that use GitLab or GitHub App. Creates a new checkout key. This API request is only usable with a user API token.
Please ensure that you have authorized your account with GitHub before creating user keys.
This is necessary to give Circleci the permission to create a user key associated with
your GitHub user account. You can find this page by visiting Project Settings > Checkout SSH Keys
*/
export async function main(
auth: Circleci,
project_slug: string,
body: { type: 'user-key' | 'deploy-key' }
) {
const url = new URL(`https://circleci.com/api/v2/project/${project_slug}/checkout-key`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Circle-Token': auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 536 days ago