Skip to content

Instantly share code, notes, and snippets.

@divergentdave divergentdave/.gitignore
Last active Jun 14, 2016

Embed
What would you like to do?
GitHub Pages List
/node_modules
/token.txt
{
"esversion": 6
}
#!/usr/bin/env node
"use strict";
const async = require("async");
const fs = require("fs");
const GitHub = require("github-api");
const http = require("http");
var fileExists = false;
try {
fileExists = fs.statSync("token.txt").isFile();
} catch (e) {
}
if (!fileExists) {
console.error("No access token found. You should create an access token at https://github.com/settings/tokens and paste it into a file named \"token.txt\".");
process.exit(1);
}
if (process.argv.length <= 2) {
console.error("Usage: " + process.argv[0] + " " + process.argv[1] + " <username> <username> ...");
process.exit(1);
}
const gh = new GitHub({
token: fs.readFileSync("token.txt", "utf-8").trim()
});
async.forEachSeries(process.argv.slice(2), function(username) {
const user = gh.getUser(username);
user.listRepos({type: "owner"}, function(error, result, request) {
if (error) {
console.error(error);
return;
}
async.forEachSeries(result, function(repo, done) {
if (!repo.fork) {
var pages_branch, path;
if (repo.name.toLowerCase() == (repo.owner.login + ".github.io").toLowerCase()) {
pages_branch = "master";
path = "/";
} else {
pages_branch = "gh-pages";
path = "/" + repo.name + "/";
}
gh.getRepo(repo.owner.login, repo.name).listBranches(function (error, result, request) {
if (error) {
console.error(error);
return;
}
async.forEachSeries(result, function(branch, done) {
if (branch.name == pages_branch) {
const options = {
hostname: username + ".github.io",
port: 80,
path: path,
method: "HEAD",
};
const req = http.request(options, function(response) {
const url = response.headers.location || ("http://" + options.hostname + options.path);
console.log(repo.full_name, "->", url);
});
req.on("error", console.error);
req.end();
}
return done();
});
});
}
return done();
});
});
});
{
"name": "github-pages-list",
"version": "1.0.0",
"description": "List all of a given user's repositories with gh-pages branches",
"repository": "gist:17b2fc8f38741f87c5f7a9ab02742a00",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"github"
],
"author": "David Cook",
"license": "ISC",
"dependencies": {
"async": "^2.0.0-rc.6",
"github-api": "^2.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.