Skip to content

Commit

Permalink
Merge pull request #13 from IonicaBizauKitchen/improvements
Browse files Browse the repository at this point in the history
Rebuild the list, improvements in build.js
  • Loading branch information
alysonla committed Jul 14, 2016
2 parents a78971c + f8612de commit 12ebdbe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
30 changes: 21 additions & 9 deletions build.js
@@ -1,18 +1,28 @@
// Dependencies
var GitHub = require("gh.js")
, SameTime = require("same-time")
, sameTime = require("same-time")
, Logger = require("bug-killer")
, Fs = require("fs")
, fs = require("fs")
, readJson = require("r-json")
, abs = require("abs")
;


var token = process.argv[2];

// A token is almost mandatory
if (!process.argv[2]) {
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");
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: process.argv[2] });
var gh = new GitHub(token);

// Fetch GitHub members
Logger.log("Fetching the GitHub members.");
Expand All @@ -23,10 +33,12 @@ gh.get("orgs/github/members", { all: true }, function (err, data) {

// Get names
Logger.log("Fetching the names.");
SameTime(data.map(function (c) {
sameTime(data.map(function (c) {
return function (next) {
gh.get("users/" + c.login, function (err, data) {
if (data.name) {
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);
Expand All @@ -47,7 +59,7 @@ gh.get("orgs/github/members", { all: true }, function (err, data) {
});

// Write to file
Fs.writeFile("js/Hubbers.js", "var Hubbers = " + JSON.stringify(data), function (err) {
fs.writeFile("js/Hubbers.js", "var Hubbers = " + JSON.stringify(data), function (err) {
if (err) {
return Logger.log(err, "error");
}
Expand Down

0 comments on commit 12ebdbe

Please sign in to comment.