Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9640aea

Browse filesBrowse files
committed
rate limiting issues
1 parent 1b174c6 commit 9640aea
Copy full SHA for 9640aea

File tree

Expand file treeCollapse file tree

1 file changed

+42
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-5
lines changed

‎javascripts/githubconsole.js

Copy file name to clipboardExpand all lines: javascripts/githubconsole.js
+42-5Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
var uri = _self.api + "users/" + _self.user.login + "/repos?callback=?";
6262
_console.log("fetching: " + uri);
6363
return $.getJSON(uri, function(response) {
64+
checkRateLimit(response.meta);
6465
_self.repos = response.data;
6566
callback();
6667
});
@@ -73,6 +74,7 @@
7374
var uri = _self.api + "users/" + user + "?callback=?";
7475
_console.log("fetching: " + uri);
7576
return $.getJSON(uri, function(response) {
77+
checkRateLimit(response.meta);
7678
_self.user = response.data;
7779
getRepos(function() {
7880
setRepo(repo, function() {
@@ -82,11 +84,25 @@
8284
});
8385
}
8486

87+
function checkRateLimit(meta) {
88+
_console.log(response.meta);
89+
if(response.meta["X-RateLimit-Remaining"] == 0) {
90+
alert("Whoops, you've hit the github rate limit. You'll need to authenticate to continue");
91+
}
92+
_shell.deactivate();
93+
}
94+
8595
function getDir(path, callback) {
86-
var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?ref=" + _self.branch + "&callback=?";
96+
if(path && path.length > 1 && path[path.length-1] === '/') {
97+
path = path.substr(0,path.length-1);
98+
}
99+
var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?callback=?";
100+
//var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?ref=" + _self.branch + "&callback=?";
87101
_console.log("fetching: " + uri);
88102
$.getJSON(uri, function(response) {
103+
checkRateLimit(response.meta);
89104
if(Object.prototype.toString.call(response.data) !== '[object Array]') {
105+
_console.log("path '" + path + "' was a file");
90106
return callback();
91107
}
92108
var node = {
@@ -96,6 +112,7 @@
96112
path: path,
97113
children: response.data
98114
};
115+
_console.log("got node at: " + node.path);
99116
return callback(node);
100117
});
101118
}
@@ -126,7 +143,7 @@
126143
return _.map(children, function(node) {
127144
return {
128145
name: node.name,
129-
path: node.path,
146+
path: "/" + node.path,
130147
isFile: node.type === 'file'
131148
};
132149
});
@@ -141,9 +158,29 @@
141158
if(!path) {
142159
return callback(_pathhandler.current);
143160
}
144-
return getDir(path, function(node) {
145-
callback(node);
146-
})
161+
var parts = _.filter(path.split("/"), function(x) {
162+
return x;
163+
});
164+
_console.log(parts);
165+
if(parts[0] === "..") {
166+
_console.log("looking for parent relative");
167+
var parentParts = _.filter(_pathhandler.current.path.split("/"), function(x) {
168+
return x;
169+
});
170+
if(parentParts.length == 0) {
171+
return callback(_pathhandler.current);
172+
}
173+
path = "/" + parentParts.slice(0, parentParts.length - 1).join('/') + "/" + parts.slice(1).join("/");
174+
} else if(path[0] !== '/') {
175+
_console.log("looking for current relative");
176+
if(_pathhandler.current.path === '/') {
177+
path = '/' + path;
178+
} else {
179+
path = _pathhandler.current.path + "/" + path;
180+
}
181+
}
182+
_console.log("path to fetch: " + path);
183+
return getDir(path, callback);
147184
};
148185
_pathhandler.getChildNodes = function(node, callback) {
149186
if(node.isfile) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.