This repository has been archived by the owner on Dec 31, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.js
67 lines (59 loc) · 1.73 KB
/
fetch.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
var request = require("request")
var ignoreRepos = ["flagbrew.github.io", "EventsGalleryPacker", "Cachebox"]
function get_readme(repo, callback) {
request("https://api.github.com/repos/FlagBrew/" + repo + "/readme",
{
json: true,
headers: {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
}, function (err, resp, body) {
if (!err && resp.statusCode === 200) {
callback(body)
} else {
console.log(err)
console.log(resp.statusCode)
}
})
}
function get_releases(repo, callback) {
request("https://api.github.com/repos/FlagBrew/" + repo + "/releases",
{
json: true,
headers: {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
}, function (err, resp, body) {
if (!err && resp.statusCode === 200) {
callback(body)
} else {
console.log(err)
console.log(resp.statusCode)
}
})
}
function get_repos(callback) {
// first we fetch a list of repos
request("https://api.github.com/orgs/FlagBrew/repos", {
json: true,
headers: {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
}, function (err, resp, body) {
if (!err && resp.statusCode === 200) {
for (var repo in body) {
if (!ignoreRepos.includes(body[repo].name) && !body[repo].fork) {
callback(body[repo].name)
}
}
} else {
console.log(err)
console.log(resp.statusCode)
}
})
}
module.exports = {
repos: function (callback) {
get_repos(callback)
},
readme: function (repo, callback) {
get_readme(repo, callback)
},
releases: function (repo, callback) {
get_releases(repo, callback)
}
}