forked from k33g/gh3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh3.min.js
1 lines (1 loc) · 14.5 KB
/
gh3.min.js
1
(function(){var e,t,n,s=this;if(e="undefined"!=typeof exports?exports:s.Gh3={},e.VERSION="1.0.0",t=function(){},t.inherits=function(e,t,n){var s,r=function(){},o=function(e,t){for(var n in t)e[n]=t[n]};return s=t&&t.hasOwnProperty("constructor")?t.constructor:function(){e.apply(this,arguments)},o(s,e),r.prototype=e.prototype,s.prototype=new r,t&&o(s.prototype,t),n&&o(s,n),s.prototype.constructor=s,s.__super__=e.prototype,s},t.extend=function(e,n){var s=t.inherits(this,e,n);return s.extend=this.extend,s},n={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",decode:function(e){var t,s,r,o,i,c,u,a="",f=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");f<e.length;)o=this._keyStr.indexOf(e.charAt(f++)),i=this._keyStr.indexOf(e.charAt(f++)),c=this._keyStr.indexOf(e.charAt(f++)),u=this._keyStr.indexOf(e.charAt(f++)),t=o<<2|i>>4,s=(15&i)<<4|c>>2,r=(3&c)<<6|u,a+=String.fromCharCode(t),64!=c&&(a+=String.fromCharCode(s)),64!=u&&(a+=String.fromCharCode(r));return a=n._utf8_decode(a)},encode:function(e){var t,s,r,o,i,c,u,a="",f=0;for(e=n._utf8_encode(e);f<e.length;)t=e.charCodeAt(f++),s=e.charCodeAt(f++),r=e.charCodeAt(f++),o=t>>2,i=(3&t)<<4|s>>4,c=(15&s)<<2|r>>6,u=63&r,isNaN(s)?c=u=64:isNaN(r)&&(u=64),a=a+this._keyStr.charAt(o)+this._keyStr.charAt(i)+this._keyStr.charAt(c)+this._keyStr.charAt(u);return a},_utf8_decode:function(e){for(var t="",n=0,s=c1=c2=0;n<e.length;)s=e.charCodeAt(n),128>s?(t+=String.fromCharCode(s),n++):s>191&&224>s?(c2=e.charCodeAt(n+1),t+=String.fromCharCode((31&s)<<6|63&c2),n+=2):(c2=e.charCodeAt(n+1),c3=e.charCodeAt(n+2),t+=String.fromCharCode((15&s)<<12|(63&c2)<<6|63&c3),n+=3);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n<e.length;n++){var s=e.charCodeAt(n);128>s?t+=String.fromCharCode(s):s>127&&2048>s?(t+=String.fromCharCode(s>>6|192),t+=String.fromCharCode(63&s|128)):(t+=String.fromCharCode(s>>12|224),t+=String.fromCharCode(s>>6&63|128),t+=String.fromCharCode(63&s|128))}return t}},e.Base64=n,null!=window.XDomainRequest)try{new XDomainRequest,$.support.cors=!0,$.ajaxSetup.xhr=function(){return new XDomainRequest}}catch(r){}e.Helper=t.extend({},{protocol:"https",domain:"api.github.com",callHttpApi:function(t){if(t.url=e.Helper.protocol+"://"+e.Helper.domain+"/"+t.service,$.support.cors){var n=t.success;$.isFunction(n)&&(t.success=function(e,t,s){n.call(this,{data:e},t,s)})}else t.dataType="jsonp";$.ajax(t)}}),e.Users=t.extend({},{users:[],search:function(t,n,s){e.Users.users=[],e.Helper.callHttpApi({service:"legacy/user/search/"+t,data:n,success:function(t){_.each(t.data.users,function(t){e.Users.users.push(new e.User(t.login,t))}),s&&s(null,e.Users)},error:function(e){s&&s(new Error(e.responseJSON.message),e)}})},reverse:function(){e.Users.users.reverse()},sort:function(t){t?e.Users.users.sort(t):e.Users.users.sort()},getAll:function(){return e.Users.users},getByName:function(t){return _.find(e.Users.users,function(e){return e.name==t})},each:function(t){_.each(e.Users.users,function(e){t(e)})},filter:function(t){return _.filter(e.Users.users,t)}}),e.User=t.extend({constructor:function(e,t){if(t)for(var n in t)this[n]=t[n];if(!e)throw"login !";this.login=e},fetch:function(t){var n=this;e.Helper.callHttpApi({service:"users/"+n.login,success:function(e){for(var s in e.data)n[s]=e.data[s];t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})}},{}),e.GistComment=t.extend({constructor:function(e){for(var t in e)this[t]=e[t]}},{}),e.Gist=t.extend({constructor:function(e){for(var t in e)this[t]=e[t]},fetchContents:function(t){var n=this;n.files=[],e.Helper.callHttpApi({service:"gists/"+n.id,success:function(e){for(var s in e.data.files)n.files.push(e.data.files[s]);delete e.data.files;for(var r in e.data)n[r]=e.data[r];t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},fetchComments:function(t){var n=this;n.comments=[],e.Helper.callHttpApi({service:"gists/"+n.id+"/comments",success:function(s){_.each(s.data,function(t){n.comments.push(new e.GistComment(t))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},getFileByName:function(e){return _.find(this.files,function(t){return t.filename==e})},getFiles:function(){return this.files},eachFile:function(e){_.each(this.files,function(t){e(t)})},getComments:function(){return this.comments},eachComment:function(e){_.each(this.comments,function(t){e(t)})},filterComments:function(e){return _.filter(this.comments,e)}},{}),e.Gists=t.extend({constructor:function(e){e&&(this.user=e),this.gists=[]},fetch:function(t,n,s){var r=this;e.Helper.callHttpApi({service:"users/"+r.user.login+"/gists",data:t,success:function(t){_.each(t.data,function(t){r.gists.push(new e.Gist(t))}),s&&s(null,r)},error:function(e){s&&s(new Error(e.responseJSON.message),e)}})},getGists:function(){return this.gists},eachGist:function(e){_.each(this.gists,function(t){e(t)})},filter:function(e){return _.filter(this.gists,e)}},{}),e.CommitComment=t.extend({constructor:function(e){for(var t in e)this[t]=e[t]}},{}),e.Commit=t.extend({constructor:function(e,t,n){this.author=e.commit.author,this.date=e.commit.author.date,this.message=e.commit.message,this.sha=e.sha,this.url=e.url,t&&(this.user=t),n&&(this.repositoryName=n)},fetchComments:function(t){var n=this;n.comments=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.repositoryName+"/commits/"+n.sha+"/comments",success:function(s){_.each(s.data,function(t){n.comments.push(new e.CommitComment(t))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)},beforeSend:function(e){e.setRequestHeader("Accept","application/vnd.github.v3.full+json")}})},getComments:function(){return this.comments},eachComment:function(e){_.each(this.comments,function(t){e(t)})}},{}),e.ItemContent=t.extend({constructor:function(e,t,n,s){for(var r in e)this[r]=e[r];t&&(this.user=t),n&&(this.repositoryName=n),s&&(this.branchName=s)}},{}),e.File=e.ItemContent.extend({constructor:function(t,n,s,r){e.File.__super__.constructor.call(this,t,n,s,r)},fetchContent:function(t){var s=this;e.Helper.callHttpApi({service:"repos/"+s.user.login+"/"+s.repositoryName+"/contents/"+s.path,success:function(e){s.content=e.data.content,s.rawContent=n.decode(e.data.content),t&&t(null,s)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},fetchCommits:function(t){var n=this;n.commits=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.repositoryName+"/commits",data:{path:n.path,sha:n.branchName},success:function(s){_.each(s.data,function(t){n.commits.push(new e.Commit(t,n.user,n.repositoryName))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},getRawContent:function(){return this.rawContent},getCommits:function(){return this.commits},getLastCommit:function(){return this.commits[0]},getFirstCommit:function(){return this.commits[this.commits.length-1]},eachCommit:function(e){_.each(this.commits,function(t){e(t)})},filterCommits:function(e){return _.filter(this.commits,e)},reverseCommits:function(){this.commits.reverse()},sortCommits:function(e){e?this.commits.sort(e):this.commits.sort()}},{}),e.Dir=e.ItemContent.extend({constructor:function(t,n,s,r){e.Dir.__super__.constructor.call(this,t,n,s,r)},fetchContents:function(t){var n=this;n.contents=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.repositoryName+"/contents/"+n.path,data:{ref:n.branchName},success:function(s){_.each(s.data,function(t){"file"==t.type&&n.contents.push(new e.File(t,n.user,n.repositoryName,n.branchName)),"dir"==t.type&&n.contents.push(new e.Dir(t,n.user,n.repositoryName,n.branchName))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},reverseContents:function(){this.contents.reverse()},sortContents:function(e){e?this.contents.sort(e):this.contents.sort()},getContents:function(){return this.contents},getFileByName:function(e){return _.find(this.contents,function(t){return t.name==e&&"file"==t.type})},getDirByName:function(e){return _.find(this.contents,function(t){return t.name==e&&"dir"==t.type})},eachContent:function(e){_.each(this.contents,function(t){e(t)})},filterContents:function(e){return _.filter(this.contents,e)}},{}),e.Branch=t.extend({constructor:function(e,t,n,s,r){e&&(this.name=e),t&&(this.sha=t),n&&(this.url=n),s&&(this.user=s),r&&(this.repositoryName=r)},fetchContents:function(t){var n=this;n.contents=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.repositoryName+"/contents/",data:{ref:n.name},success:function(s){_.each(s.data,function(t){"file"==t.type&&n.contents.push(new e.File(t,n.user,n.repositoryName,n.name)),"dir"==t.type&&n.contents.push(new e.Dir(t,n.user,n.repositoryName,n.name))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},reverseContents:function(){this.contents.reverse()},sortContents:function(e){e?this.contents.sort(e):this.contents.sort()},getContents:function(){return this.contents},getFileByName:function(e){return _.find(this.contents,function(t){return t.name==e&&"file"==t.type})},getDirByName:function(e){return _.find(this.contents,function(t){return t.name==e&&"dir"==t.type})},eachContent:function(e){_.each(this.contents,function(t){e(t)})},filterContents:function(e){return _.filter(this.contents,e)}},{}),e.Issue=t.extend({constructor:function(e,t,n,s){if(e&&(this.number=e),t&&(this.user=t),n&&(this.repositoryName=n),s)for(var r in s)this[r]=s[r]},fetchContents:function(t){var n=this;e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.repositoryName+"/issues/"+n.id,success:function(e){_.each(e.data,function(){for(var t in e.data)n[t]=e.data[t]}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})}},{}),e.Pull=t.extend({constructor:function(e,t,n,s){if(e&&(this.number=e),t&&(this.user=t),n&&(this.repositoryName=n),s)for(var r in s)this[r]=s[r]},fetchContents:function(t){var n=this;e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.repositoryName+"/pulls/"+n.id,success:function(e){_.each(e.data,function(){for(var t in e.data)n[t]=e.data[t]}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})}},{}),e.Repository=t.extend({constructor:function(e,t,n){if(n)for(var s in n)this[s]=n[s];e&&(this.name=e),t&&(this.user=t)},fetch:function(t){var n=this;e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.name,success:function(e){for(var s in e.data)n[s]=e.data[s];t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},fetchBranches:function(t){var n=this;n.branches=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.name+"/branches",success:function(s){_.each(s.data,function(t){n.branches.push(new e.Branch(t.name,t.commit.sha,t.commit.url,n.user,n.name))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},fetchIssues:function(t){var n=this;n.issues=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.name+"/issues",data:{sort:"updated"},success:function(s){_.each(s.data,function(t){n.issues.push(new e.Issue(t.number,t.user,n.name,t))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},fetchClosedIssues:function(t){var n=this;n.issues=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.name+"/issues",data:{state:"closed",sort:"updated"},success:function(s){_.each(s.data,function(t){n.issues.push(new e.Issue(t.number,t.user,n.name,t))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},fetchPulls:function(t){var n=this;n.pulls=[],e.Helper.callHttpApi({service:"repos/"+n.user.login+"/"+n.name+"/pulls",data:{sort:"updated"},success:function(s){_.each(s.data,function(t){n.pulls.push(new e.Pull(t.number,t.user,n.name,t))}),t&&t(null,n)},error:function(e){t&&t(new Error(e.responseJSON.message),e)}})},getBranches:function(){return this.branches},getBranchByName:function(e){return _.find(this.branches,function(t){return t.name==e})},eachBranch:function(e){_.each(this.branches,function(t){e(t)})},reverseBranches:function(){this.branches.reverse()},sortBranches:function(e){e?this.branches.sort(e):this.branches.sort()},getIssues:function(){return this.issues},eachIssue:function(e){_.each(this.issues,function(t){e(t)})},reverseIssues:function(){this.issues.reverse()},getPulls:function(){return this.pulls},eachPull:function(e){_.each(this.pulls,function(t){e(t)})},reversePulls:function(){this.pulls.reverse()}},{}),e.Repositories=t.extend({constructor:function(e){e&&(this.user=e)},fetch:function(t,n,s){var r=this;r.repositories=[],e.Helper.callHttpApi({service:"users/"+r.user.login+"/repos",data:t,success:function(t){_.each(t.data,function(t){r.repositories.push(new e.Repository(t.name,r.user))}),s&&s(null,r)},error:function(e){s&&s(new Error(e.responseJSON.message),e)}})},reverseRepositories:function(){this.repositories.reverse()},sortRepositories:function(e){e?this.repositories.sort(e):this.repositories.sort()},getRepositories:function(){return this.repositories},getRepositoryByName:function(e){return _.find(this.repositories,function(t){return t.name==e})},eachRepository:function(e){_.each(this.repositories,function(t){e(t)})},filterRepositories:function(e){return _.filter(this.repositories,e)}},{repositories:[],search:function(t,n,s){e.Repositories.repositories=[],e.Helper.callHttpApi({service:"legacy/repos/search/"+t,data:n,success:function(t){_.each(t.data.repositories,function(t){e.Repositories.repositories.push(new e.Repository(t.name,new e.User(t.owner),t))}),s&&s(null,e.Repositories)},error:function(e){s&&s(new Error(e.responseJSON.message),e)}})},reverse:function(){e.Repositories.repositories.reverse()},sort:function(t){t?e.Repositories.repositories.sort(t):e.Repositories.repositories.sort()},getAll:function(){return e.Repositories.repositories},getByName:function(t){return _.find(e.Repositories.repositories,function(e){return e.name==t})},each:function(t){_.each(e.Repositories.repositories,function(e){t(e)})},filter:function(t){return _.filter(e.Repositories.repositories,t)}}),e.Search=t.extend({},{repos:function(t,n,s){e.Search._template(t,n,s,"search/repositories",function(t){return new e.Repository(t.name,new e.User(t.owner),t)})},code:function(t,n,s){e.Search._template(t,n,s,"search/code")},issues:function(t,n,s){var r=/.*\/(.*)\/issues\/.*/;e.Search._template(t,n,s,"search/issues",function(t){var n=r.exec(t.html_url);return n&&n[1]?new e.Issue(t.number,t.user,n[1],t):null})},users:function(t,n,s){e.Search._template(t,n,s,"search/users",function(t){return new e.User(t.login,t)})},_template:function(t,n,s,r,o){var i=$.extend({},t,n);e.Helper.callHttpApi({service:r+"?"+decodeURIComponent($.param(i)),success:function(e){var t=[];o?_.each(e.data.items,function(e){var n=o(e);n&&t.push(n)}):t=e.data.items,s&&s(null,t)},error:function(e){s&&s(new Error(e.responseJSON.message),e)}})}})}).call(this);