@@ -11,11 +11,13 @@ import { CustomError, MissingParamError } from "../common/error.js";
1111import { wrapTextMultiline } from "../common/fmt.js" ;
1212import { request } from "../common/http.js" ;
1313
14+ import { parseOwnerAffiliations } from "../common/ops.js" ;
15+
1416dotenv . config ( ) ;
1517
1618// GraphQL queries.
1719const GRAPHQL_REPOS_FIELD = `
18- repositories(first: 100, ownerAffiliations: OWNER , orderBy: {direction: DESC, field: STARGAZERS}, after: $after ) {
20+ repositories(first: 100, after: $after, ownerAffiliations: $ownerAffiliations , orderBy: {direction: DESC, field: STARGAZERS}) {
1921 totalCount
2022 nodes {
2123 name
@@ -31,15 +33,15 @@ const GRAPHQL_REPOS_FIELD = `
3133` ;
3234
3335const GRAPHQL_REPOS_QUERY = `
34- query userInfo($login: String!, $after: String) {
36+ query userInfo($login: String!, $after: String, $ownerAffiliations: [RepositoryAffiliation] ) {
3537 user(login: $login) {
3638 ${ GRAPHQL_REPOS_FIELD }
3739 }
3840 }
3941` ;
4042
4143const GRAPHQL_STATS_QUERY = `
42- query userInfo($login: String!, $after: String, $includeMergedPullRequests: Boolean!, $includeDiscussions: Boolean!, $includeDiscussionsAnswers: Boolean!, $startTime: DateTime = null) {
44+ query userInfo($login: String!, $after: String, $ownerAffiliations: [RepositoryAffiliation], $ includeMergedPullRequests: Boolean!, $includeDiscussions: Boolean!, $includeDiscussionsAnswers: Boolean!, $startTime: DateTime = null) {
4345 user(login: $login) {
4446 name
4547 login
@@ -103,6 +105,7 @@ const fetcher = (variables, token) => {
103105 *
104106 * @param {object } variables Fetcher variables.
105107 * @param {string } variables.username GitHub username.
108+ * @param {string[] } variables.ownerAffiliations The owner affiliations to filter by. Default: ["OWNER"].
106109 * @param {boolean } variables.includeMergedPullRequests Include merged pull requests.
107110 * @param {boolean } variables.includeDiscussions Include discussions.
108111 * @param {boolean } variables.includeDiscussionsAnswers Include discussions answers.
@@ -113,6 +116,7 @@ const fetcher = (variables, token) => {
113116 */
114117const statsFetcher = async ( {
115118 username,
119+ ownerAffiliations,
116120 includeMergedPullRequests,
117121 includeDiscussions,
118122 includeDiscussionsAnswers,
@@ -126,6 +130,7 @@ const statsFetcher = async ({
126130 login : username ,
127131 first : 100 ,
128132 after : endCursor ,
133+ ownerAffiliations,
129134 includeMergedPullRequests,
130135 includeDiscussions,
131136 includeDiscussionsAnswers,
@@ -222,6 +227,7 @@ const totalCommitsFetcher = async (username) => {
222227 * @param {boolean } include_discussions Include discussions.
223228 * @param {boolean } include_discussions_answers Include discussions answers.
224229 * @param {number|undefined } commits_year Year to count total commits
230+ * @param {string[] } owner_affiliations Owner affiliations. Default: ["OWNER"].
225231 * @returns {Promise<import("./types").StatsData> } Stats data.
226232 */
227233const fetchStats = async (
@@ -232,6 +238,7 @@ const fetchStats = async (
232238 include_discussions = false ,
233239 include_discussions_answers = false ,
234240 commits_year ,
241+ owner_affiliations = [ ] ,
235242) => {
236243 if ( ! username ) {
237244 throw new MissingParamError ( [ "username" ] ) ;
@@ -252,8 +259,11 @@ const fetchStats = async (
252259 rank : { level : "C" , percentile : 100 } ,
253260 } ;
254261
262+ const ownerAffiliations = parseOwnerAffiliations ( owner_affiliations ) ;
263+
255264 let res = await statsFetcher ( {
256265 username,
266+ ownerAffiliations,
257267 includeMergedPullRequests : include_merged_pull_requests ,
258268 includeDiscussions : include_discussions ,
259269 includeDiscussionsAnswers : include_discussions_answers ,
0 commit comments