Edits history of script submission #10634 for ' Create an outbound webhook (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * Create an outbound webhook
     * Creates an outbound webhook.
     */
    export async function main(
    	auth: Circleci,
    	body: {
    		name: string
    		events: 'workflow-completed' | 'job-completed'[]
    		url: string
    		'verify-tls': false | true
    		'signing-secret': string
    		scope: { id: string; type: 'project' }
    	}
    ) {
    	const url = new URL(`https://circleci.com/api/v2/webhook`)
    
    	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 537 days ago