diff --git a/README.md b/README.md index a270ef9..9ba4c55 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Deployable **GitHub language chart generator** — embeddable SVGs for READMEs a - **Theming**: Supports `default`, `light`, and `dark` themes. - **Custom Colours**: Set background (`bg`), text (`text`), and individual language colours (`c1`-`c16`) via query parameters. - **Dynamic Layout:** The legend automatically shifts to a **two-column layout** when displaying 9 or more languages. -- Automatically fetches all public GitHub repositories. Organization sources with a token also include private repos visible to that token. +- Automatically fetches all public GitHub repositories. Users or organization sources with a token include private repos exposed to that token. - Ignores forks and optionally specific repositories (`IGNORED_REPOS`). - Uses **hourly caching** to reduce API calls and improve performance. diff --git a/src/github.ts b/src/github.ts index 4baca51..723d74c 100644 --- a/src/github.ts +++ b/src/github.ts @@ -83,13 +83,17 @@ async function fetchAndAggregate(now: number): Promise { let hadFetchFailure = false; const repoGroups = await Promise.all([ ...usernames.map(u => - fetchAllRepos(`https://api.github.com/users/${encodeURIComponent(u.name)}/repos?per_page=100`, u.token) - .then(repos => ({ token: u.token, repos })) - .catch(() => { - hadFetchFailure = true; - console.error(`Skipping user "${u.name}": failed to fetch repositories.`); - return { token: u.token, repos: [] as Repo[] }; - }) + fetchAllRepos( + u.token ? `https://api.github.com/user/repos?per_page=100&visibility=all&affiliation=owner` + : `https://api.github.com/users/${encodeURIComponent(u.name)}/repos?per_page=100`, + u.token + ) + .then(repos => ({ token: u.token, repos })) + .catch(() => { + hadFetchFailure = true; + console.error(`Skipping user "${u.name}": failed to fetch repositories.`); + return { token: u.token, repos: [] as Repo[] }; + }) ), ...orgs.map(o => fetchAllRepos(`https://api.github.com/orgs/${encodeURIComponent(o.name)}/repos?per_page=100`, o.token) diff --git a/tests/github.test.ts b/tests/github.test.ts index 2e4b887..6a9add4 100644 --- a/tests/github.test.ts +++ b/tests/github.test.ts @@ -304,7 +304,7 @@ describe("fetchLanguageData", () => { await fetchLanguageData(); expect(global.fetch).toHaveBeenCalledWith( - "https://api.github.com/users/testuser/repos?per_page=100", + "https://api.github.com/user/repos?per_page=100&visibility=all&affiliation=owner", { headers: { Authorization: "Bearer test-token" } } ); expect(global.fetch).toHaveBeenCalledWith(