Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/contributors.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ interface Props {
}
const { repo, file } = Astro.props;

// Build an API URL that gets the 100 most recent commits for the specified file.
// Build an API URL that gets the 100 most recent commits for the overall repo.
// See https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-commits
const url = new URL(`https://api.github.com/repos/${repo}/commits`);
url.searchParams.set('per_page', 1000);
url.searchParams.set('per_page', 100);

Comment thread
Mr-KayZ marked this conversation as resolved.
// Fetch commits from the GitHub API
const commits = await fetch(url, {
Expand All @@ -19,7 +19,11 @@ const commits = await fetch(url, {
}).then((res) => res.json());

function removeDuplicates(commits) {
if (!commits) return [];
if (!Array.isArray(commits)) {
throw new Error(
`GitHub API did not return a commits array. Check the repo name, authentication, and rate limits.\nAPI response: ${JSON.stringify(commits)}`
);
Comment thread
Mr-KayZ marked this conversation as resolved.
}
const map = new Map();
for (const commit of commits) {
const author = commit.author;
Expand Down