Stars on Gitea: a GitHub token from STARS_GITHUB_TOKEN when set, anonymous otherwise; links to the Gitea repo
Catalog / validate (push) Successful in 17s
Catalog / stars (push) Successful in 19s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 16:19:32 -04:00
1 parent a28681ad71
commit 697383430c
3 files changed
+8 -8

No files matched your search

+4 -5
View File
@@ -20,13 +20,12 @@ export async function refresh(root, get, now) {
return changed;
}
/** A repository's stars from GitHub's API. */
/** A repository's stars from GitHub's API, signed in when GITHUB_TOKEN holds a GitHub token. */
async function stargazers({ owner, repo }) {
const token = process.env.GITHUB_TOKEN;
if (!token) throw new Error("stars: GITHUB_TOKEN is not set");
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
headers: { accept: "application/vnd.github+json", authorization: `Bearer ${token}`, "x-github-api-version": "2022-11-28" },
});
const headers = { accept: "application/vnd.github+json", "x-github-api-version": "2022-11-28" };
if (token) headers.authorization = `Bearer ${token}`;
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}`, { headers });
if (!res.ok) throw new Error(`stars: ${owner}/${repo} answered ${res.status} ${await res.text()}`);
return (await res.json()).stargazers_count;
}