@@ -22,7 +22,7 @@ const fetcher = (variables, token) => {
22
22
return request (
23
23
{
24
24
query : `
25
- query userInfo($login: String!) {
25
+ query userInfo($login: String!, $ownerAffiliations: [RepositoryAffiliation] ) {
26
26
user(login: $login) {
27
27
name
28
28
login
@@ -45,7 +45,7 @@ const fetcher = (variables, token) => {
45
45
followers {
46
46
totalCount
47
47
}
48
- repositories(ownerAffiliations: OWNER ) {
48
+ repositories(ownerAffiliations: $ownerAffiliations ) {
49
49
totalCount
50
50
}
51
51
}
@@ -70,9 +70,9 @@ const repositoriesFetcher = (variables, token) => {
70
70
return request (
71
71
{
72
72
query : `
73
- query userInfo($login: String!, $after: String) {
73
+ query userInfo($login: String!, $after: String, $ownerAffiliations: [RepositoryAffiliation] ) {
74
74
user(login: $login) {
75
- repositories(first: 100, ownerAffiliations: OWNER , orderBy: {direction: DESC, field: STARGAZERS}, after: $after) {
75
+ repositories(first: 100, ownerAffiliations: $ownerAffiliations , orderBy: {direction: DESC, field: STARGAZERS}, after: $after) {
76
76
nodes {
77
77
name
78
78
stargazers {
@@ -141,15 +141,21 @@ const totalCommitsFetcher = async (username) => {
141
141
* Fetch all the stars for all the repositories of a given username.
142
142
*
143
143
* @param {string } username GitHub username.
144
+ * @param {boolean } include_orgs Include stats from organization repos.
144
145
* @param {array } repoToHide Repositories to hide.
145
146
* @returns {Promise<number> } Total stars.
146
147
*/
147
- const totalStarsFetcher = async ( username , repoToHide ) => {
148
+ const totalStarsFetcher = async ( username , include_orgs , repoToHide ) => {
148
149
let nodes = [ ] ;
149
150
let hasNextPage = true ;
150
151
let endCursor = null ;
151
152
while ( hasNextPage ) {
152
- const variables = { login : username , first : 100 , after : endCursor } ;
153
+ const variables = {
154
+ login : username ,
155
+ first : 100 ,
156
+ after : endCursor ,
157
+ ownerAffiliations : include_orgs ? [ "OWNER" , "COLLABORATOR" ] : [ "OWNER" ] ,
158
+ } ;
153
159
let res = await retryer ( repositoriesFetcher , variables ) ;
154
160
155
161
if ( res . data . errors ) {
@@ -183,12 +189,14 @@ const totalStarsFetcher = async (username, repoToHide) => {
183
189
* @param {string } username GitHub username.
184
190
* @param {boolean } count_private Include private contributions.
185
191
* @param {boolean } include_all_commits Include all commits.
192
+ * @param {boolean } include_orgs Include stats from organization repos.
186
193
* @returns {Promise<import("./types").StatsData> } Stats data.
187
194
*/
188
195
const fetchStats = async (
189
196
username ,
190
197
count_private = false ,
191
198
include_all_commits = false ,
199
+ include_orgs = false ,
192
200
exclude_repo = [ ] ,
193
201
) => {
194
202
if ( ! username ) throw new MissingParamError ( [ "username" ] ) ;
@@ -203,7 +211,10 @@ const fetchStats = async (
203
211
rank : { level : "C" , score : 0 } ,
204
212
} ;
205
213
206
- let res = await retryer ( fetcher , { login : username } ) ;
214
+ let res = await retryer ( fetcher , {
215
+ login : username ,
216
+ ownerAffiliations : include_orgs ? [ "OWNER" , "COLLABORATOR" ] : [ "OWNER" ] ,
217
+ } ) ;
207
218
208
219
// Catch GraphQL errors.
209
220
if ( res . data . errors ) {
@@ -259,7 +270,11 @@ const fetchStats = async (
259
270
stats . contributedTo = user . repositoriesContributedTo . totalCount ;
260
271
261
272
// Retrieve stars while filtering out repositories to be hidden
262
- stats . totalStars = await totalStarsFetcher ( username , repoToHide ) ;
273
+ stats . totalStars = await totalStarsFetcher (
274
+ username ,
275
+ include_orgs ,
276
+ repoToHide ,
277
+ ) ;
263
278
264
279
stats . rank = calculateRank ( {
265
280
totalCommits : stats . totalCommits ,
0 commit comments