1
1
const redis = require ( 'redis' )
2
2
const { promisify } = require ( 'bluebird' )
3
3
const Log = require ( 'gk-log' )
4
+ const { flatten } = require ( 'lodash' )
4
5
5
6
const dbs = require ( '../lib/dbs' )
6
7
const githubQueue = require ( '../lib/github-queue' )
@@ -31,13 +32,21 @@ module.exports = async function ({ accountId }) {
31
32
}
32
33
33
34
try {
34
- gitHubRepos = await githubQueue ( installationId ) . read ( github => github . apps . listRepos ( {
35
+ const options = await githubQueue ( installationId ) . read ( github => github . apps . listRepos . endpoint . merge ( {
35
36
headers : {
36
37
accept : 'application/vnd.github.machine-man-preview+json'
37
38
} ,
38
39
org : 'neighbourhoodie' ,
39
40
per_page : 100
40
41
} ) )
42
+
43
+ // Paginate does not actually flatten results into a single result array
44
+ // as it should, according to the docs, possibly due to these:
45
+ // https://github.com/octokit/rest.js/issues/1161
46
+ // https://github.com/octokit/routes/issues/329
47
+ const results = await githubQueue ( installationId ) . read ( github => github . paginate ( options ) )
48
+ // So we flatten them ourselves
49
+ gitHubRepos = flatten ( results . map ( ( result ) => result . repositories ) )
41
50
} catch ( error ) {
42
51
log . error ( 'Could not get repos from Github' , { error : error . message } )
43
52
}
@@ -46,8 +55,8 @@ module.exports = async function ({ accountId }) {
46
55
47
56
// create missing repositories
48
57
let reposToCreate = [ ]
49
- gitHubRepos . repositories . map ( ghRepo => {
50
- if ( ! ghRepo . name . includes ( dbRepos ) ) {
58
+ gitHubRepos . map ( ghRepo => {
59
+ if ( ! dbRepos . includes ( ghRepo . name ) ) {
51
60
reposToCreate . push ( ghRepo )
52
61
}
53
62
} )
0 commit comments