mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
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:
parent
5d093da478
commit
d4b62d8895
2 changed files with 19 additions and 7 deletions
|
|
@ -54,6 +54,7 @@ export const queryUserRepository = `
|
|||
stargazers {
|
||||
totalCount
|
||||
}
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue