From 177725130dca8b0428d374594858ad4bbf85494d Mon Sep 17 00:00:00 2001 From: LukeHagar Date: Thu, 7 Mar 2024 18:03:50 +0000 Subject: [PATCH] chore(release): 0.0.4 --- dist/index.js | 229 +++++++++++++++++++++----------------------------- 1 file changed, 95 insertions(+), 134 deletions(-) diff --git a/dist/index.js b/dist/index.js index addfb1a..dca0067 100644 --- a/dist/index.js +++ b/dist/index.js @@ -45120,14 +45120,24 @@ async function getUserData(octokit, username) { pullRequests(first: 1) { totalCount } - } - viewer { + repositoriesContributedTo(first: 1, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) { + totalCount + } openIssues: issues(states: OPEN) { totalCount } closedIssues: issues(states: CLOSED) { totalCount } + followers { + totalCount + } + repositoryDiscussions { + totalCount + } + repositoryDiscussionComments(onlyAnswers: true) { + totalCount + } } rateLimit { limit @@ -45145,8 +45155,8 @@ async function getRepoData(octokit, username) { repositories( orderBy: {field: STARGAZERS, direction: DESC} ownerAffiliations: OWNER - isFork: false first: 100 + after: $cursor ) { totalCount nodes { @@ -45170,34 +45180,6 @@ async function getRepoData(octokit, username) { 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 - } - } - } - } - } } }`, { login: username, @@ -45215,67 +45197,37 @@ async function getContributionCollection(octokit, year) { if (i === currentYear.getFullYear()) endYear = currentYear.toISOString(); promises.push(octokit - .graphql(`query { + .graphql(`{ rateLimit { limit remaining used resetAt } - viewer { - contributionsCollection(from: "${startYear}", to: "${endYear}") { - totalCommitContributions - restrictedContributionsCount - totalIssueContributions - totalCommitContributions - totalRepositoryContributions - totalPullRequestContributions - totalPullRequestReviewContributions - popularPullRequestContribution { - pullRequest { - id - title - repository { - name - owner { - login - } - } - } - } - contributionCalendar { - totalContributions - weeks { - contributionDays { - contributionCount - date - } - } - } - commitContributionsByRepository { - contributions { - totalCount - } - repository { - name - owner { - login - } - languages(first: 5, orderBy: { field: SIZE, direction: DESC }) { - edges { - size - node { - color - name - id + viewer { + contributionsCollection( + from: "${startYear}" + to: "${endYear}" + ) { + totalCommitContributions + restrictedContributionsCount + totalIssueContributions + totalCommitContributions + totalRepositoryContributions + totalPullRequestContributions + totalPullRequestReviewContributions + contributionCalendar { + totalContributions + weeks { + contributionDays { + contributionCount + date } } } } } } - } - } `) .catch((error) => { console.error(`Failed to fetch data for year ${i}: ${error.message}`); @@ -45287,16 +45239,21 @@ async function getContributionCollection(octokit, year) { } const { contributionsCollection } = years[0].viewer; for (const year of years.slice(1)) { - contributionsCollection.commitContributionsByRepository = [ - ...contributionsCollection.commitContributionsByRepository, - ...year.viewer.contributionsCollection.commitContributionsByRepository, - ]; contributionsCollection.contributionCalendar.totalContributions += year.viewer.contributionsCollection.contributionCalendar.totalContributions; - contributionsCollection.contributionCalendar.weeks = [ - ...contributionsCollection.contributionCalendar.weeks, - ...year.viewer.contributionsCollection.contributionCalendar.weeks, - ]; + contributionsCollection.contributionCalendar.weeks.push(...year.viewer.contributionsCollection.contributionCalendar.weeks); + contributionsCollection.totalCommitContributions += + year.viewer.contributionsCollection.totalCommitContributions; + contributionsCollection.restrictedContributionsCount += + year.viewer.contributionsCollection.restrictedContributionsCount; + contributionsCollection.totalIssueContributions += + year.viewer.contributionsCollection.totalIssueContributions; + contributionsCollection.totalRepositoryContributions += + year.viewer.contributionsCollection.totalRepositoryContributions; + contributionsCollection.totalPullRequestContributions += + year.viewer.contributionsCollection.totalPullRequestContributions; + contributionsCollection.totalPullRequestReviewContributions += + year.viewer.contributionsCollection.totalPullRequestReviewContributions; } return contributionsCollection; } @@ -45311,18 +45268,24 @@ async function getUsersStars(octokit, username) { }); } async function getReposContributorsStats(octokit, username, repo) { - const response = await octokit.rest.repos.getContributorsStats({ - owner: username, - repo, - }); - if (response.status === 202) { - // Retry after the specified delay - await new Promise((resolve) => setTimeout(resolve, 2 * 1000)); - // Retry the request - return getReposContributorsStats(octokit, username, repo); + try { + const response = await octokit.rest.repos.getContributorsStats({ + owner: username, + repo, + }); + if (response.status === 202) { + // Retry after the specified delay + await new Promise((resolve) => setTimeout(resolve, 2 * 1000)); + // Retry the request + return getReposContributorsStats(octokit, username, repo); + } + else { + return response; + } } - else { - return response; + catch (error) { + console.error(error); + return undefined; } } async function getReposViewCount(octokit, username, repo) { @@ -45379,11 +45342,9 @@ try { const viewCountPromises = []; let starCount = 0; let forkCount = 0; + let contribStatsPromises = []; let contributorStats = []; - const repos = [ - ...repoData.user.repositories.nodes, - ...repoData.user.repositoriesContributedTo.nodes, - ]; + const repos = repoData.user.repositories.nodes; for (const repo of repos) { let repoOwner, repoName; if (repo.nameWithOwner) { @@ -45393,23 +45354,29 @@ try { repoOwner = username; repoName = repo.name; } - const repoContribStatsResp = await getReposContributorsStats(octokit, repoOwner, repoName); + contribStatsPromises.push(getReposContributorsStats(octokit, repoOwner, repoName)); + if (repoOwner === username) { + viewCountPromises.push(getReposViewCount(octokit, username, repoName)); + starCount += repo.stargazers.totalCount; + forkCount += repo.forkCount; + } + } + const repoContribStatsResps = await Promise.all(contribStatsPromises); + for (const resp of repoContribStatsResps) { + if (!resp) { + continue; + } let stats; - if (!Array.isArray(repoContribStatsResp.data)) { - console.log(repoContribStatsResp); - stats = [repoContribStatsResp.data]; + if (!Array.isArray(resp.data)) { + console.log(resp); + stats = [resp.data]; } else { - stats = repoContribStatsResp.data; + stats = resp.data; } const repoContribStats = stats.find((contributor) => contributor.author?.login === username); if (repoContribStats?.weeks) contributorStats.push(...repoContribStats.weeks); - if (repoOwner === username) { - viewCountPromises.push(getReposViewCount(octokit, username, repo.name)); - starCount += repo.stargazers.totalCount; - forkCount += repo.forkCount; - } } let linesOfCodeChanged = 0; let addedLines = 0; @@ -45458,9 +45425,6 @@ try { } } } - const allDays = contributionsCollection.contributionCalendar.weeks - .map((w) => w.contributionDays) - .flat(1); const tableData = [ ["Name", userDetails.data.name || ""], ["Username", username], @@ -45476,8 +45440,8 @@ try { "Total Contributions", contributionsCollection.contributionCalendar.totalContributions, ], - ["Closed Issues", userData.viewer.closedIssues.totalCount], - ["Open Issues", userData.viewer.openIssues.totalCount], + ["Closed Issues", userData.user.closedIssues.totalCount], + ["Open Issues", userData.user.openIssues.totalCount], ["Fetched At", fetchedAt], ]; const formattedTableData = tableData.map((row) => { @@ -45496,24 +45460,21 @@ try { forkCount, starCount, totalContributions: contributionsCollection.contributionCalendar.totalContributions, - closedIssues: userData.viewer.closedIssues.totalCount, - openIssues: userData.viewer.openIssues.totalCount, + contributionsCollection, + closedIssues: userData.user.closedIssues.totalCount, + openIssues: userData.user.openIssues.totalCount, fetchedAt, - contributionData: allDays, }, null, 4)); - // const tableDataString = tableData - // .map((row) => `${row.name}: ${row.value}`) - // .join("\n"); - // core.setOutput("tableData", tableDataString); - await _actions_core__WEBPACK_IMPORTED_MODULE_0__.summary.addHeading("Test Results") - .addTable([ - [ - { data: "Name", header: true }, - { data: "Value", header: true }, - ], - ...tableData.map((row) => [String(row[0]), String(row[1])]), - ]) - .write(); + if (process.env["GITHUB_WORKFLOW"] === "CI") + await _actions_core__WEBPACK_IMPORTED_MODULE_0__.summary.addHeading("Test Results") + .addTable([ + [ + { data: "Name", header: true }, + { data: "Value", header: true }, + ], + ...tableData.map((row) => [String(row[0]), String(row[1])]), + ]) + .write(); } catch (error) { _actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(error);