Edits history of script submission #10646 for ' Get a list of pipelines (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * Get a list of pipelines
     * Returns all pipelines for the most recently built projects (max 250) you follow in an organization.
     */
    export async function main(
    	auth: Circleci,
    	org_slug: string | undefined,
    	page_token: string | undefined,
    	mine: string | undefined
    ) {
    	const url = new URL(`https://circleci.com/api/v2/pipeline`)
    	for (const [k, v] of [
    		['org-slug', org_slug],
    		['page-token', page_token],
    		['mine', mine]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			'Circle-Token': auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 536 days ago