Skip to content

Commit c67e84a

Browse files
committed
Merge pull request #7 from repo-utils/promise
Promise and thunk
2 parents 2cc8d98 + a7941d1 commit c67e84a

24 files changed

+393
-246
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ results
1414

1515
node_modules
1616
npm-debug.log
17+
coverage/

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ Makefile
55
.travis.yml
66
logo.png
77
.jshint*
8+
coverage/
9+
logo.png
10+
*.log

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
3-
- '0.10'
4-
script: make test-coveralls
3+
- '0.11'
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: 43 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,49 @@ 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+
var gitlab = require('node-gitlab');
59+
60+
var client = gitlab.createThunk({
61+
api: 'https://gitlab.com/api/v3',
62+
privateToken: 'your private token'
5063
});
64+
65+
co(function* () {
66+
var milestones = yield client.milestones.list({id: 1});
67+
})();
68+
```
69+
70+
### Promise way
71+
72+
Require node >= `0.11.13` or [bluebird](https://github.com/petkaantonov/bluebird):
73+
74+
```js
75+
var gitlab = require('node-gitlab');
76+
77+
var client = gitlab.createPromise({
78+
api: 'https://gitlab.com/api/v3',
79+
privateToken: 'your private token'
80+
});
81+
82+
client.milestones.list({id: 1})
83+
.then(function (milestones) {
84+
console.log(milestones);
85+
})
86+
.catch(function (err) {
87+
throw err;
88+
});
5189
```
5290

5391
## Document
@@ -259,7 +297,7 @@ Parameters:
259297

260298
(The MIT License)
261299

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

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

lib/gitlab.js

Lines changed: 25 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;
@@ -78,3 +52,13 @@ Gitlab.prototype.setAuthentication = function (req) {
7852
Gitlab.create = function (options) {
7953
return new Gitlab(options);
8054
};
55+
56+
Gitlab.createPromise = function (options) {
57+
var client = Gitlab.create(options);
58+
return require('./promisify')(client);
59+
};
60+
61+
Gitlab.createThunk = function (options) {
62+
var client = Gitlab.create(options);
63+
return require('./thunkify')(client);
64+
};

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/milestone.js

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

0 commit comments

Comments
 (0)