Edits history of script submission #10686 for ' Rerun a workflow (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * Rerun a workflow
     * Reruns a workflow.
     */
    export async function main(
    	auth: Circleci,
    	id: string,
    	body: {
    		enable_ssh?: false | true
    		from_failed?: false | true
    		jobs?: string[]
    		sparse_tree?: false | true
    	}
    ) {
    	const url = new URL(`https://circleci.com/api/v2/workflow/${id}/rerun`)
    
    	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