From 3ca1c111eed3b6c67ed9d2f652f4b5e428fef4f4 Mon Sep 17 00:00:00 2001 From: Eugene Fidelin Date: Fri, 13 Feb 2015 15:02:11 +0100 Subject: [PATCH] Get contributors list with additions, deletions, and commit counts --- README.md | 5 +++++ github.js | 21 +++++++++++++++++++++ test/test.repo.js | 12 ++++++++++++ 3 files changed, 38 insertions(+) diff --git a/README.md b/README.md index d4a34352..b5e0c65a 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,11 @@ Delete a reference. repo.deleteRef('heads/gh-pages', function(err) {}); ``` +Get contributors list with additions, deletions, and commit counts. + +```js +repo.contributors(function(err, data) {}); +``` ## User API diff --git a/github.js b/github.js index f0ddb7ab..939407a0 100644 --- a/github.js +++ b/github.js @@ -493,6 +493,27 @@ _request("GET", repoPath, null, cb); }; + // Show repository contributors + // ------- + + this.contributors = function (cb, retry) { + retry = retry || 1000; + var self = this; + _request("GET", repoPath + "/stats/contributors", null, function (err, data, response) { + if (err) return cb(err); + if (response.status === 202) { + setTimeout( + function () { + self.contributors(cb, retry); + }, + retry + ); + } else { + cb(err, data); + } + }); + }; + // Get contents // -------- diff --git a/test/test.repo.js b/test/test.repo.js index 547f6b79..0770ce2a 100644 --- a/test/test.repo.js +++ b/test/test.repo.js @@ -35,6 +35,18 @@ test("Repo API", function(t) { }); }); + t.test('repo.contributors', function(q) { + repo.contributors(function(err, res) { + q.error(err, 'repo contributors'); + q.ok(res instanceof Array, 'list of contributors'); + q.ok(res.length, 'at least one contributor'); + q.ok(res[0].author, 'contributor info'); + q.ok(res[0].total, 'total number of commits'); + q.ok(res[0].weeks, 'weekly hash'); + q.end(); + }); + }); + //@TODO repo.branch, repo.pull t.test('repo.listBranches', function(q) {