-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
50 lines (43 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require('dotenv').config()
const fs = require('fs')
const path = require('path')
const Json2csvParser = require('json2csv').Parser;
const github = require('@octokit/rest')({
headers: {
accept: 'application/vnd.github.hellcat-preview+json'
},
//Set this to GHE API url if on GitHub Enterprise
baseUrl: 'https://api.github.com'
})
require('./pagination')(github)
//Add a PAT to the .env file to authenticate against the instance.
github.authenticate({
type: 'token',
token: process.env.ghToken
})
async function getRepoData() {
var table = []
//Get List of Repos and their sizes
const repoResponse = [].concat.apply([],
(await github.paginate(github.repos.getAll())).map(n => n.data.map((n) => [n.name , n.size + ' kb'])))
for(const repo of repoResponse){
table.push({
repo: repo[0],
size: repo[1]
})
}
//Write to CSV file
var jsonResults = JSON.stringify(table)
const fields = ['repo', 'size']
var json2csvParser = new Json2csvParser({
fields,
delimiter: ';'
})
const csv = json2csvParser.parse(table)
console.log(csv)
fs.writeFile('repo-sizes.csv', csv, function (err) {
if (err) throw err
console.log('file saved!')
})
}
getRepoData()