@@ -22,7 +22,8 @@ module.exports = class Teams extends Diffable {
22
22
add ( attrs ) {
23
23
// There is not a way to resolve a team slug to an id without fetching all
24
24
// teams for an organization.
25
- return this . allTeams . then ( teams => {
25
+ const options = this . github . teams . list . endpoint . merge ( { per_page : 100 , org : this . repo . owner } )
26
+ this . github . paginate ( options ) . then ( teams => {
26
27
const existing = teams . find ( team => this . comparator ( team , attrs ) )
27
28
28
29
return this . github . teams . addOrUpdateRepo ( this . toParams ( existing , attrs ) )
@@ -43,29 +44,4 @@ module.exports = class Teams extends Diffable {
43
44
permission : attrs . permission
44
45
}
45
46
}
46
-
47
- // Lazy getter to fetch all teams for the organization
48
- get allTeams ( ) {
49
- const getter = this . github . teams . list ( { org : this . repo . owner } )
50
- . then ( this . paginate . bind ( this ) )
51
- . then ( responses => {
52
- return responses . reduce ( ( teams , res ) => {
53
- return teams . concat ( res . data )
54
- } , [ ] )
55
- } )
56
- Object . defineProperty ( this , 'allTeams' , getter )
57
- return getter
58
- }
59
-
60
- // Paginator will keep fetching the next page until there are no more.
61
- paginate ( res , records = [ ] ) {
62
- records = records . concat ( res )
63
- if ( res . meta && this . github . hasNextPage ( res ) ) {
64
- return this . github . getNextPage ( res ) . then ( next => {
65
- return this . paginate ( next , records )
66
- } )
67
- } else {
68
- return Promise . resolve ( records )
69
- }
70
- }
71
47
}
0 commit comments