Edits history of script submission #10630 for ' Create a new context (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * Create a new context
     * Creates a new context.
     */
    export async function main(
    	auth: Circleci,
    	body: {
    		name: string
    		owner:
    			| { id: string; type?: 'account' | 'organization' }
    			| { slug: string; type?: 'organization' }
    	}
    ) {
    	const url = new URL(`https://circleci.com/api/v2/context`)
    
    	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