//native
/**
* List Commits
* List commits newest first, on a branch (sha) or touching a path, filtered by author and date range. Paginate with page.
*/
export async function main(
auth: RT.Github,
owner: string,
repo: string,
sha: string | undefined,
path: string | undefined,
author: string | undefined,
since: string | undefined,
until: string | undefined,
per_page: number = 30,
page: number = 1
) {
const url = new URL(`https://api.github.com/repos/${owner}/${repo}/commits`)
for (const [k, v] of Object.entries({
sha,
path,
author,
since,
until,
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