/
gh.js
106 lines (80 loc) · 2.91 KB
/
gh.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
window.GH = {
hash: {}
// ,proxy: 'http://hoavui.com/github_jsonp.php?url='
,proxy: './proxy.php?url='
,api: 'http://github.com/api/v2/json'
,Commits: {
listBranch: function(user_id, repository, branch, options ) {
options = Object.extend({
onSuccess: function(response) {
var commits = eval('(' + response.responseText +')');
onData( commits );
}
,onData: Prototype.K
}, options || {});
var onData = options.onData;
var url = GH.api + '/commits/list/' + user_id + '/' + repository + '/' + branch;
new AR( GH.proxy + url, options );
}
,list: function( user_id, repository, branch, path, options ) {
options = Object.extend({
onSuccess: function(response) {
var commits = eval('(' + response.responseText +')').commits;
onData( commits ); // get rid of root namespace
}
,onData: Prototype.K
}, options || {});
var onData = options.onData;
// debugger
var url = GH.api + '/commits/list/' + user_id + '/' + repository + '/' + branch + path;
new AR( GH.proxy + url, options );
}
,show: function( user_id, repository, sha, options ) {
options = Object.extend({
onSuccess: function(response) {
var commit = eval('(' + response.responseText +')').commit;
onData( commit );
}
,onData: Prototype.K
}, options || {});
var onData = options.onData;
var url = GH.api + '/commits/show/' + user_id + '/' + repository + '/' + sha;
new AR( GH.proxy + url, options );
}
}
,Tree: {
show: function( user_id, repository, branch, tree_sha, options ) {
options = Object.extend({
onSuccess: function(response) {
// console.log("response %o",response);
var tree = (eval('(' + response.responseText + ')')).tree;
tree = tree.sort(function(a,b){
// blobs always lose to tree
if( a.type == 'blob' && b.type == 'tree' )
return 1;
if( a.type == 'tree' && b.type == 'blob' )
return -1;
return a.name > b.name ? 1 : ( a.name < b.name ? - 1 : 0 );
});
onData(tree);
}
}, options || {});
var onData = options.onData;
var url = GH.api + '/tree/show/' + user_id +'/' + repository +'/' + tree_sha;
new AR( GH.proxy + url, options);
}
}
,Blob: {
show: function( user_id, repository, sha, options ) {
options = Object.extend({
onSuccess: Prototype.K
}, options || {});
var onData = options.onData;
var url = GH.api + '/blob/show/' + user_id + '/' + repository + '/' + sha;
new AR( GH.proxy + url, options );
}
}
};
/* switch to the correct AR */
window.AR = GH.proxy.indexOf('./') == 0 ? Ajax.Request :
Ajax.JSONRequest;