From 1ef240653db381d2d3c61c6aafcd3524e5c258d2 Mon Sep 17 00:00:00 2001 From: Mike Pack Date: Sat, 26 Nov 2011 17:40:30 -0700 Subject: [PATCH 01/10] Fix error with iframe content reference. Closes #8 --- github.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/github.js b/github.js index 3fa3045..88e1c5a 100644 --- a/github.js +++ b/github.js @@ -60,7 +60,12 @@ post = function (url, vals) { var form = document.createElement("form"), - iframe = document.createElement("iframe"), + iframe = document.createElement("iframe"); + + // Need to insert the iframe now so contentDocument and contentWindow are defined + document.body.appendChild(iframe); + + var doc = iframe.contentDocument !== undefined ? iframe.contentDocument : iframe.contentWindow.document, @@ -80,7 +85,6 @@ iframe.setAttribute("style", "display: none;"); doc.body.appendChild(form); - document.body.appendChild(iframe); form.submit(); }, From d53b45efb5d73ec949ca2a7757f1b0e3e2328e96 Mon Sep 17 00:00:00 2001 From: Mike Pack Date: Sat, 26 Nov 2011 18:06:53 -0700 Subject: [PATCH 02/10] Add examples --- github.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/github.js b/github.js index 3fa3045..d03af5d 100644 --- a/github.js +++ b/github.js @@ -157,7 +157,14 @@ // Update a user's info. You must be authenticated as this user for this to // succeed. // - // TODO: example + // gh.user("fitzgen").update({name: "Nick Fitzgerald"}); + // + // Possible attributes to update include: + // - name + // - email + // - blog + // - company + // - location gh.user.prototype.update = function (params) { authRequired(this.username); var key, postData = { @@ -175,14 +182,18 @@ // Get a list of who this user is following. // - // TODO: example + // gh.user("fitzgen").following(function (data) { + // console.log(data.users); + // }); gh.user.prototype.following = function (callback, context) { jsonp("user/show/" + this.username + "/following", callback, context); }; // Find out what other users are following this user. // - // TODO: example + // gh.user("fitzgen").followers(function (data) { + // console.log(data.users); + // }); gh.user.prototype.followers = function (callback, context) { jsonp("user/show/" + this.username + "/followers", callback, context); }; @@ -190,7 +201,7 @@ // Make this user follow some other user. You must be authenticated as this // user for this to succeed. // - // TODO: example + // gh.user("fitzgen").follow("mikepack"); gh.user.prototype.follow = function (user) { authRequired.call(this); post("user/follow/" + user); @@ -200,7 +211,7 @@ // Make this user quit following the given `user`. You must be authenticated // as this user to succeed. // - // TODO: example + // gh.user("fitzgen").unfollow("mikepack"); gh.user.prototype.unfollow = function (user) { authRequired.call(this); post("user/unfollow/" + user); @@ -209,7 +220,9 @@ // Get a list of repositories that this user is watching. // - // TODO: example + // gh.user("fitzgen").watching(function (data) { + // console.log(data.repositories); + // }); gh.user.prototype.watching = function (callback, context) { jsonp("repos/watched/" + this.username, callback, context); return this; From 46593c59be7fd406e77c66232a51ea1370e906f4 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 2 Jan 2012 16:42:01 -0500 Subject: [PATCH 03/10] Added user.orgs function to get list of user's organizations --- github.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/github.js b/github.js index 3fa3045..7da691e 100644 --- a/github.js +++ b/github.js @@ -215,6 +215,16 @@ return this; }; + // Get a list of organizations that this user belongs to. + // + // gh.user("fitzgen").organizations( function(data) { + // alert(data.organizations.length); + // }); + gh.user.prototype.orgs = function (callback, context) { + jsonp("user/show/" + this.username + "/organizations", callback, context); + return this + }; + // Get a list of this user's repositories, 30 per page // // gh.user("fitzgen").repos(function (data) { From 24325cd17b199a157ad97b33a4affbfd6ccb02e9 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 2 Jan 2012 17:20:04 -0500 Subject: [PATCH 04/10] Fixed jsonp URLs with token authentication --- github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github.js b/github.js index 3fa3045..cdb06eb 100644 --- a/github.js +++ b/github.js @@ -43,7 +43,7 @@ url += prefix + "callback=" + encodeURIComponent("gh.__jsonp_callbacks[" + id + "]"); if (authUsername && authToken) { - url += "&login=" + authUsername + "&authToken=" + authToken; + url += "&login=" + authUsername + "&token=" + authToken; } script.setAttribute("src", apiRoot + url); From 1b51884480cd8bc159806a688ce17d2b74f3a9d4 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 2 Jan 2012 16:43:04 -0500 Subject: [PATCH 05/10] Added user.allOrgRepos method to get list of all user's organization repos --- github.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/github.js b/github.js index 3fa3045..9d709aa 100644 --- a/github.js +++ b/github.js @@ -215,6 +215,20 @@ return this; }; + // Get a list of all organization repos this user has access to. + // + // gh.authenticate("fitzgen", ); + // user = gh.user("fitzen"); + // + // user.allOrgRepos(function (data) { + // alert(data.repositories.length); + // }); + gh.user.prototype.allOrgRepos = function (callback) { + authRequired(this.username); + jsonp("organizations/repositories", callback); + return this; + }; + // Get a list of this user's repositories, 30 per page // // gh.user("fitzgen").repos(function (data) { From 76b8a3fc1cd8d236753f2cadc723457c6f91d6a7 Mon Sep 17 00:00:00 2001 From: Steve Schwartz Date: Mon, 2 Jan 2012 16:43:48 -0500 Subject: [PATCH 06/10] Added support for authenticating via oauth token. --- github.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/github.js b/github.js index 3fa3045..4cdd35c 100644 --- a/github.js +++ b/github.js @@ -11,6 +11,8 @@ // The username and authentication token of the library's user. authUsername, authToken, + // The access token of OAuth user, can be used instead of authUsername + authToken + authAccessToken // To save keystrokes when we make JSONP calls to the HTTP API, we will keep // track of the root from which all V2 urls extend. @@ -45,6 +47,9 @@ if (authUsername && authToken) { url += "&login=" + authUsername + "&authToken=" + authToken; } + if (authAccessToken) { + url += "&access_token=" + authAccessToken; + } script.setAttribute("src", apiRoot + url); document.getElementsByTagName('head')[0].appendChild(script); @@ -87,7 +92,7 @@ // This helper function will throw a TypeError if the library user is not // properly authenticated. Otherwise, it silently returns. authRequired = function (username) { - if (!authUsername || !authToken || authUsername !== username) { + if ((!authUsername || !authToken || authUsername !== username) && !authAccessToken) { throw new TypeError("gh: Must be authenticated to do that."); } }, @@ -123,9 +128,11 @@ // Authenticate as a user. Does not try to validate at any point; that job // is up to each individual method, which calls `authRequired` as needed. - gh.authenticate = function (username, token) { + // If using OAuth access token, you may pass `null` for `username` and `token` args. + gh.authenticate = function (username, token, accessToken) { authUsername = username; authToken = token; + authAccessToken = accessToken; return this; }; From bb87f7971280894ea8cc9cb1972a8f742c503f2b Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 3 Jan 2012 14:54:57 -0800 Subject: [PATCH 07/10] Adding missing comma --- github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github.js b/github.js index 4f52e34..3005999 100644 --- a/github.js +++ b/github.js @@ -12,7 +12,7 @@ authUsername, authToken, // The access token of OAuth user, can be used instead of authUsername + authToken - authAccessToken + authAccessToken, // To save keystrokes when we make JSONP calls to the HTTP API, we will keep // track of the root from which all V2 urls extend. From ac19564a0fd57464f9428bba55786b4e4b86c7c4 Mon Sep 17 00:00:00 2001 From: avyaznikov Date: Wed, 25 Jan 2012 15:47:44 +0400 Subject: [PATCH 08/10] new gh-issue fixed --- github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github.js b/github.js index 3005999..0a68553 100644 --- a/github.js +++ b/github.js @@ -538,7 +538,7 @@ gh.issue = function (user, repo, number) { if ( !(this instanceof gh.issue) ) - return new gh.commit(user, repo, number); + return new gh.issue(user, repo, number); this.user = user; this.repo = repo; this.number = number; From 2c4fdbe2090ed965d78cf9782698b88bc0b98f24 Mon Sep 17 00:00:00 2001 From: avyaznikov Date: Wed, 25 Jan 2012 17:59:58 +0400 Subject: [PATCH 09/10] Update github.js --- github.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/github.js b/github.js index 0a68553..7b5acde 100644 --- a/github.js +++ b/github.js @@ -543,6 +543,23 @@ this.repo = repo; this.number = number; }; + + //View open issues + gh.issue.prototype.openIssues = function (callback, context) { + jsonp("issues/list/" + this.user + "/" + this.repo + "/open", + callback, + context); + return this; + }; + + //View closed issues + gh.issue.prototype.closedIssues = function (callback, context) { + jsonp("issues/list/" + this.user + "/" + this.repo + "/closed", + callback, + context); + return this; + }; + // View this issue's info. gh.issue.prototype.show = function (callback, context) { From f375e1f89dbd98499d3467fe2ee1afffc6bf5e64 Mon Sep 17 00:00:00 2001 From: Chris DeLuca Date: Tue, 22 Sep 2015 17:12:11 -0400 Subject: [PATCH 10/10] Add syntax highlighting to readme code snippet --- README.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9cbb202..a906598 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,21 @@ Exposes `gh` to the global environment. Tries to follow both the form of Github HTTP API and JS style. - gh.authenticate("fitzgen", "sdfk32we-FAKE-uydfs7f-rhrwe8r7"); - var huddlej = gh.user("huddlej"); - huddlej.show(function (data) { - console.log(data.user); - }); - huddlej.repos(function (data) { - console.log("Number of repos: " + data.repositories.length); - }); - var wujs = gh.repo("fitzgen", "wu.js") - wujs.show(function (data) { - console.log("Number of watchers: " + data.repository.watchers); - }); - wujs.update({ has_wiki: 0 }); // Unfortunately, no callbacks with POSTs :( +```js +gh.authenticate("fitzgen", "sdfk32we-FAKE-uydfs7f-rhrwe8r7"); +var huddlej = gh.user("huddlej"); +huddlej.show(function (data) { + console.log(data.user); +}); +huddlej.repos(function (data) { + console.log("Number of repos: " + data.repositories.length); +}); +var wujs = gh.repo("fitzgen", "wu.js") +wujs.show(function (data) { + console.log("Number of watchers: " + data.repository.watchers); +}); +wujs.update({ has_wiki: 0 }); // Unfortunately, no callbacks with POSTs :( +``` COMPLETE ======== @@ -30,4 +32,4 @@ COMPLETE TODO ==== -* Documentation \ No newline at end of file +* Documentation