Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Commit 9d5c1d0

Browse files
dcolensfengmk2
authored andcommitted
feat: Adding repository.compare() (repo-utils#30)
* tests for repository.compare() * forgot to expose new methods!
1 parent 7b1fff8 commit 9d5c1d0

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/properties.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ var properties = {
4444
'getTags',
4545
'getCommits',
4646
'getTree',
47-
'getBlob'
47+
'getBlob',
48+
'archive',
49+
'compare'
4850
],
4951
issues: [
5052
'listNotes',

lib/resources/repository.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,18 @@ Repository.prototype.archive = function (params, callback) {
179179
this.client.request('get', this.path, params, callback);
180180
};
181181

182+
/**
183+
* Compare branches, tags or commits.
184+
*
185+
* @param {Object} params
186+
* - {String} id (required) The ID of a project
187+
* - {String} from (required) - the commit SHA or branch name
188+
* - {String} to (required) - the commit SHA or branch name
189+
* @param {Function} callback
190+
*/
191+
Repository.prototype.compare = function (params, callback) {
192+
params.type = 'compare';
193+
this.client.request('get', this.path, params, callback);
194+
};
195+
182196

test/repository.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,17 @@ describe.skip('repository.test.js', function () {
248248
});
249249
});
250250
});
251+
252+
describe('client.repository.compare()', function () {
253+
it('should return diffs', function (done) {
254+
client.repository.compare({id: 55045, to: 'master', from: '946579807281bd26b75b91986c78f15ad0bd40f7'}, function (err, diffs) {
255+
should.not.exists(err);
256+
should.exists(diffs);
257+
diffs.should.have.keys('commit', 'commits', 'diffs', 'compare_timeout', 'compare_same_ref');
258+
diffs.commits.should.be.instanceof(Array);
259+
diffs.diffs.should.be.instanceof(Array);
260+
done();
261+
});
262+
});
263+
});
251264
});

0 commit comments

Comments
 (0)