Edits history of script submission #10629 for ' Create a new checkout key (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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