Permalink
Browse files

Updated script to also work if you only give a filepath in a repo

  • Loading branch information...
1 parent 70310d5 commit 176eeeebc5049087bf83f16d69e2d3d69f4b4597 @brntbeer committed Oct 30, 2012
Showing with 21 additions and 0 deletions.
  1. +9 −0 README.md
  2. +12 −0 src/main/javascript/github-files.js
View
@@ -9,6 +9,10 @@ API:
$.getGithubFile(user, repo, sha, callback, startLineNum, endLineNum)
+or
+
+ $.getGithubFileByFilePath(user, repo, filePath, callback, startLineNum, endLineNum)
+
Examples:
// fetch this README.md file and return all of the lines
@@ -26,6 +30,11 @@ Examples:
console.log(contents)
}, 6, 15);
+ // fetch this README.md file and return all of the lines
+ $.getGithubFileByFilePath("jamesward", "github-files", "README.md", function(contents) {
+ console.log(contents)
+ });
+
To get the sha for a file in git run something like:
git rev-parse HEAD:README.md
@@ -13,6 +13,18 @@
}
};
+ $.getGithubFileByFilePath =
+ function(user, repo, filePath, callback, startLineNum, endLineNum) {
+ $.ajax({
+ type: "GET"
+ ,url: "https://api.github.com/repos/" + user + "/" + repo + "/contents/"+filePath
+ ,dataType: "jsonp"
+ ,success: function(data){
+ $.getGithubFile(user, repo, data.data.sha, callback, startLineNum, endLineNum)
+ }
+ });
+ };
+
$.getGithubFile =
function(user, repo, sha, callback, startLineNum, endLineNum) {
$.ajax({

0 comments on commit 176eeee

Please sign in to comment.