Edits history of script submission #18558 for ' Get all changelog entries (readme)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get all changelog entries
     * Get all changelog entries from your ReadMe project.
     */
    export async function main(
    	auth: RT.Readme,
    	page?: string | undefined,
    	per_page?: string | undefined,
    	visibility?: 'public' | 'anyone_with_link' | 'all' | undefined
    ) {
    	const url = new URL(`https://api.readme.com/v2/changelogs`)
    	for (const [k, v] of [
    		['page', page],
    		['per_page', per_page],
    		['visibility', visibility]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago