From d4b62d889581e4a24818640da66fadaad6f0c5e1 Mon Sep 17 00:00:00 2001 From: Christina Ertural <52951132+QuantumChemist@users.noreply.github.com> Date: Mon, 10 Nov 2025 15:32:00 +0100 Subject: [PATCH] Replaced createdAt with date of earliest repo for merged accounts (#377) * Refactor UserInfo class to calculate duration based on earliest repository creation date * Remove repository creation date from Repository type and adjust duration calculations to use user activity creation date * Refactor UserInfo class to calculate duration based on earliest repository creation date * Add repository name logging in UserInfo class for debugging * Add logging for earliest repository creation date and duration calculation in UserInfo class * Add repository name and creation date to user repository query * Remove debug logging for repository name and earliest creation date in UserInfo class * deno task format * Refactor UserInfo class to optimize stargazers and languages aggregation, and streamline earliest repository date calculation * undo last commit * Refactor earliest repository date calculation for improved clarity and efficiency * remove info that was used for debugging * deno task format * remove info that was used for debugging --- src/Schemas/index.ts | 1 + src/user_info.ts | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Schemas/index.ts b/src/Schemas/index.ts index 2c7e3f3..8ac83d7 100644 --- a/src/Schemas/index.ts +++ b/src/Schemas/index.ts @@ -54,6 +54,7 @@ export const queryUserRepository = ` stargazers { totalCount } + createdAt } } } diff --git a/src/user_info.ts b/src/user_info.ts index 805402d..5d1e286 100644 --- a/src/user_info.ts +++ b/src/user_info.ts @@ -3,6 +3,7 @@ type Stargazers = { totalCount: number }; type Repository = { languages: { nodes: Language[] }; stargazers: Stargazers; + createdAt: string; }; export type GitHubUserRepository = { repositories: { @@ -81,20 +82,30 @@ export class UserInfo { }); } }); + + // Find the earliest repository creation date + let earliestRepoDate = userActivity.createdAt; // start with the oldest possible + + earliestRepoDate = userRepository.repositories.nodes.reduce( + (earliest, node) => { + return new Date(node.createdAt).getTime() < new Date(earliest).getTime() + ? node.createdAt + : earliest; + }, + earliestRepoDate, + ); + const durationTime = new Date().getTime() - - new Date(userActivity.createdAt).getTime(); + new Date(earliestRepoDate).getTime(); const durationYear = new Date(durationTime).getUTCFullYear() - 1970; const durationDays = Math.floor( durationTime / (1000 * 60 * 60 * 24) / 100, ); - const ancientAccount = - new Date(userActivity.createdAt).getFullYear() <= 2010 ? 1 : 0; - const joined2020 = new Date(userActivity.createdAt).getFullYear() == 2020 - ? 1 - : 0; - const ogAccount = new Date(userActivity.createdAt).getFullYear() <= 2008 + const ancientAccount = new Date(earliestRepoDate).getFullYear() <= 2010 ? 1 : 0; + const joined2020 = new Date(earliestRepoDate).getFullYear() == 2020 ? 1 : 0; + const ogAccount = new Date(earliestRepoDate).getFullYear() <= 2008 ? 1 : 0; this.totalCommits = totalCommits; this.totalFollowers = userActivity.followers.totalCount;