Skip to content

Commit 6c147a4

Browse files
committed
Fixed weird caching issue.
Closes #14.
1 parent 126301b commit 6c147a4

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

github.js

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@
1010

1111
Github = window.Github = function(options) {
1212

13-
// Util
13+
// HTTP Request Abstraction
1414
// =======
15+
//
16+
// I'm not proud of this and neither should you be if you were responsible for the XMLHttpRequest spec.
1517

1618
function _request(method, path, data, cb, raw) {
19+
function getURL() {
20+
var url = API_URL + path;
21+
return url + ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime();
22+
}
23+
1724
var xhr = new XMLHttpRequest();
1825
if (!raw) {xhr.dataType = "json"}
19-
xhr.open(method, API_URL + path);
26+
27+
xhr.open(method, getURL());
2028
xhr.onreadystatechange = function () {
2129
if (this.readyState == 4) {
2230
if (this.status >= 200 && this.status < 300 || this.status === 304) {
@@ -143,6 +151,28 @@
143151
});
144152
};
145153

154+
// Create a new reference
155+
// --------
156+
//
157+
// {
158+
// "ref": "refs/heads/my-new-branch-name",
159+
// "sha": "827efc6d56897b048c772eb4087f854f46256132"
160+
// }
161+
162+
this.createRef = function(options, cb) {
163+
_request("POST", repoPath + "/git/refs", options, cb);
164+
};
165+
166+
// Delete a reference
167+
// --------
168+
//
169+
// repo.deleteRef('heads/gh-pages')
170+
// repo.deleteRef('tags/v1.0')
171+
172+
this.deleteRef = function(ref, cb) {
173+
_request("DELETE", repoPath + "/git/refs/"+ref, options, cb);
174+
};
175+
146176
// List all branches of a repository
147177
// -------
148178

@@ -269,18 +299,41 @@
269299
// -------
270300

271301
this.show = function(cb) {
272-
_request("GET", repoPath, null, function(err, info) {
273-
cb(null, info);
302+
_request("GET", repoPath, null, cb);
303+
};
304+
305+
// Get contents
306+
// --------
307+
308+
this.contents = function(path, cb) {
309+
_request("GET", repoPath + "/contents", { path: path }, cb);
310+
};
311+
312+
// Fork repository
313+
// -------
314+
315+
this.fork = function(cb) {
316+
_request("POST", repoPath + "/forks", null, function(err, forkedRepo) {
317+
cb(null, forkedRepo);
274318
});
275319
};
276320

321+
// Create pull request
322+
// --------
323+
324+
this.createPullRequest = function(options, cb) {
325+
_request("POST", repoPath + "/pulls", options, cb);
326+
};
327+
277328
// Read file at given path
278329
// -------
279330

280331
this.read = function(branch, path, cb) {
281332
that.getSha(branch, path, function(err, sha) {
282333
if (!sha) return cb("not found", null);
283-
that.getBlob(sha, cb);
334+
that.getBlob(sha, function(err, content) {
335+
cb(err, content, sha);
336+
});
284337
});
285338
};
286339

0 commit comments

Comments
 (0)