Created
April 24, 2013 17:57
-
-
Save etewiah/5454122 to your computer and use it in GitHub Desktop.
Use Gh3 library to recurse over branches and files in a github repository
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>gh3</title> | |
</head> | |
<body> | |
<h2>Get file contents</h2> | |
<label>User</label> <input value="dougmiller" id="userName" /> | |
<label>Repository Name</label> <input value="SVG-Shapes" id="repositoryName" /> | |
<input type="button" value="Get Repository" onclick='getRep()' /> | |
<h4>Branches</h4> | |
<ul id="branchesList"> | |
</ul> | |
<h4>Files</h4> | |
<ul id="filesList"> | |
</ul> | |
<h4>File Content</h4> | |
<textarea style="width: 80%;height: 500px;"> | |
</textarea> | |
</body> | |
<script src="../vendors/jquery-1.7.2.js"></script> | |
<script src="../vendors/underscore.js"></script> | |
<script src="../gh3.js"></script> | |
<script> | |
var branchesList = $("#branchesList"); | |
var filesList = $("#filesList"); | |
var rawContent = $("textarea"); | |
var scope = {}; | |
var ghUser = new Gh3.User($("#userName")[0].value ); | |
var ghRepository = new Gh3.Repository($("#repositoryName")[0].value, | |
ghUser); | |
var getRep = function(){ | |
ghRepository.fetch(function (err, res) { | |
ghRepository.fetchBranches(function (err, res) { | |
res.eachBranch( function(branch){ | |
branchesList.append('<li>'+branch.name); | |
branchesList.append("<input type=\"button\" value=\"Get Files for this Branch\" " + | |
"onclick=\"getBranch('" + branch.name + "')\" />"); | |
}); | |
}); | |
}); | |
}; | |
var getBranch = function(branchName){ | |
scope.branch = ghRepository.getBranchByName(branchName); | |
scope.branch.fetchContents(function (err, res) { | |
if(err) { throw "outch ..." } | |
filesList.html(""); | |
res.eachContent(function (content) { | |
filesList.append('<li>'+content.name); | |
filesList.append("<input type=\"button\" value=\"Get File\" " + | |
"onclick=\"getFile('" + content.name + "')\" />"); | |
}); | |
}); | |
}; | |
var getFile = function(fileName){ | |
myfile = scope.branch.getFileByName(fileName); | |
myfile.fetchContent(function (err, res) { | |
if(err) { throw "outch ..." } | |
rawContent.text(myfile.getRawContent()); | |
}); | |
}; | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment