//native
/**
* List Gists
* List a user's public gists, or the authenticated user's gists (including secret ones) when username is empty. Paginate with page.
*/
export async function main(
auth: RT.Github,
username: string | undefined,
since: string | undefined,
per_page: number = 30,
page: number = 1
) {
const url = new URL(
username
? `https://api.github.com/users/${username}/gists`
: "https://api.github.com/gists"
)
for (const [k, v] of Object.entries({ since, per_page, page })) {
if (v !== undefined && v !== "") url.searchParams.append(k, String(v))
}
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago