Edits history of script submission #10680 for ' List environment variables (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * List environment variables
     * List information about environment variables in a context, not including their values.
     */
    export async function main(auth: Circleci, context_id: string, page_token: string | undefined) {
    	const url = new URL(`https://circleci.com/api/v2/context/${context_id}/environment-variable`)
    	for (const [k, v] of [['page-token', page_token]]) {
    		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 537 days ago