File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ export class APIService {
17
17
'https://api.github.com/graphql' ,
18
18
{
19
19
query : "query GetUserDetails($username: String!) { user(login: $username)" +
20
- "{ name login followers { totalCount } repositories(first: 3 , orderBy: {field: STARGAZERS, direction: DESC})" +
21
- "{ nodes { name stargazerCount } totalCount } } } }" ,
20
+ "{ name login followers { totalCount } repositories(first: 100 , orderBy: {field: STARGAZERS, direction: DESC})" +
21
+ "{ nodes { name stargazerCount } } } } }" ,
22
22
variables : {
23
23
username : username
24
24
}
@@ -31,8 +31,11 @@ export class APIService {
31
31
32
32
if ( response . status !== 200 ) return null ;
33
33
34
- await this . cacheManager . set ( `repos:${ username } ` , JSON . stringify ( response . data ) , 1000 * 60 * 60 ) ;
35
- return response . data ;
34
+ const data : GithubRepos = response . data ;
35
+ data . total_stars = data ?. data ?. user ?. repositories ?. nodes ?. reduce ( ( acc , node ) => acc + node . stargazerCount , 0 ) ;
36
+
37
+ await this . cacheManager . set ( `repos:${ username } ` , JSON . stringify ( data ) , 1000 * 60 * 60 ) ;
38
+ return data ;
36
39
}
37
40
38
41
Original file line number Diff line number Diff line change @@ -11,11 +11,11 @@ interface GithubRepos {
11
11
name : string ,
12
12
stargazerCount : number
13
13
14
- } [ ] ,
15
- totalCount : number
14
+ } [ ]
16
15
}
17
16
}
18
- }
17
+ } ,
18
+ total_stars : number
19
19
}
20
20
21
21
interface GithubStreak {
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ export class WidgetService {
61
61
this . apiService . getActivity ( process . env . ACTIVITY_API , process . env . ACTIVITY_ID )
62
62
] ) ;
63
63
64
- const top_repos = github_data . data . user ?. repositories ?. nodes ?. reduce ( ( acc , value ) => {
64
+ const top_repos = github_data . data . user ?. repositories ?. nodes ?. slice ( 0 , 3 ) ?. reduce ( ( acc , value ) => {
65
65
const el = { [ value . name ] : value . stargazerCount } ;
66
66
acc = { ...acc , ...el } ;
67
67
return acc ;
@@ -78,7 +78,7 @@ export class WidgetService {
78
78
description : process . env . DESCRIPTION ,
79
79
github : {
80
80
followers : github_data . data . user ?. followers ?. totalCount ?? null ,
81
- total_stars : github_data . data . user ?. repositories ?. totalCount ?? null ,
81
+ total_stars : github_data ?. total_stars ?? null ,
82
82
top_repos : top_repos ?? null ,
83
83
streak : streak ? {
84
84
current : streak . streak ,
You can’t perform that action at this time.
0 commit comments