-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathuser_info.ts
More file actions
129 lines (124 loc) · 3.78 KB
/
user_info.ts
File metadata and controls
129 lines (124 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
type Language = { name: string };
type Stargazers = { totalCount: number };
type Repository = {
languages: { nodes: Language[] };
stargazers: Stargazers;
};
type Gist = {
stargazers: Stargazers;
};
export type GitHubUserRepository = {
repositories: {
totalCount: number;
nodes: Repository[];
};
gists: {
totalCount: number;
nodes: Gist[];
};
};
export type GitHubUserIssue = {
openIssues: {
totalCount: number;
};
closedIssues: {
totalCount: number;
};
};
export type GitHubUserPullRequest = {
pullRequests: {
totalCount: number;
};
};
export type GitHubUserActivity = {
createdAt: string;
contributionsCollection: {
totalCommitContributions: number;
restrictedContributionsCount: number;
totalPullRequestReviewContributions: number;
};
organizations: {
totalCount: number;
};
followers: {
totalCount: number;
};
};
export class UserInfo {
public readonly totalCommits: number;
public readonly totalFollowers: number;
public readonly totalIssues: number;
public readonly totalOrganizations: number;
public readonly totalPullRequests: number;
public readonly totalReviews: number;
public readonly totalStargazers: number;
public readonly totalRepositories: number;
public readonly languageCount: number;
public readonly durationYear: number;
public readonly durationDays: number;
public readonly ancientAccount: number;
public readonly joined2020: number;
public readonly ogAccount: number;
constructor(
userActivity: GitHubUserActivity,
userIssue: GitHubUserIssue,
userPullRequest: GitHubUserPullRequest,
userRepository: GitHubUserRepository,
) {
const totalCommits =
userActivity.contributionsCollection.restrictedContributionsCount +
userActivity.contributionsCollection.totalCommitContributions;
const totalStargazers = userRepository.repositories.nodes.reduce(
(prev: number, node: Repository) => {
return prev + node.stargazers.totalCount;
},
0,
) +
userRepository.gists.nodes.reduce(
(prev: number, node: Gist) => {
return prev + node.stargazers.totalCount;
},
0,
);
const languages = new Set<string>();
userRepository.repositories.nodes.forEach((node: Repository) => {
if (node.languages.nodes != undefined) {
node.languages.nodes.forEach((node: Language) => {
if (node != undefined) {
languages.add(node.name);
}
});
}
});
const durationTime = new Date().getTime() -
new Date(userActivity.createdAt).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
? 1
: 0;
this.totalCommits = totalCommits;
this.totalFollowers = userActivity.followers.totalCount;
this.totalIssues = userIssue.openIssues.totalCount +
userIssue.closedIssues.totalCount;
this.totalOrganizations = userActivity.organizations.totalCount;
this.totalPullRequests = userPullRequest.pullRequests.totalCount;
this.totalReviews =
userActivity.contributionsCollection.totalPullRequestReviewContributions;
this.totalStargazers = totalStargazers;
this.totalRepositories = userRepository.repositories.totalCount;
this.languageCount = languages.size;
this.durationYear = durationYear;
this.durationDays = durationDays;
this.ancientAccount = ancientAccount;
this.joined2020 = joined2020;
this.ogAccount = ogAccount;
}
}