Skip to content

Commit 99b7e4b

Browse files
mversluysclayreimann
authored andcommitted
feature(repository): add getReadme
Provides support for the preferred method of retrieving the README from a repository, as opposed to using `getContents`.
1 parent 7748652 commit 99b7e4b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Repository.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,20 @@ class Repository extends Requestable {
404404
}, cb, raw);
405405
}
406406

407+
/**
408+
* Get the README of a repository
409+
* @see https://developer.github.com/v3/repos/contents/#get-the-readme
410+
* @param {string} ref - the ref to check
411+
* @param {boolean} raw - `true` if the results should be returned raw instead of GitHub's normalized format
412+
* @param {Function} cb - will receive the fetched data
413+
* @return {Promise} - the promise for the http request
414+
*/
415+
getReadme(ref, raw, cb) {
416+
return this._request('GET', `/repos/${this.__fullname}/readme`, {
417+
ref
418+
}, cb, raw);
419+
}
420+
407421
/**
408422
* Fork a repository
409423
* @see https://developer.github.com/v3/repos/forks/#create-a-fork

test/repository.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ describe('Repository', function() {
7575
}));
7676
});
7777

78+
it('should show repo readme', function(done) {
79+
remoteRepo.getReadme('master', 'raw', assertSuccessful(done, function(err, text) {
80+
expect(text).to.contain('# Github.js');
81+
82+
done();
83+
}));
84+
});
85+
7886
it('should get ref from repo', function(done) {
7987
remoteRepo.getRef('heads/master', assertSuccessful(done));
8088
});

0 commit comments

Comments
 (0)