-
Notifications
You must be signed in to change notification settings - Fork 3
/
fetchGithubData.js
69 lines (60 loc) · 2.18 KB
/
fetchGithubData.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
62
63
64
65
66
67
68
69
const fetch = require('node-fetch');
const fs = require('fs');
const R = require('ramda');
const accessToken = 'YOU_HAVE_TO_GENERATE_YOUR_OWN'; // https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
var groupsOf = R.curry(function group(n, list) {
return R.isEmpty(list) ? [] : R.prepend(R.take(n, list), group(n, R.drop(n, list)));
})(3);
const query = `
query {
organization(login: "inaka") {
repositories(first: 100, orderBy: {field: NAME, direction: ASC})
{
nodes {
name description projectsUrl primaryLanguage { name }
}
}
}
}`;
fetch('https://api.github.com/graphql', {
method: 'POST',
body: JSON.stringify({
query
}),
headers: {
'Authorization': `Bearer ${accessToken}`,
},
})
.then(res => res.json())
.then(body => {
let nodes = {nodes: groupsOf(body.data.organization.repositories.nodes)};
nodes.nodes = nodes.nodes.map(node => node.map(
elm => {
if(elm.primaryLanguage){
elm.imageSuffix = elm.primaryLanguage.name.toLowerCase();
switch(elm.imageSuffix) {
case 'erlang':
case 'swift':
case 'elixir':
case 'objective-c':
case 'makefile':
case 'javascript':
case 'kotlin':
case 'java':
case 'ruby':
break;
default:
elm.imageSuffix = 'erlang';
}
} else {
elm.imageSuffix = 'other';
}
elm.projectsUrl = elm.projectsUrl.replace('/projects', '')
return elm;
}
));
while(R.last(nodes.nodes).length < 3) R.last(nodes.nodes).push({});
fs.writeFileSync('data/repose.json', JSON.stringify(nodes), err => console.error(err));
console.log('FINISHED!!');
})
.catch(error => console.error(error));