Skip to content

Instantly share code, notes, and snippets.

@Junch
Created July 3, 2018 09:42
Show Gist options
  • Select an option

  • Save Junch/dda2025b603f20e8a764db81e85542fd to your computer and use it in GitHub Desktop.

Select an option

Save Junch/dda2025b603f20e8a764db81e85542fd to your computer and use it in GitHub Desktop.
Access the github repos with @octokit/rest.js
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