data = {
const S = [];
yield S;
let pages = await fetch(`https://api.github.com/repos/${repo}/stargazers?per_page=100`, {
headers: {
...token && { Authorization: `token ${token}` },
accept: "application/vnd.github.v3.star+json"
}
}).then(d => [...d.headers].find(d => d[0] === "link")?.[1].split(/,/).pop().match(/&page=(\d+)/)?.[1] || 1);
mutable msg = `${pages} pages to load…`
for (const page of new Set([1, +pages].concat(d3.shuffle(d3.range(2, +pages))))) {
const s = await fetch(`https://api.github.com/repos/${repo}/stargazers?per_page=100&page=${page}`, {
headers: {
...token && { Authorization: `token ${token}` },
accept: "application/vnd.github.v3.star+json"
}
})
.catch(() => false)
.then(d => d.json ? d.json() : false);
if (!s) return;
if (s.message) return mutable msg = s.message;
mutable msg = `${--pages} pages to load…`
s.forEach((u, i) => {
S.push({
login: u.user.login,
id: u.user.id,
date: new Date(u.starred_at),
count: 100 * (page - 1) + i + 1,
repo
});
});
S.sort((a, b) => a.count - b.count);
yield S;
await Promises.delay(150);
}
yield S;
}