From cd6002a9f442d1be18294ff1e7ca391ffe21b1a0 Mon Sep 17 00:00:00 2001 From: luke-hagar-sp <98849695+luke-hagar-sp@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:38:35 -0500 Subject: [PATCH] adjusted collection method --- github-user-stats.json | 8 ++-- src/index.ts | 106 ++++++++++++++++++++++++++++------------- 2 files changed, 78 insertions(+), 36 deletions(-) diff --git a/github-user-stats.json b/github-user-stats.json index 9184a66..bf9ad41 100644 --- a/github-user-stats.json +++ b/github-user-stats.json @@ -2,10 +2,10 @@ "name": "Luke Hagar", "username": "lukehagar", "repoViews": 1589, - "linesOfCodeChanged": 7397302, + "linesOfCodeChanged": 10613251, "totalCommits": 1582, "totalPullRequests": 48, - "codeByteTotal": 11731473, + "codeByteTotal": 11731760, "topLanguages": [ { "languageName": "Svelte", @@ -20,7 +20,7 @@ { "languageName": "TypeScript", "color": "#3178c6", - "value": 3157579 + "value": 3157866 }, { "languageName": "Makefile", @@ -82,5 +82,5 @@ "starCount": 113, "closedIssues": 12, "openIssues": 10, - "fetchedAt": 1709244633038 + "fetchedAt": 1709246251263 } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index f1c94d1..58ceccb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,41 +43,71 @@ export async function getUserData( ); } -export async function getRepoData(octokit: Octokit, username: string) { +export async function getRepoData( + octokit: Octokit, + username: string +): Promise { return octokit.graphql.paginate( - `query repoInfo ($login: String!, $cursor: String) { - user(login: $login) { - repositories( - orderBy: {field: STARGAZERS, direction: DESC} - ownerAffiliations: OWNER - isFork: false - first: 100 - after: $cursor - ) { - totalCount - nodes { - stargazers { - totalCount + `query repoInfo($login: String!, $cursor: String) { + user(login: $login) { + repositories( + orderBy: {field: STARGAZERS, direction: DESC} + ownerAffiliations: OWNER + isFork: false + first: 100 + ) { + totalCount + nodes { + stargazers { + totalCount + } + forkCount + name + languages(first: 10, orderBy: {field: SIZE, direction: DESC}) { + edges { + size + node { + color + name + } + } + } } - forkCount - name - languages(first: 10, orderBy: {field: SIZE, direction: DESC}) { - edges { - size - node { - color - name + pageInfo { + endCursor + hasNextPage + } + } + repositoriesContributedTo( + first: 100 + includeUserRepositories: false + orderBy: {field: STARGAZERS, direction: DESC} + contributionTypes: [COMMIT, PULL_REQUEST, REPOSITORY, PULL_REQUEST_REVIEW] + after: $cursor + ) { + pageInfo { + hasNextPage + endCursor + } + nodes { + nameWithOwner + stargazers { + totalCount + } + forkCount + languages(first: 10, orderBy: {field: SIZE, direction: DESC}) { + edges { + size + node { + name + color + } } } } } - pageInfo { - endCursor - hasNextPage - } } - } - }`, + }`, { login: username, } @@ -319,6 +349,8 @@ try { // getContributionCollection(octokit, accountCreationDate), ]); + console.log("repoData", repoData.user.repositoriesContributedTo.nodes); + let starCount = 0; let forkCount = 0; for (const repo of repoData.user.repositories.nodes) { @@ -329,10 +361,20 @@ try { const contributorStatsPromises = []; const viewCountPromises = []; for (const repo of repoData.user.repositories.nodes) { - contributorStatsPromises.push( - getReposContributorsStats(octokit, username, repo.name) - ); - viewCountPromises.push(getReposViewCount(octokit, username, repo.name)); + if (repo.name) { + contributorStatsPromises.push( + getReposContributorsStats(octokit, username, repo.name) + ); + viewCountPromises.push(getReposViewCount(octokit, username, repo.name)); + } + } + + for (const repo of repoData.user.repositoriesContributedTo.nodes) { + if (repo.name) { + contributorStatsPromises.push( + getReposContributorsStats(octokit, username, repo.name) + ); + } } const contributorStats = (await Promise.all(contributorStatsPromises))