-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
61 lines (53 loc) · 1.49 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
51
52
53
54
55
56
57
58
59
60
61
require('dotenv').config()
const fs = require('fs')
const path = require('path')
const Json2csvParser = require('json2csv').Parser;
const github = require('@octokit/rest')({
auth: `token ${process.env.ghToken}`,
previews: [
'hellcat-preview',
'mercy-preview'
],
//Set this to GHE API url if on GitHub Enterprise
baseUrl: 'https://api.github.com'
})
require('./pagination')(github)
async function getTopicData() {
var topics = []
var table = []
//Get List of Repos and their sizes
topics = [].concat.apply([],
(await github.paginate(await github.repos.listForOrg({org: `${process.env.orgName}`))).map(n => n.data.map((n) => n.topics)))
results = new Counter([].concat(...topics));
for (let [topic, times] of results.entries())
table.push({
topic: topic,
results: times
})
//Write to CSV file
const fields = ['topic', 'results']
var json2csvParser = new Json2csvParser({
fields,
delimiter: ';'
})
const csv = json2csvParser.parse(table)
console.log(csv)
fs.writeFile('org-topic-list.csv', csv, function (err) {
if (err) throw err
console.log('file saved!')
})
}
getTopicData()
class Counter extends Map {
constructor(iter, key=null) {
super();
this.key = key || (x => x);
for (let x of iter) {
this.add(x);
}
}
add(x) {
x = this.key(x);
this.set(x, (this.get(x) || 0) + 1);
}
}