Created
July 24, 2020 21:51
-
-
Save Adimvicky/db4465dc0039c532ce3d3721796c3354 to your computer and use it in GitHub Desktop.
Getting list of contributors and converting to a markdown list
This file contains 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 fs = require("fs"); | |
const path = require("path"); | |
const request = require("request-promise"); | |
let apiUrl = "https://api.github.com/repos/firstcontributions/first-contributions/contributors?per_page=100"; | |
// Change the page limit (currently 10) to 50 | |
for(let page = 1; page <= 10; page++){ | |
let options = { | |
uri : `${apiUrl}&page=${page}`, | |
headers: { | |
'User-Agent': 'Request-Promise' | |
}, | |
json : true | |
} | |
request(options) | |
.then(data => { | |
if(data){ | |
writeToFile(data); | |
console.log(`Results for page ${page} retrieved => ${data.length}`) | |
} else { | |
console.log(`Data retrieval failed for page ${page}`); | |
} | |
}). | |
catch(e => { | |
console.log(`Data retrieval failed for page ${page} with error => ${e}`); | |
}) | |
}; | |
function writeToFile(data){ | |
for(let profile of data){ | |
let markdown = `* [${profile.login}](${profile.html_url})\n`; | |
fs.appendFile(path.join(__dirname,'Contributor.md'),markdown,()=>{}); | |
}; | |
}; |
This file contains 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
{ | |
"name": "convert-contributors-to-md", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Adim, Alabo", | |
"license": "ISC", | |
"dependencies": { | |
"request": "^2.88.2", | |
"request-promise": "^4.2.6" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment