-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
51 lines (45 loc) · 1.49 KB
/
github.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(function () {
window.Github = function () {
var pathname = Path.current();
var splittedPath = Path.split(pathname);
this.user = splittedPath[0];
this.project = splittedPath[1];
this.basePath = Path.join([this.user, this.project]);
if (Path.isTree(pathname)) {
this.type = Github.TREE;
this.path = buildTreePath(this);
} else if (Path.isPull(pathname)) {
this.type = Github.PULL_REQUEST;
this.path = new PullPath(this);
} else {
throw "Unknown type for the pathname - " + pathname;
}
};
window.Github.TREE = "tree";
window.Github.PULL_REQUEST = "pull_request";
var API_HOST = "https://api.github.com";
window.Github.HOST = "https://github.com";
window.Github.isTree = function () {
return Path.isTree(Path.current());
};
window.Github.pullType = function () {
var node = document.querySelector("meta[name='diff-view']");
if (node) {
return node.attributes.content.value;
}
};
window.Github.isPullSplit = function () {
return Path.isPull(Path.current()) && this.pullType() === "split";
};
window.Github.isPullUnified = function () {
return Path.isPull(Path.current()) && this.pullType() === "unified";
};
window.Github.api = function (path, callback, errorCallback) {
var url = Path.join([API_HOST, path]);
if (Github.token) {
url += (url.match(/\?/) ? "&" : "?");
url += "access_token=" + Github.token;
}
Request.getJson(url, callback, errorCallback);
};
}());