Edits history of script submission #10682 for ' Makes a decision (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * Makes a decision
     * This endpoint will evaluate input data (config+metadata) against owner's stored policies and return a decision.
     */
    export async function main(
    	auth: Circleci,
    	ownerID: string,
    	context: string,
    	body: { input: string; metadata?: {} }
    ) {
    	const url = new URL(`https://circleci.com/api/v2/owner/${ownerID}/context/${context}/decision`)
    
    	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