@@ -28,9 +28,47 @@ function getQuery(login) {
28
28
`
29
29
}
30
30
31
- module . exports = async ( username , token , org , verbose ) => {
31
+ module . exports = async ( {
32
+ username,
33
+ token,
34
+ org,
35
+ team,
36
+ verbose,
37
+ } ) => {
32
38
const auth = `Basic ${ btoa ( `${ username } :${ token } ` ) } ` ;
33
39
40
+ const query = ( team ) ? `
41
+ query {
42
+ organization(login:"${ org } ") {
43
+ team(slug:"${ team } ") {
44
+ members(first: 100) {
45
+ edges {
46
+ node {
47
+ login
48
+ name
49
+ avatarUrl
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ ` : `
57
+ query {
58
+ organization(login:"${ org } ") {
59
+ membersWithRole(first: 100) {
60
+ edges {
61
+ node {
62
+ login
63
+ name
64
+ avatarUrl
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ ` ;
71
+
34
72
if ( verbose ) { console . info ( 'Fetch org members' ) ; }
35
73
const response = await fetch ( `https://api.github.com/graphql` , {
36
74
method : 'POST' ,
@@ -40,31 +78,20 @@ module.exports = async (username, token, org, verbose) => {
40
78
'Accept' : 'application/json' ,
41
79
} ,
42
80
body : JSON . stringify ( {
43
- query :`
44
- query {
45
- organization(login:"${ org } ") {
46
- membersWithRole(first: 100) {
47
- edges {
48
- node {
49
- login
50
- name
51
- avatarUrl
52
- }
53
- }
54
- }
55
- }
56
- }
57
- ` ,
81
+ query
58
82
} ) ,
59
83
} ) ;
60
84
61
85
62
86
if ( false === response . ok ) {
63
87
return ;
64
88
}
65
- const { data : { organization : { membersWithRole : { edges } } } } = await response . json ( ) ;
66
89
67
- const membersStats = edges . map ( async ( { node} ) => {
90
+ const jsonResponse = await response . json ( ) ;
91
+
92
+ const membersInfo = team ? jsonResponse . data . organization . team . members . edges : jsonResponse . data . organization . membersWithRole . edges ;
93
+
94
+ const membersStats = membersInfo . map ( async ( { node} ) => {
68
95
if ( verbose ) { console . info ( `Fetch "${ node . login } " pull request counter.` ) ; }
69
96
try {
70
97
const responcePR = await fetch ( `https://api.github.com/graphql` , {
0 commit comments