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
This commit is contained in:
Christina Ertural 2025-11-10 15:32:00 +01:00 • committed by GitHub
parent 5d093da478
commit d4b62d8895
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 7 deletions

View file

@ -54,6 +54,7 @@ export const queryUserRepository = `
stargazers { stargazers {
totalCount totalCount
} }
createdAt
} }
} }
} }

View file

@ -3,6 +3,7 @@ type Stargazers = { totalCount: number };
type Repository = { type Repository = {
languages: { nodes: Language[] }; languages: { nodes: Language[] };
stargazers: Stargazers; stargazers: Stargazers;
createdAt: string;
}; };
export type GitHubUserRepository = { export type GitHubUserRepository = {
repositories: { 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() - const durationTime = new Date().getTime() -
new Date(userActivity.createdAt).getTime(); new Date(earliestRepoDate).getTime();
const durationYear = new Date(durationTime).getUTCFullYear() - 1970; const durationYear = new Date(durationTime).getUTCFullYear() - 1970;
const durationDays = Math.floor( const durationDays = Math.floor(
durationTime / (1000 * 60 * 60 * 24) / 100, durationTime / (1000 * 60 * 60 * 24) / 100,
); );
const ancientAccount = const ancientAccount = new Date(earliestRepoDate).getFullYear() <= 2010
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
? 1 ? 1
: 0; : 0;
const joined2020 = new Date(earliestRepoDate).getFullYear() == 2020 ? 1 : 0;
const ogAccount = new Date(earliestRepoDate).getFullYear() <= 2008 ? 1 : 0;
this.totalCommits = totalCommits; this.totalCommits = totalCommits;
this.totalFollowers = userActivity.followers.totalCount; this.totalFollowers = userActivity.followers.totalCount;