From 4529a830775e890ecbfc80686bb0138dc5772001 Mon Sep 17 00:00:00 2001 From: yorkie Date: Thu, 24 Sep 2015 13:19:59 +0800 Subject: [PATCH] repo: add getRepo with fullname Hooks API has direct full_name to be respond, so adding a way to initistant the repo object with full_name should be more convinent. --- github.js | 16 ++++++++++++++-- test/test.repo.js | 9 +++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/github.js b/github.js index 6f8dc215..97c0adfa 100644 --- a/github.js +++ b/github.js @@ -235,9 +235,16 @@ Github.Repository = function(options) { var repo = options.name; var user = options.user; + var fullname = options.fullname; var that = this; - var repoPath = '/repos/' + user + '/' + repo; + var repoPath; + + if (fullname) { + repoPath = '/repos/' + fullname; + } else { + repoPath = '/repos/' + user + '/' + repo; + } var currentTree = { 'branch': null, @@ -842,7 +849,12 @@ }; this.getRepo = function(user, repo) { - return new Github.Repository({user: user, name: repo}); + if (!repo) { + var fullname = user; + return new Github.Repository({fullname: fullname}); + } else { + return new Github.Repository({user: user, name: repo}); + } }; this.getUser = function() { diff --git a/test/test.repo.js b/test/test.repo.js index 6196cccf..b08e1d99 100644 --- a/test/test.repo.js +++ b/test/test.repo.js @@ -80,6 +80,15 @@ test("Repo API", function(t) { }); }); + t.test('getRepo(fullname)', function(q) { + var repo2 = github.getRepo('michael/github'); + repo2.show(function(err, res) { + q.error(err, 'show repo'); + q.equals(res.full_name, 'michael/github', 'repo name'); + q.end(); + }); + }); + clearTimeout(timeout); t.end();