Created
April 26, 2017 22:11
-
-
Save timwco/9a294c987f46efef116ef7d15d36485f to your computer and use it in GitHub Desktop.
Github Pull Repos and back up to CSV
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 request = require('request'); | |
const fs = require('fs'); | |
const csv = require('json2csv'); | |
var githubURL = 'https://api.github.com'; | |
var githubHeaders = { | |
'User-Agent': 'request', | |
'Authorization': 'token <token-here>' | |
}; | |
// Will get up to 100 | |
let url = `${githubURL}/repos/tiy-academics/catalog/issues?state=open&per_page=100` | |
// Change or iterate the page # for > 100 issues | |
request({ url: url + '&page=1', headers: githubHeaders }, | |
function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
let data = JSON.parse(body); | |
// Filter out Issues from Pull Requests - Github does not | |
let issues = data.filter( item => !has(item, 'pull_request')); | |
let mkCSV = csv({ data: issues }); | |
fs.writeFile("./dump.csv", mkCSV, function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log(issues.length, 'were saved!'); | |
}); | |
} else { | |
console.log('ERROR', error); | |
} | |
} | |
) | |
function has(object, key) { | |
return object ? hasOwnProperty.call(object, key) : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment