From b6d44dd3105fd92b8cee240b5a8f33aaca142bcc Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 06:58:45 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Extract=20GraphQL=20logic=20from?= =?UTF-8?q?=20fetchRepositories?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/github.ts | 77 ++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/src/lib/github.ts b/src/lib/github.ts index ed7dd37..c1b8590 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -295,6 +295,47 @@ type RepositoriesResponse = { } | null; }; +const REPOSITORIES_GRAPHQL_QUERY = `query($login: String!) { + user(login: $login) { + repositories(first: 100, ownerAffiliations: [OWNER, ORGANIZATION_MEMBER, COLLABORATOR], orderBy: {field: STARGAZERS, direction: DESC}, isFork: false, privacy: PUBLIC) { + totalCount + nodes { + name + description + url + stargazerCount + forkCount + isFork + primaryLanguage { name color } + languages(first: 10) { + edges { + size + node { name color } + } + } + repositoryTopics(first: 10) { + nodes { + topic { name } + } + } + } + } + } +}`; + +async function fetchRepositoriesGraphQL( + username: string, + token: string +): Promise { + const data = await graphql(REPOSITORIES_GRAPHQL_QUERY, token, { login: username }); + if (!data.user) { + throw new UserNotFoundError(username); + } + + const repos = data.user.repositories.nodes.filter((r) => !r.isFork); + return processRepoData(repos); +} + /** * Task⑤: リポジトリ一覧・言語統計・トップリポジトリを取得 * 認証時: GraphQL (言語バイト数ベース), 未認証時: REST フォールバック @@ -310,41 +351,7 @@ export const fetchRepositories = cache(async function fetchRepositories( return fetchRepositoriesREST(username); } - const query = `query($login: String!) { - user(login: $login) { - repositories(first: 100, ownerAffiliations: [OWNER, ORGANIZATION_MEMBER, COLLABORATOR], orderBy: {field: STARGAZERS, direction: DESC}, isFork: false, privacy: PUBLIC) { - totalCount - nodes { - name - description - url - stargazerCount - forkCount - isFork - primaryLanguage { name color } - languages(first: 10) { - edges { - size - node { name color } - } - } - repositoryTopics(first: 10) { - nodes { - topic { name } - } - } - } - } - } - }`; - - const data = await graphql(query, token, { login: username }); - if (!data.user) { - throw new UserNotFoundError(username); - } - - const repos = data.user.repositories.nodes.filter((r) => !r.isFork); - return processRepoData(repos); + return fetchRepositoriesGraphQL(username, token); }); async function fetchRepositoriesREST(username: string): Promise {