I discovered that by default the API responds with 30 repos.
May I know how should I use for loop to retrieve all repos?
const axios = require('axios');
const repoUrl = `https://api.github.com/users/USERNAME/repos`;
access_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
// console.log
const config = {
headers: {Authorization: `Bearer ${access_token}`} # only 30
};
axios.get(repoUrl, null, config).then((responses) => {
const repos = responses.data.map(({name, language, html_url, created_at, description}) => {
return {name, language, html_url, created_at, description};
})
console.log("number of repo ", repos.length);
}).catch(error => {
console.log(`getrepos error: ${error}`)
});
by https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user--parameters , there is a page parameter
but how should I write the for loop? should I loop the page with 1,2,3,4.... until server give me some error?