Created
July 3, 2018 09:42
-
-
Save Junch/dda2025b603f20e8a764db81e85542fd to your computer and use it in GitHub Desktop.
Access the github repos with @octokit/rest.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const octokit = require('@octokit/rest')(); | |
| octokit.authenticate({ | |
| type: 'token', | |
| token: 'xxxxxx your token xxxxxxxx' | |
| }); | |
| async function paginate (method) { | |
| let response = await method({ | |
| owner: 'Junch', | |
| headers: { | |
| accept: 'application/vnd.github.v3+json' | |
| }, | |
| per_page: 40 | |
| }); | |
| let {data} = response; | |
| while (octokit.hasNextPage(response)) { | |
| response = await octokit.getNextPage(response); | |
| data = data.concat(response.data); | |
| } | |
| return data; | |
| } | |
| paginate(octokit.repos.getAll).then(data=>{ | |
| data.forEach(item => { | |
| console.log(item.full_name); | |
| }) | |
| }); | |
| // octokit.repos.getAll({ | |
| // owner: 'Junch', | |
| // headers: { | |
| // accept: 'application/vnd.github.v3+json' | |
| // } | |
| // }).then(response=>{ | |
| // //console.log(response.data.full_name); | |
| // response.data.forEach(item => { | |
| // console.log(item.full_name); | |
| // }) | |
| // }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment