Skip to content

Commit daec914

Browse files
committed
Merge branch 'xiaoqiang-master'
2 parents a39afb0 + a5ae1d3 commit daec914

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

lib/repository.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = Repository;
2222

2323
/**
2424
* Get a list of repository branches from a project, sorted by name alphabetically.
25-
*
25+
*
2626
* @param {Object} params
2727
* - {String} id The ID of a project
2828
* @param {Function} callback
@@ -33,10 +33,10 @@ Repository.prototype.getBranches = function (params, callback) {
3333
};
3434

3535
/**
36-
* Protects a single project repository branch.
37-
* This is an idempotent function, protecting an already protected repository branch
36+
* Protects a single project repository branch.
37+
* This is an idempotent function, protecting an already protected repository branch
3838
* still returns a 200 Ok status code.
39-
*
39+
*
4040
* @param {Object} params
4141
* - {String} id The ID of a project
4242
* - {String} branch The name of the branch
@@ -48,10 +48,10 @@ Repository.prototype.protectBranch = function (params, callback) {
4848
};
4949

5050
/**
51-
* Unprotects a single project repository branch.
52-
* This is an idempotent function, unprotecting an already unprotected repository branch
51+
* Unprotects a single project repository branch.
52+
* This is an idempotent function, unprotecting an already unprotected repository branch
5353
* still returns a 200 Ok status code.
54-
*
54+
*
5555
* @param {Object} params
5656
* - {String} id The ID of a project
5757
* - {String} branch The name of the branch
@@ -64,7 +64,7 @@ Repository.prototype.unprotectBranch = function (params, callback) {
6464

6565
/**
6666
* Get a single project repository branch.
67-
*
67+
*
6868
* @param {Object} params
6969
* - {String} id The ID of a project
7070
* - {String} branch The name of the branch
@@ -77,7 +77,7 @@ Repository.prototype.getBranch = function (params, callback) {
7777

7878
/**
7979
* Get a list of repository tags from a project, sorted by name in reverse alphabetical order.
80-
*
80+
*
8181
* @param {Object} params
8282
* - {String} id The ID of a project
8383
* @param {Function} callback
@@ -89,7 +89,7 @@ Repository.prototype.getTags = function (params, callback) {
8989

9090
/**
9191
* Get a list of repository commits in a project.
92-
*
92+
*
9393
* @param {Object} params
9494
* - {String} id The ID of a project
9595
* - {String} [ref_name] The name of a repository branch or tag or if not given the default branch
@@ -102,7 +102,7 @@ Repository.prototype.getCommits = function (params, callback) {
102102

103103
/**
104104
* Get a list of repository files and directories in a project.
105-
*
105+
*
106106
* @param {Object} params
107107
* - {String} id The ID of a project
108108
* - {String} [path] The path inside repository, default is '/'. Used to get contend of subdirectories. e.g.: `test`
@@ -116,7 +116,7 @@ Repository.prototype.getTree = function (params, callback) {
116116

117117
/**
118118
* Get the raw file contents for a file.
119-
*
119+
*
120120
* @param {Object} params
121121
* - {String} id The ID of a project
122122
* - {String} sha The commit or branch name
@@ -128,3 +128,17 @@ Repository.prototype.getBlob = function (params, callback) {
128128
params.contentType = 'buffer';
129129
this.client.request('get', this.path + '/:sha/blob', params, callback);
130130
};
131+
132+
/**
133+
* Get the raw file contents for a blob by blob sha.
134+
*
135+
* @param {Object} params
136+
* - {String} id The ID of a project
137+
* - {String} sha The blob sha
138+
* @param {Function} callback
139+
*/
140+
Repository.prototype.getRawBlob = function (params, callback) {
141+
params.type = 'raw_blobs';
142+
params.contentType = 'buffer';
143+
this.client.request('get', this.path + '/:sha', params, callback);
144+
};

test/repository.test.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('repository.test.js', function () {
116116
branch.should.have.keys('name', 'commit', 'protected');
117117
branch.name.should.equal('master');
118118
branch.protected.should.equal(true);
119-
119+
120120
client.repository.protectBranch({ id: 441, branch: 'master' }, function (err, branch) {
121121
should.not.exists(err);
122122
should.exists(branch);
@@ -135,7 +135,7 @@ describe('repository.test.js', function () {
135135
branch.should.have.keys('name', 'commit', 'protected');
136136
branch.name.should.equal('master');
137137
branch.protected.should.equal(false);
138-
138+
139139
client.repository.unprotectBranch({ id: 441, branch: 'master' }, function (err, branch) {
140140
should.not.exists(err);
141141
should.exists(branch);
@@ -222,4 +222,18 @@ describe('repository.test.js', function () {
222222
});
223223
});
224224

225-
});
225+
describe('client.repository.getRawBlob()', function () {
226+
it('should return raw file content', function (done) {
227+
client.repository.getRawBlob({id: 55045, sha: '946579807281bd26b75b91986c78f15ad0bd40f7'}, function (err, raw) {
228+
should.not.exists(err);
229+
should.exists(raw);
230+
should.ok(Buffer.isBuffer(raw));
231+
raw.should.be.a.Buffer;
232+
raw.length.should.above(0);
233+
raw.toString().should.include('gitlab-client-unittest\n=======\n\n');
234+
done();
235+
});
236+
});
237+
});
238+
239+
});

0 commit comments

Comments
 (0)