forked from APIs-guru/awesome-openapi3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.js
More file actions
56 lines (47 loc) · 1.33 KB
/
add.js
File metadata and controls
56 lines (47 loc) · 1.33 KB
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
'use strict';
const fs = require('fs');
const yaml = require('js-yaml');
const graphql = require('graphql-request').GraphQLClient;
const estr = fs.readFileSync('./docs/_data/tools.yaml','utf8');
const entries = yaml.load(estr);
const query = `{
search(type: REPOSITORY, query: "topic:openapi3", first: 100) {
edges{
node {
... on Repository {
url
}
}
}
}
}`
let existing = 0;
let added = 0;
const client = new graphql('https://api.github.com/graphql', { headers: {
Authorization: 'Basic '+Buffer.from(process.env.github_user+':'+process.env.github_pwd).toString('base64')
}});
client.request(query).then(function(data){
for (let edge of data.search.edges) {
let url = edge.node.url;
let entry = entries.find(function(e,i,a){
return e.github && e.github.toLowerCase() === url.toLowerCase();
});
if (entry) {
existing++;
}
else {
entries.push({ github: url, v3: true, category: 'unclassified' });
console.log('New',url);
added++;
}
}
})
.catch(function(ex){
console.error(ex.message);
});
process.on('exit',function(){
console.log('Existing:',existing,'added:',added);
if (added) {
fs.writeFileSync('./docs/_data/tools.yaml',yaml.dump(entries),'utf8');
}
});