Skip to content

Commit d4b62d8

Browse files
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
1 parent 5d093da commit d4b62d8

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const queryUserRepository = `
5454
stargazers {
5555
totalCount
5656
}
57+
createdAt
5758
}
5859
}
5960
}

src/user_info.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ type Stargazers = { totalCount: number };
33
type Repository = {
44
languages: { nodes: Language[] };
55
stargazers: Stargazers;
6+
createdAt: string;
67
};
78
export type GitHubUserRepository = {
89
repositories: {
@@ -81,20 +82,30 @@ export class UserInfo {
8182
});
8283
}
8384
});
85+
86+
// Find the earliest repository creation date
87+
let earliestRepoDate = userActivity.createdAt; // start with the oldest possible
88+
89+
earliestRepoDate = userRepository.repositories.nodes.reduce(
90+
(earliest, node) => {
91+
return new Date(node.createdAt).getTime() < new Date(earliest).getTime()
92+
? node.createdAt
93+
: earliest;
94+
},
95+
earliestRepoDate,
96+
);
97+
8498
const durationTime = new Date().getTime() -
85-
new Date(userActivity.createdAt).getTime();
99+
new Date(earliestRepoDate).getTime();
86100
const durationYear = new Date(durationTime).getUTCFullYear() - 1970;
87101
const durationDays = Math.floor(
88102
durationTime / (1000 * 60 * 60 * 24) / 100,
89103
);
90-
const ancientAccount =
91-
new Date(userActivity.createdAt).getFullYear() <= 2010 ? 1 : 0;
92-
const joined2020 = new Date(userActivity.createdAt).getFullYear() == 2020
93-
? 1
94-
: 0;
95-
const ogAccount = new Date(userActivity.createdAt).getFullYear() <= 2008
104+
const ancientAccount = new Date(earliestRepoDate).getFullYear() <= 2010
96105
? 1
97106
: 0;
107+
const joined2020 = new Date(earliestRepoDate).getFullYear() == 2020 ? 1 : 0;
108+
const ogAccount = new Date(earliestRepoDate).getFullYear() <= 2008 ? 1 : 0;
98109

99110
this.totalCommits = totalCommits;
100111
this.totalFollowers = userActivity.followers.totalCount;

0 commit comments

Comments
 (0)