-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.js
69 lines (61 loc) · 1.94 KB
/
build.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
// Dependencies
var GitHub = require("gh.js")
, sameTime = require("same-time")
, Logger = require("bug-killer")
, fs = require("fs")
, readJson = require("r-json")
, abs = require("abs")
;
var token = process.argv[2];
// A token is almost mandatory
if (!token) {
try {
token = readJson(abs("~/.github-config.json")).token;
Logger.log("Using the token found in ~/.github-config.json");
} catch (e) {
Logger.log("Usage: node build.js <token>", "warn");
Logger.log("If a token is not provided, this script will fail due to the API rate limit.", "warn");
}
}
// Initialize the gh.js instance
var gh = new GitHub(token);
// Fetch GitHub members
Logger.log("Fetching the GitHub members.");
gh.get("orgs/github/members", { all: true }, function (err, data) {
if (err) {
return Logger.log(err, "error");
}
// Get names
Logger.log("Fetching the names.");
sameTime(data.map(function (c) {
return function (next) {
gh.get("users/" + c.login, function (err, data) {
if (err) {
Logger.log("Failed to fetch the name for @" + data.login);
} else if (data.name) {
Logger.log("Fetched name: " + data.name + " (@" + data.login + ")");
}
next(err, data);
});
};
}), function (err, data) {
if (err) {
return Logger.log(err, "error");
}
// Keep only the data we need
data = data.map(function (c) {
return {
login: c.login
, name: c.name
, avatar_url: c.avatar_url
};
});
// Write to file
fs.writeFile("js/Hubbers.js", "var Hubbers = " + JSON.stringify(data), function (err) {
if (err) {
return Logger.log(err, "error");
}
Logger.log("Saved js/Hubbers.js");
});
});
});