Last active
June 14, 2016 23:00
-
-
Save divergentdave/17b2fc8f38741f87c5f7a9ab02742a00 to your computer and use it in GitHub Desktop.
GitHub Pages List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/node_modules | |
/token.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"esversion": 6 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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(); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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