Skip to content

Commit c1701ec

Browse files
committed
docs: improve document
1 parent 82adf29 commit c1701ec

File tree

11 files changed

+538
-30
lines changed

11 files changed

+538
-30
lines changed

README.md

Lines changed: 427 additions & 0 deletions
Large diffs are not rendered by default.

lib/properties.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**!
22
* gitlab - lib/properties.js
33
*
4-
* Copyright(c) fengmk2 and other contributors.
4+
* Copyright(c) repo-utils and other contributors.
55
* MIT Licensed
66
*
77
* Authors:
8-
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
8+
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
99
*/
1010

1111
'use strict';
@@ -26,6 +26,10 @@ var properties = {
2626
users: [],
2727
mergeRequests: [],
2828
repositoryFiles: [],
29+
repositoryBranches: [
30+
'protect',
31+
'unprotect',
32+
],
2933
repository: [
3034
'getBranches',
3135
'protectBranch',
@@ -43,7 +47,10 @@ var properties = {
4347
'updateNote',
4448
],
4549
projects: [
46-
'getByPath'
50+
'getByPath',
51+
'listEvents',
52+
'fork',
53+
'search',
4754
],
4855
projectMembers: [],
4956
groups: [

lib/resources/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ module.exports = {
2424

2525
repository: require('./repository'),
2626

27+
repositoryBranches: require('./repository_branch'),
28+
2729
repositoryFiles: {
2830
resourcePath: '/projects/:id/repository/files'
2931
},
@@ -45,7 +47,6 @@ module.exports = {
4547
idName: 'hook_id'
4648
},
4749

48-
4950
milestones: require('./milestone'),
5051

5152
hooks: {

lib/resources/milestone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ function Milestone(client) {
2525
util.inherits(Milestone, restful.RESTFulResource);
2626

2727
Milestone.prototype.listIssues = function (params, callback) {
28-
this.client.request('get', '/projects/:id/milestones/:milestone_id/issues', params, callback);
28+
this.client.request('get', this.onePath + '/issues', params, callback);
2929
return this;
3030
};

lib/resources/project.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**!
22
* gitlab - lib/resources/project.js
33
*
4-
* Copyright(c) fengmk2 and other contributors.
4+
* Copyright(c) repo-utils and other contributors.
55
* MIT Licensed
66
*
77
* Authors:
8-
* fengmk2 <[email protected]> (http://fengmk2.github.com)
8+
* fengmk2 <[email protected]> (http://fengmk2.com)
99
*/
1010

1111
'use strict';
@@ -36,3 +36,15 @@ util.inherits(Project, restful.RESTFulResource);
3636
Project.prototype.getByPath = function (params, callback) {
3737
this.client.request('get', '/project', params, callback);
3838
};
39+
40+
Project.prototype.search = function (params, callback) {
41+
this.client.request('get', '/projects/search/:query', params, callback);
42+
};
43+
44+
Project.prototype.fork = function (params, callback) {
45+
this.client.request('post', '/projects/fork/:id', params, callback);
46+
};
47+
48+
Project.prototype.listEvents = function (params, callback) {
49+
this.client.request('get', this.onePath + '/events', params, callback);
50+
};

lib/resources/repository.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**!
22
* gitlab - lib/resources/repository.js
33
*
4-
* Copyright(c) fengmk2 and other contributors.
4+
* Copyright(c) repo-utils and other contributors.
55
* MIT Licensed
66
*
77
* Authors:
8-
* fengmk2 <[email protected]> (http://fengmk2.github.com)
8+
* fengmk2 <[email protected]> (http://fengmk2.com)
99
*/
1010

1111
'use strict';

lib/resources/repository_branch.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**!
2+
* gitlab - lib/resources/repository_branch.js
3+
*
4+
* Copyright(c) repo-utils and other contributors.
5+
* MIT Licensed
6+
*
7+
* Authors:
8+
* fengmk2 <[email protected]> (http://fengmk2.com)
9+
*/
10+
11+
'use strict';
12+
13+
/**
14+
* Module dependencies.
15+
*/
16+
17+
var util = require('util');
18+
var restful = require('restful-client');
19+
20+
module.exports = RepositoryBranch;
21+
22+
function RepositoryBranch(client) {
23+
this.constructor.super_.call(this, client, '/projects/:id/repository/branches', 'branch');
24+
}
25+
util.inherits(RepositoryBranch, restful.RESTFulResource);
26+
27+
RepositoryBranch.prototype.protect = function (params, callback) {
28+
this.client.request('put', this.this.onePath + '/protect', params, callback);
29+
return this;
30+
};
31+
32+
RepositoryBranch.prototype.unprotect = function (params, callback) {
33+
this.client.request('put', this.this.onePath + '/unprotect', params, callback);
34+
return this;
35+
};

test/gitlab.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ describe('gitlab.test.js', function () {
4343

4444
it('should request 404 error', function (done) {
4545
client.request('get', '/projects/:id/milestones', {id: 99999999}, function (err, milestones) {
46-
should.exists(err);
47-
err.name.should.equal('Gitlab404Error');
48-
err.message.should.equal('404 Not Found');
46+
should.not.exists(err);
4947
should.not.exists(milestones);
5048
done();
5149
});
@@ -55,7 +53,7 @@ describe('gitlab.test.js', function () {
5553
client.request('get', '/projects/:id/milestones', {id: 223, private_token: 'wrong'}, function (err, milestones) {
5654
should.exists(err);
5755
err.name.should.equal('Gitlab401Error');
58-
err.message.should.equal('401 Unauthorized');
56+
err.message.should.containEql('401 Unauthorized');
5957
should.not.exists(milestones);
6058
done();
6159
});
@@ -66,7 +64,7 @@ describe('gitlab.test.js', function () {
6664
function (err, milestones) {
6765
should.exists(err);
6866
err.name.should.equal('Gitlab405Error');
69-
err.message.should.equal('Unknow Error 405');
67+
err.message.should.containEql('Unknow Error 405');
7068
should.not.exists(milestones);
7169
done();
7270
});

test/milestone.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var client = require('./client');
1818
var should = require('should');
1919
var milestoneId;
2020

21-
describe.only('milestone.test.js', function () {
21+
describe('milestone.test.js', function () {
2222
before(function (done) {
2323
client.createProject(function (err) {
2424
if (err) {

test/project.test.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
/*!
2-
* gitlab - test/project.test.js
3-
* Copyright(c) 2012 fengmk2 <[email protected]>
1+
/**!
2+
* node-gitlab - test/project.test.js
3+
*
4+
* Copyright(c) repo-utils and other contributors.
45
* MIT Licensed
6+
*
7+
* Authors:
8+
* fengmk2 <[email protected]> (http://fengmk2.com)
59
*/
610

7-
"use strict";
11+
'use strict';
812

913
/**
1014
* Module dependencies.
@@ -56,6 +60,24 @@ describe('project.test.js', function () {
5660

5761
});
5862

63+
describe('listEvents()', function () {
64+
it('should list current project events', function* () {
65+
var events = yield client.thunk.projects.listEvents({id: client.id});
66+
events.length.should.above(0);
67+
events[0].action_name.should.equal('created');
68+
});
69+
});
70+
71+
describe('search()', function () {
72+
it('should search and list projects', function* () {
73+
var projects = yield client.thunk.projects.search({
74+
query: 'node-gitlab-test'
75+
});
76+
projects.length.should.equal(1);
77+
projects[0].name.should.equal('node-gitlab-test');
78+
});
79+
});
80+
5981
describe.skip('client.projects.getByPath()', function () {
6082
it('should return a project by path', function (done) {
6183
client.projects.getByPath({path: 'fengmk2/node-gitlab-test'}, function (err, project) {

0 commit comments

Comments
 (0)