mirror of
https://github.com/LukeHagar/stats-action.git
synced 2025-12-06 04:21:26 +00:00
broke up graph queries
This commit is contained in:
15203
github-user-stats.json
15203
github-user-stats.json
File diff suppressed because it is too large
Load Diff
101
src/index.ts
101
src/index.ts
@@ -4,46 +4,20 @@ import { writeFileSync } from "fs";
|
|||||||
import { Octokit } from "octokit";
|
import { Octokit } from "octokit";
|
||||||
import { throttling } from "@octokit/plugin-throttling";
|
import { throttling } from "@octokit/plugin-throttling";
|
||||||
import { ContributionsCollection, Language } from "./Types";
|
import { ContributionsCollection, Language } from "./Types";
|
||||||
|
import type { GraphQlQueryResponseData } from "@octokit/graphql";
|
||||||
config();
|
config();
|
||||||
|
|
||||||
const ThrottledOctokit = Octokit.plugin(throttling);
|
const ThrottledOctokit = Octokit.plugin(throttling);
|
||||||
|
|
||||||
export async function getGraphQLData(octokit: Octokit, username: string) {
|
export async function getUserData(
|
||||||
return octokit.graphql.paginate(
|
octokit: Octokit,
|
||||||
`query userInfo($login: String!, $cursor: String) {
|
username: string
|
||||||
|
): Promise<GraphQlQueryResponseData> {
|
||||||
|
return octokit.graphql(
|
||||||
|
`query userInfo($login: String!) {
|
||||||
user(login: $login) {
|
user(login: $login) {
|
||||||
name
|
name
|
||||||
login
|
login
|
||||||
repositories(
|
|
||||||
orderBy: {field: STARGAZERS, direction: DESC}
|
|
||||||
ownerAffiliations: OWNER
|
|
||||||
isFork: false
|
|
||||||
first: 100
|
|
||||||
after: $cursor
|
|
||||||
) {
|
|
||||||
totalCount
|
|
||||||
nodes {
|
|
||||||
stargazers {
|
|
||||||
totalCount
|
|
||||||
}
|
|
||||||
forkCount
|
|
||||||
name
|
|
||||||
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
|
|
||||||
edges {
|
|
||||||
size
|
|
||||||
node {
|
|
||||||
|
|
||||||
color
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pageInfo {
|
|
||||||
endCursor
|
|
||||||
hasNextPage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pullRequests(first: 1) {
|
pullRequests(first: 1) {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
@@ -69,6 +43,47 @@ export async function getGraphQLData(octokit: Octokit, username: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getRepoData(octokit: Octokit, username: string) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
forkCount
|
||||||
|
name
|
||||||
|
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
|
||||||
|
edges {
|
||||||
|
size
|
||||||
|
node {
|
||||||
|
color
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pageInfo {
|
||||||
|
endCursor
|
||||||
|
hasNextPage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
{
|
||||||
|
login: username,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export async function getContributionCollection(
|
export async function getContributionCollection(
|
||||||
octokit: Octokit,
|
octokit: Octokit,
|
||||||
year: string
|
year: string
|
||||||
@@ -257,7 +272,7 @@ try {
|
|||||||
const token = process.env["GITHUB_TOKEN"];
|
const token = process.env["GITHUB_TOKEN"];
|
||||||
if (!token) throw new Error("GITHUB_TOKEN is not present");
|
if (!token) throw new Error("GITHUB_TOKEN is not present");
|
||||||
|
|
||||||
const username = core.getInput("username");
|
const username = core.getInput("username") || "lukehagar";
|
||||||
|
|
||||||
if (!username) throw new Error("Username is not present");
|
if (!username) throw new Error("Username is not present");
|
||||||
|
|
||||||
@@ -293,25 +308,27 @@ try {
|
|||||||
// const accountCreationDate = userDetails.data.created_at;
|
// const accountCreationDate = userDetails.data.created_at;
|
||||||
|
|
||||||
const [
|
const [
|
||||||
graphQLData,
|
userData,
|
||||||
|
repoData,
|
||||||
totalCommits,
|
totalCommits,
|
||||||
// contributionsCollection
|
// contributionsCollection
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
getGraphQLData(octokit, username),
|
getUserData(octokit, username),
|
||||||
|
getRepoData(octokit, username),
|
||||||
getTotalCommits(octokit, username),
|
getTotalCommits(octokit, username),
|
||||||
// getContributionCollection(octokit, accountCreationDate),
|
// getContributionCollection(octokit, accountCreationDate),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let starCount = 0;
|
let starCount = 0;
|
||||||
let forkCount = 0;
|
let forkCount = 0;
|
||||||
for (const repo of graphQLData.user.repositories.nodes) {
|
for (const repo of repoData.user.repositories.nodes) {
|
||||||
starCount += repo.stargazers.totalCount;
|
starCount += repo.stargazers.totalCount;
|
||||||
forkCount += repo.forkCount;
|
forkCount += repo.forkCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
const contributorStatsPromises = [];
|
const contributorStatsPromises = [];
|
||||||
const viewCountPromises = [];
|
const viewCountPromises = [];
|
||||||
for (const repo of graphQLData.user.repositories.nodes) {
|
for (const repo of repoData.user.repositories.nodes) {
|
||||||
contributorStatsPromises.push(
|
contributorStatsPromises.push(
|
||||||
getReposContributorsStats(octokit, username, repo.name)
|
getReposContributorsStats(octokit, username, repo.name)
|
||||||
);
|
);
|
||||||
@@ -348,7 +365,7 @@ try {
|
|||||||
const topLanguages: Language[] = [];
|
const topLanguages: Language[] = [];
|
||||||
let codeByteTotal = 0;
|
let codeByteTotal = 0;
|
||||||
|
|
||||||
for (const node of graphQLData.user.repositories.nodes) {
|
for (const node of repoData.user.repositories.nodes) {
|
||||||
for (const edge of node.languages.edges) {
|
for (const edge of node.languages.edges) {
|
||||||
if (NOT_LANGUAGES_OBJ[edge.node.name.toLowerCase()]) {
|
if (NOT_LANGUAGES_OBJ[edge.node.name.toLowerCase()]) {
|
||||||
continue;
|
continue;
|
||||||
@@ -385,15 +402,15 @@ try {
|
|||||||
repoViews,
|
repoViews,
|
||||||
linesOfCodeChanged,
|
linesOfCodeChanged,
|
||||||
totalCommits: totalCommits.data.total_count,
|
totalCommits: totalCommits.data.total_count,
|
||||||
totalPullRequests: graphQLData.user.pullRequests.totalCount,
|
totalPullRequests: userData.user.pullRequests.totalCount,
|
||||||
codeByteTotal,
|
codeByteTotal,
|
||||||
topLanguages,
|
topLanguages,
|
||||||
forkCount,
|
forkCount,
|
||||||
starCount,
|
starCount,
|
||||||
// totalContributions:
|
// totalContributions:
|
||||||
// contributionsCollection.contributionCalendar.totalContributions,
|
// contributionsCollection.contributionCalendar.totalContributions,
|
||||||
closedIssues: graphQLData.viewer.closedIssues.totalCount,
|
closedIssues: userData.viewer.closedIssues.totalCount,
|
||||||
openIssues: graphQLData.viewer.openIssues.totalCount,
|
openIssues: userData.viewer.openIssues.totalCount,
|
||||||
fetchedAt,
|
fetchedAt,
|
||||||
// contributionData: allDays,
|
// contributionData: allDays,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user