Apply automatic changes

This commit is contained in:
luke-hagar-sp
2024-03-01 20:16:41 +00:00
committed by github-actions[bot]
parent 275b00b091
commit 8427a7123e
2 changed files with 98 additions and 53 deletions

135
dist/index.js vendored
View File

@@ -45311,25 +45311,19 @@ async function getUsersStars(octokit, username) {
});
}
async function getReposContributorsStats(octokit, username, repo) {
return octokit.rest.repos
.getContributorsStats({
const response = await octokit.rest.repos.getContributorsStats({
owner: username,
repo,
})
.then((res) => {
if (res.status === 202) {
setTimeout(() => {
return octokit.rest.repos.getContributorsStats({
owner: username,
repo,
});
}, 2000);
}
return res;
})
.catch((error) => {
throw new Error(`Failed to fetch data for repo ${repo}: ${error.message}`);
});
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;
}
}
async function getReposViewCount(octokit, username, repo) {
return octokit.rest.repos.getViews({
@@ -45382,42 +45376,63 @@ try {
getTotalCommits(octokit, username),
getContributionCollection(octokit, userDetails.data.created_at),
]);
const viewCountPromises = [];
let starCount = 0;
let forkCount = 0;
for (const repo of repoData.user.repositories.nodes) {
starCount += repo.stargazers.totalCount;
forkCount += repo.forkCount;
}
const contributorStatsPromises = [];
const viewCountPromises = [];
for (const repo of repoData.user.repositories.nodes) {
if (repo.name) {
contributorStatsPromises.push(getReposContributorsStats(octokit, username, repo.name));
let contributorStats = [];
const repos = [
...repoData.user.repositories.nodes,
...repoData.user.repositoriesContributedTo.nodes,
];
for (const repo of repos) {
let repoOwner, repoName;
if (repo.nameWithOwner) {
[repoOwner, repoName] = repo.nameWithOwner.split("/");
}
else {
repoOwner = username;
repoName = repo.name;
}
const repoContribStatsResp = await getReposContributorsStats(octokit, repoOwner, repoName);
let stats;
if (!Array.isArray(repoContribStatsResp.data)) {
console.log("RepoContribStats is not an array");
console.log(repoContribStatsResp);
stats = [repoContribStatsResp.data];
}
else {
stats = repoContribStatsResp.data;
}
// console.log(stats);
const repoContribStats = stats.find((contributor) => contributor.author?.login === username);
// console.log(repoContribStats?.weeks);
if (repoContribStats?.weeks)
contributorStats.push(...repoContribStats.weeks);
if (repoOwner === username) {
viewCountPromises.push(getReposViewCount(octokit, username, repo.name));
starCount += repo.stargazers.totalCount;
forkCount += repo.forkCount;
}
}
for (const repo of repoData.user.repositoriesContributedTo.nodes) {
if (repo.name) {
contributorStatsPromises.push(getReposContributorsStats(octokit, username, repo.name));
}
}
const contributorStats = (await Promise.allSettled(contributorStatsPromises))
.filter((entry) => entry !== null || entry !== undefined)
.map((entry) => {
if (entry.status === "rejected") {
return [];
}
return (Array.isArray(entry.value.data) ? entry.value.data : [entry.value.data])
.filter((contributor) => contributor.author?.login === userDetails.data.login)
.map((contributor) => contributor.weeks);
});
let linesOfCodeChanged = 0;
for (const repo of contributorStats) {
for (const week of repo) {
for (const day of week) {
linesOfCodeChanged += (day.a || 0) + (day.d || 0) + (day.c || 0);
}
let addedLines = 0;
let deletedLines = 0;
let changedLines = 0;
let testTotal = 0;
for (const week of contributorStats) {
if (week.a) {
testTotal += week.a;
addedLines += week.a;
}
if (week.d) {
testTotal += week.d;
deletedLines += week.d;
}
if (week.c) {
testTotal += week.c;
changedLines += week.c;
}
linesOfCodeChanged += (week.a || 0) + (week.d || 0) + (week.c || 0);
}
const viewCounts = await Promise.all(viewCountPromises);
let repoViews = 0;
@@ -45449,6 +45464,36 @@ try {
const allDays = contributionsCollection.contributionCalendar.weeks
.map((w) => w.contributionDays)
.flat(1);
const tableData = [
{ name: "Name", value: userDetails.data.name || "" },
{ name: "Username", value: username },
{ name: "Repository Views", value: repoViews },
{ name: "Lines of Code Changed", value: linesOfCodeChanged },
{ name: "Total Commits", value: totalCommits.data.total_count },
{
name: "Total Pull Requests",
value: userData.user.pullRequests.totalCount,
},
{ name: "Code Byte Total", value: codeByteTotal },
{
name: "Top Languages",
value: topLanguages.map((lang) => lang.languageName).join(", "),
},
{ name: "Fork Count", value: forkCount },
{ name: "Star Count", value: starCount },
{
name: "Total Contributions",
value: contributionsCollection.contributionCalendar.totalContributions,
},
{ name: "Closed Issues", value: userData.viewer.closedIssues.totalCount },
{ name: "Open Issues", value: userData.viewer.openIssues.totalCount },
{ name: "Fetched At", value: fetchedAt },
];
console.table(tableData);
const tableDataString = tableData
.map((row) => `${row.name}: ${row.value}`)
.join("\n");
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput("tableData", tableDataString);
(0,fs__WEBPACK_IMPORTED_MODULE_2__.writeFileSync)("github-user-stats.json", JSON.stringify({
name: userDetails.data.name || "",
username,

View File

@@ -1,11 +1,11 @@
{
"name": "Luke Hagar",
"username": "LukeHagar",
"repoViews": 1842,
"linesOfCodeChanged": 633966,
"totalCommits": 1582,
"repoViews": 1902,
"linesOfCodeChanged": 10702113,
"totalCommits": 1583,
"totalPullRequests": 48,
"codeByteTotal": 12548750,
"codeByteTotal": 12550153,
"topLanguages": [
{
"languageName": "Svelte",
@@ -20,7 +20,7 @@
{
"languageName": "TypeScript",
"color": "#3178c6",
"value": 3158843
"value": 3160246
},
{
"languageName": "Makefile",
@@ -85,10 +85,10 @@
],
"forkCount": 15,
"starCount": 113,
"totalContributions": 1773,
"totalContributions": 1774,
"closedIssues": 12,
"openIssues": 10,
"fetchedAt": 1709295395197,
"fetchedAt": 1709324155287,
"contributionData": [
{
"contributionCount": 1,
@@ -15279,7 +15279,7 @@
"date": "2024-02-29"
},
{
"contributionCount": 0,
"contributionCount": 1,
"date": "2024-03-01"
}
]