Skip to content

Commit d709f54

Browse files
committed
mv all resources to lib/resources
1 parent 2cc8d98 commit d709f54

20 files changed

+223
-229
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
33
- '0.10'
4-
script: make test-coveralls
4+
script: "npm run test-travis"
5+
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

LICENSE.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ gitlab
2424
[download-image]: https://img.shields.io/npm/dm/node-gitlab.svg?style=flat-square
2525
[download-url]: https://npmjs.org/package/node-gitlab
2626

27-
![logo](https://raw.github.com/repo-utils/gitlab/master/logo.png)
28-
29-
Gitlab API nodejs client.
27+
Gitlab API Node.js client
3028

3129
* [Gitlab API document](https://github.com/gitlabhq/gitlabhq/tree/master/doc/api)
3230

@@ -45,9 +43,41 @@ var client = gitlab.create({
4543
api: 'https://gitlab.com/api/v3',
4644
privateToken: 'your private token'
4745
});
46+
4847
client.milestones.list({id: 1}, function (err, milestones) {
49-
console.log(milestones);
48+
console.log(err, milestones);
49+
});
50+
```
51+
52+
### Thunk way
53+
54+
Require [co](https://github.com/visionmedia/co) and node >= `0.11.12`:
55+
56+
```js
57+
var co = require('co');
58+
59+
co(function* () {
60+
var milestones = yield client.milestones.list({id: 1});
61+
})();
62+
```
63+
64+
### Promise way
65+
66+
```js
67+
var gitlab = require('node-gitlab');
68+
69+
var client = gitlab.createPromise({
70+
api: 'https://gitlab.com/api/v3',
71+
privateToken: 'your private token'
5072
});
73+
74+
client.milestones.list({id: 1})
75+
.then(function (milestones) {
76+
console.log(milestones);
77+
})
78+
.catch(function (err) {
79+
throw err;
80+
});
5181
```
5282

5383
## Document
@@ -259,7 +289,7 @@ Parameters:
259289

260290
(The MIT License)
261291

262-
Copyright (c) 2013 - 2014 fengmk2 <fengmk2@gmail.com>
292+
Copyright (c) 2013 - 2014 fengmk2 <fengmk2@gmail.com>
263293

264294
Permission is hereby granted, free of charge, to any person obtaining
265295
a copy of this software and associated documentation files (the

lib/gitlab.js

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
/*!
1+
/**!
22
* gitlab - lib/gitlab.js
3-
* Copyright(c) 2012 - 2013 fengmk2 <[email protected]>
3+
*
4+
* Copyright(c) fengmk2 and other contributors.
45
* MIT Licensed
6+
*
7+
* Authors:
8+
* fengmk2 <[email protected]> (http://fengmk2.github.com)
59
*/
610

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

913
/**
1014
* Module dependencies.
1115
*/
1216

1317
var debug = require('debug')('gitlab');
14-
var restful = require('restful-client');
18+
var RESTFulClient = require('restful-client').RESTFulClient;
1519
var util = require('util');
16-
var Milestone = require('./milestone');
17-
var Project = require('./project');
18-
var Member = require('./member');
19-
var GlobalHook = require('./globalHook.js');
20-
var Issue = require('./issue');
21-
var User = require('./user');
22-
var Repository = require('./repository');
23-
var MergeRequest = require('./merge_request');
24-
var RepositoryFile = require('./repository_file');
25-
var Group = require('./group');
20+
var resources = require('./resources');
2621

2722
module.exports = Gitlab;
2823

@@ -36,39 +31,18 @@ module.exports = Gitlab;
3631
function Gitlab(options) {
3732
options = options || {};
3833
options.api = options.api || 'https://gitlab.com/api/v3';
39-
restful.RESTFulClient.call(this, options);
40-
34+
RESTFulClient.call(this, options);
4135
this.privateToken = options.privateToken;
4236

43-
this.addResources({
44-
projects: Project,
45-
projectMembers: {
46-
resourcePath: '/projects/:id/members',
47-
idName: 'user_id',
48-
},
49-
repository: Repository,
50-
repositoryFiles: RepositoryFile,
51-
mergeRequests: MergeRequest,
52-
users: User,
53-
issues: Issue,
54-
globalHooks: GlobalHook,
55-
members: Member,
56-
milestones: Milestone,
57-
hooks: {
58-
resourcePath: '/projects/:id/hooks',
59-
idName: 'hook_id',
60-
},
61-
groupMembers: {
62-
resourcePath: '/groups/:id/members',
63-
idName: 'user_id',
64-
},
65-
groups: Group
66-
});
37+
this.addResources(resources);
6738

39+
// mergeRequests => merge_requests
6840
this.merge_requests = this.mergeRequests;
41+
// members => projectMembers
42+
this.members = this.projectMembers;
6943
}
7044

71-
util.inherits(Gitlab, restful.RESTFulClient);
45+
util.inherits(Gitlab, RESTFulClient);
7246

7347
Gitlab.prototype.setAuthentication = function (req) {
7448
req.params.data.private_token = req.params.data.private_token || this.privateToken;

lib/globalHook.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/member.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/merge_request.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/methods.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**!
2+
* gitlab - lib/methods.js
3+
*
4+
* Copyright(c) fengmk2 and other contributors.
5+
* MIT Licensed
6+
*
7+
* Authors:
8+
* fengmk2 <[email protected]> (http://fengmk2.github.com)
9+
*/
10+
11+
'use strict';
12+
13+
/**
14+
* Module dependencies.
15+
*/
16+
17+
var defaultMethods = ['get', 'list', 'create', 'update', 'remove'];
18+
19+
var methods = {
20+
milestones: [],
21+
members: [],
22+
hooks: [],
23+
globalHooks: [],
24+
users: [],
25+
mergeRequests: [],
26+
repositoryFiles: [],
27+
repository: [
28+
'getBranches',
29+
'protectBranch',
30+
'unprotectBranch',
31+
'getBranch',
32+
'getTags',
33+
'getCommits',
34+
'getTree',
35+
'getBlob'
36+
],
37+
issues: [
38+
'listNotes',
39+
'createNote'
40+
],
41+
projects: [
42+
'getByPath'
43+
],
44+
projectMembers: [],
45+
groups: [],
46+
groupMembers: [],
47+
};
48+
49+
methods.forEach(function (apis) {
50+
apis = defaultMethods.concat(apis);
51+
});
52+
53+
module.exports = methods;

lib/milestone.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/promisify.js

Whitespace-only changes.

0 commit comments

Comments
 (0)