diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..13377d7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +node_modules/* +coverage/* +.tmp/* +.git/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..cf75188 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,66 @@ +{ + "extends": 'usecases/usecase/nodejs', + "env": { + "browser": true, + "node": true + }, + "globals": { + "describe": true, + "it": true, + "before": true, + "afterEach": true, + "beforeEach": true, + "after": true + }, + "rules": { + "global-require": 0, + "no-bitwise": 2, + "camelcase": 0, + "curly": 2, + "eqeqeq": 2, + "guard-for-in": 0, + "wrap-iife": 0, + "indent": 0, + "no-use-before-define": 0, + "new-cap": 0, + "no-caller": 2, + "no-empty": 2, + "no-new": 0, + "no-plusplus": 0, + "quotes": 0, + "no-undef": 2, + "no-unused-vars": 0, + "strict": 0, + "max-params": 0, + "max-depth": 0, + "max-statements": 0, + "complexity": 0, + "max-len": 0, + "semi": 0, + "no-cond-assign": [ + 2, + "except-parens" + ], + "no-debugger": 0, + "no-eq-null": 0, + "no-eval": 0, + "no-unused-expressions": 2, + "block-scoped-var": 0, + "no-iterator": 0, + "linebreak-style": 2, + "comma-style": [ + 2, + "first" + ], + "no-loop-func": 0, + "no-multi-str": 2, + "no-proto": 0, + "no-script-url": 0, + "no-shadow": 0, + "dot-notation": 2, + "no-new-func": 0, + "no-new-wrappers": 0, + "no-invalid-this": 2, + "require-yield": 2 + } +} diff --git a/lib/gitlab.js b/lib/gitlab.js index 9871775..1acbe1c 100644 --- a/lib/gitlab.js +++ b/lib/gitlab.js @@ -14,10 +14,10 @@ * Module dependencies. */ -var debug = require('debug')('gitlab'); -var RESTFulClient = require('restful-client').RESTFulClient; -var util = require('util'); -var resources = require('./resources'); +let debug = require('debug')('gitlab'); +let RESTFulClient = require('restful-client').RESTFulClient; +let util = require('util'); +let resources = require('./resources'); module.exports = Gitlab; @@ -44,21 +44,21 @@ function Gitlab(options) { util.inherits(Gitlab, RESTFulClient); -Gitlab.prototype.setAuthentication = function (req) { +Gitlab.prototype.setAuthentication = function(req) { req.params.data.private_token = req.params.data.private_token || this.privateToken; return req; }; -Gitlab.create = function (options) { +Gitlab.create = function(options) { return new Gitlab(options); }; -Gitlab.createPromise = function (options) { - var client = Gitlab.create(options); +Gitlab.createPromise = function(options) { + let client = Gitlab.create(options); return require('./promisify')(client); }; -Gitlab.createThunk = function (options) { - var client = Gitlab.create(options); +Gitlab.createThunk = function(options) { + let client = Gitlab.create(options); return require('./thunkify')(client); }; diff --git a/lib/promisify.js b/lib/promisify.js index c1382a8..6102761 100644 --- a/lib/promisify.js +++ b/lib/promisify.js @@ -15,20 +15,20 @@ */ /* jshint ignore:start */ -var Promise = require('any-promise'); +let Promise = require('any-promise'); /* jshint ignore:end */ -var properties = require('./properties'); +let properties = require('./properties'); module.exports = promisifyAll; function promisifyAll(source) { - var target = { + let target = { request: promisify('request', source.request.bind(source)) }; - Object.keys(properties).forEach(function (name) { - var methods = properties[name]; + Object.keys(properties).forEach((name) => { + let methods = properties[name]; target[name] = {}; - methods.forEach(function (method) { + methods.forEach((method) => { target[name][method] = promisify(method, source[name][method].bind(source[name])); }); }); @@ -50,7 +50,7 @@ function promisify(name, fn) { } function makeCallback(resolve, reject) { - return function (err, result) { + return function(err, result) { if (err) { reject(err); } else { diff --git a/lib/properties.js b/lib/properties.js index ff15cf9..45f3812 100644 --- a/lib/properties.js +++ b/lib/properties.js @@ -14,62 +14,62 @@ * Module dependencies. */ -var defaultMethods = ['get', 'list', 'create', 'update', 'remove']; +let defaultMethods = ['get', 'list', 'create', 'update', 'remove']; -var properties = { +let properties = { milestones: [ - 'listIssues', - ], - members: [], - hooks: [], - globalHooks: [], - users: [], - mergeRequests: [ - 'listNotes', - 'createNote', - 'getNote', - 'updateNote', - 'merge' - ], - repositoryFiles: [], - repositoryBranches: [ - 'protect', - 'unprotect', - ], - repository: [ - 'getBranches', - 'protectBranch', - 'unprotectBranch', - 'getBranch', - 'getTags', - 'getCommits', - 'getTree', - 'getBlob', - 'archive', - 'compare' - ], - issues: [ - 'listNotes', - 'createNote', - 'getNote', - 'updateNote' - ], - projects: [ - 'getByPath', - 'listEvents', - 'fork', - 'search', - ], - deployKeys: [], - projectMembers: [], - groups: [ + 'listIssues' + ] + , members: [] + , hooks: [] + , globalHooks: [] + , users: [] + , mergeRequests: [ + 'listNotes' + , 'createNote' + , 'getNote' + , 'updateNote' + , 'merge' + ] + , repositoryFiles: [] + , repositoryBranches: [ + 'protect' + , 'unprotect' + ] + , repository: [ + 'getBranches' + , 'protectBranch' + , 'unprotectBranch' + , 'getBranch' + , 'getTags' + , 'getCommits' + , 'getTree' + , 'getBlob' + , 'archive' + , 'compare' + ] + , issues: [ + 'listNotes' + , 'createNote' + , 'getNote' + , 'updateNote' + ] + , projects: [ + 'getByPath' + , 'listEvents' + , 'fork' + , 'search' + ] + , deployKeys: [] + , projectMembers: [] + , groups: [ 'transferProject' - ], - groupMembers: [], + ] + , groupMembers: [], }; -for (var key in properties) { - var methods = properties[key]; +for (let key in properties) { + let methods = properties[key]; properties[key] = defaultMethods.concat(methods); } diff --git a/lib/resources/group.js b/lib/resources/group.js index ea0ea8d..1889930 100644 --- a/lib/resources/group.js +++ b/lib/resources/group.js @@ -14,8 +14,8 @@ * Module dependencies. */ -var util = require('util'); -var restful = require('restful-client'); +let util = require('util'); +let restful = require('restful-client'); module.exports = Group; @@ -34,7 +34,7 @@ util.inherits(Group, restful.RESTFulResource); * - {String} project_id project id * @param {Function(err, project)} callback */ -Group.prototype.transferProject = function (params, callback) { +Group.prototype.transferProject = function(params, callback) { this.client.request('post', '/groups/:id/projects/:project_id', params, callback); return this; }; diff --git a/lib/resources/index.js b/lib/resources/index.js index 7f67a0a..3651c5d 100644 --- a/lib/resources/index.js +++ b/lib/resources/index.js @@ -15,51 +15,51 @@ */ module.exports = { - projects: require('./project'), + projects: require('./project') - projectMembers: { - resourcePath: '/projects/:id/members', - idName: 'user_id', - }, + , projectMembers: { + resourcePath: '/projects/:id/members' + , idName: 'user_id', + } - repository: require('./repository'), + , repository: require('./repository') - repositoryBranches: require('./repository_branch'), + , repositoryBranches: require('./repository_branch') - repositoryFiles: { + , repositoryFiles: { resourcePath: '/projects/:id/repository/files' - }, + } - mergeRequests: require('./merge_request'), + , mergeRequests: require('./merge_request') - users: { - resourcePath: '/users', - idName: 'user_id' - }, + , users: { + resourcePath: '/users' + , idName: 'user_id' + } - issues: require('./issue'), + , issues: require('./issue') - globalHooks: { - resourcePath: '/hooks', - idName: 'hook_id' - }, + , globalHooks: { + resourcePath: '/hooks' + , idName: 'hook_id' + } - milestones: require('./milestone'), + , milestones: require('./milestone') - hooks: { - resourcePath: '/projects/:id/hooks', - idName: 'hook_id', - }, + , hooks: { + resourcePath: '/projects/:id/hooks' + , idName: 'hook_id', + } - groups: require('./group'), + , groups: require('./group') - groupMembers: { - resourcePath: '/groups/:id/members', - idName: 'user_id', - }, + , groupMembers: { + resourcePath: '/groups/:id/members' + , idName: 'user_id', + } - deployKeys: { - resourcePath: '/projects/:id/keys', - idName: 'key_id', + , deployKeys: { + resourcePath: '/projects/:id/keys' + , idName: 'key_id', }, }; diff --git a/lib/resources/issue.js b/lib/resources/issue.js index 83630d8..91241ef 100644 --- a/lib/resources/issue.js +++ b/lib/resources/issue.js @@ -14,8 +14,8 @@ * Module dependencies. */ -var util = require('util'); -var RESTFulResource = require('restful-client').RESTFulResource; +let util = require('util'); +let RESTFulResource = require('restful-client').RESTFulResource; module.exports = Issue; @@ -24,18 +24,18 @@ function Issue(client) { } util.inherits(Issue, RESTFulResource); -Issue.prototype.listNotes = function (params, callback) { +Issue.prototype.listNotes = function(params, callback) { this.client.request('get', this.onePath + '/notes', params, callback); }; -Issue.prototype.createNote = function (params, callback) { +Issue.prototype.createNote = function(params, callback) { this.client.request('post', this.onePath + '/notes', params, callback); }; -Issue.prototype.getNote = function (params, callback) { +Issue.prototype.getNote = function(params, callback) { this.client.request('get', this.onePath + '/notes/:note_id', params, callback); }; -Issue.prototype.updateNote = function (params, callback) { +Issue.prototype.updateNote = function(params, callback) { this.client.request('put', this.onePath + '/notes/:note_id', params, callback); }; diff --git a/lib/resources/merge_request.js b/lib/resources/merge_request.js index ce14237..9e71fc7 100644 --- a/lib/resources/merge_request.js +++ b/lib/resources/merge_request.js @@ -1,7 +1,7 @@ 'use strict'; -var util = require('util'); -var RESTFulResource = require('restful-client').RESTFulResource; +let util = require('util'); +let RESTFulResource = require('restful-client').RESTFulResource; module.exports = MergeRequest; @@ -10,26 +10,26 @@ function MergeRequest(client) { } util.inherits(MergeRequest, RESTFulResource); -MergeRequest.prototype.listNotes = function (params, callback) { +MergeRequest.prototype.listNotes = function(params, callback) { this.client.request('get', this.onePath + '/notes', params, callback); }; -MergeRequest.prototype.createNote = function (params, callback) { +MergeRequest.prototype.createNote = function(params, callback) { this.client.request('post', this.onePath + '/notes', params, callback); }; -MergeRequest.prototype.getNote = function (params, callback) { +MergeRequest.prototype.getNote = function(params, callback) { this.client.request('get', this.onePath + '/notes/:note_id', params, callback); }; -MergeRequest.prototype.updateNote = function (params, callback) { +MergeRequest.prototype.updateNote = function(params, callback) { this.client.request('put', this.onePath + '/notes/:note_id', params, callback); }; -MergeRequest.prototype.merge = function (params, callback) { +MergeRequest.prototype.merge = function(params, callback) { this.client.request('put', this.onePath + '/merge', params, callback); }; -MergeRequest.prototype.listCommits = function (params, callback) { +MergeRequest.prototype.listCommits = function(params, callback) { this.client.request('get', this.onePath + '/commits', params, callback); } diff --git a/lib/resources/milestone.js b/lib/resources/milestone.js index fb7e483..e9b01cf 100644 --- a/lib/resources/milestone.js +++ b/lib/resources/milestone.js @@ -14,8 +14,8 @@ * Module dependencies. */ -var util = require('util'); -var restful = require('restful-client'); +let util = require('util'); +let restful = require('restful-client'); module.exports = Milestone; @@ -24,7 +24,7 @@ function Milestone(client) { } util.inherits(Milestone, restful.RESTFulResource); -Milestone.prototype.listIssues = function (params, callback) { +Milestone.prototype.listIssues = function(params, callback) { this.client.request('get', this.onePath + '/issues', params, callback); return this; }; diff --git a/lib/resources/project.js b/lib/resources/project.js index 2df2b04..8af954a 100644 --- a/lib/resources/project.js +++ b/lib/resources/project.js @@ -14,8 +14,8 @@ * Module dependencies. */ -var util = require('util'); -var restful = require('restful-client'); +let util = require('util'); +let restful = require('restful-client'); module.exports = Project; @@ -33,27 +33,27 @@ util.inherits(Project, restful.RESTFulResource); * - {String} path * @param {Function(err, project)} callback */ -Project.prototype.getByPath = function (params, callback) { +Project.prototype.getByPath = function(params, callback) { this.client.request('get', '/project', params, callback); }; -Project.prototype.search = function (params, callback) { +Project.prototype.search = function(params, callback) { this.client.request('get', '/projects/search/:query', params, callback); }; -Project.prototype.fork = function (params, callback) { +Project.prototype.fork = function(params, callback) { this.client.request('post', '/projects/fork/:id', params, callback); }; -Project.prototype.listEvents = function (params, callback) { +Project.prototype.listEvents = function(params, callback) { this.client.request('get', this.onePath + '/events', params, callback); }; -Project.prototype.getLabels = function (params, callback) { +Project.prototype.getLabels = function(params, callback) { this.client.request('get', this.onePath + '/labels', params, callback); }; -Project.prototype.createLabel = function (params, callback) { +Project.prototype.createLabel = function(params, callback) { this.client.request('post', this.onePath + '/labels', params, callback); }; diff --git a/lib/resources/repository.js b/lib/resources/repository.js index d337f74..5e4a126 100644 --- a/lib/resources/repository.js +++ b/lib/resources/repository.js @@ -14,8 +14,8 @@ * Module dependencies. */ -var util = require('util'); -var restful = require('restful-client'); +let util = require('util'); +let restful = require('restful-client'); module.exports = Repository; @@ -31,7 +31,7 @@ util.inherits(Repository, restful.RESTFulResource); * - {String} id The ID of a project * @param {Function} callback */ -Repository.prototype.getBranches = function (params, callback) { +Repository.prototype.getBranches = function(params, callback) { params.type = 'branches'; this.list(params, callback); }; @@ -46,7 +46,7 @@ Repository.prototype.getBranches = function (params, callback) { * - {String} branch The name of the branch * @param {Function} callback */ -Repository.prototype.protectBranch = function (params, callback) { +Repository.prototype.protectBranch = function(params, callback) { params.type = 'branches'; this.client.request('PUT', this.path + '/:branch/protect', params, callback); }; @@ -61,7 +61,7 @@ Repository.prototype.protectBranch = function (params, callback) { * - {String} branch The name of the branch * @param {Function} callback */ -Repository.prototype.unprotectBranch = function (params, callback) { +Repository.prototype.unprotectBranch = function(params, callback) { params.type = 'branches'; this.client.request('PUT', this.path + '/:branch/unprotect', params, callback); }; @@ -74,7 +74,7 @@ Repository.prototype.unprotectBranch = function (params, callback) { * - {String} branch The name of the branch * @param {Function} callback */ -Repository.prototype.getBranch = function (params, callback) { +Repository.prototype.getBranch = function(params, callback) { params.type = 'branches'; this.client.request('get', this.path + '/:branch', params, callback); }; @@ -86,7 +86,7 @@ Repository.prototype.getBranch = function (params, callback) { * - {String} id The ID of a project * @param {Function} callback */ -Repository.prototype.getTags = function (params, callback) { +Repository.prototype.getTags = function(params, callback) { params.type = 'tags'; this.list(params, callback); }; @@ -99,7 +99,7 @@ Repository.prototype.getTags = function (params, callback) { * - {String} [ref_name] The name of a repository branch or tag or if not given the default branch * @param {Function} callback */ -Repository.prototype.getCommits = function (params, callback) { +Repository.prototype.getCommits = function(params, callback) { params.type = 'commits'; this.list(params, callback); }; @@ -113,7 +113,7 @@ Repository.prototype.getCommits = function (params, callback) { * - {String} [ref_name] The name of a repository branch or tag or if not given the default branch * @param {Function} callback */ -Repository.prototype.getTree = function (params, callback) { +Repository.prototype.getTree = function(params, callback) { params.type = 'tree'; this.list(params, callback); }; @@ -127,7 +127,7 @@ Repository.prototype.getTree = function (params, callback) { * - {String} filepath The path the file * @param {Function} callback */ -Repository.prototype.getBlob = function (params, callback) { +Repository.prototype.getBlob = function(params, callback) { params.type = 'commits'; params.contentType = 'buffer'; this.client.request('get', this.path + '/:sha/blob', params, callback); @@ -141,7 +141,7 @@ Repository.prototype.getBlob = function (params, callback) { * - {String} sha The blob sha * @param {Function} callback */ -Repository.prototype.getRawBlob = function (params, callback) { +Repository.prototype.getRawBlob = function(params, callback) { params.type = 'raw_blobs'; params.contentType = 'buffer'; this.client.request('get', this.path + '/:sha', params, callback); @@ -159,7 +159,7 @@ Repository.prototype.getRawBlob = function (params, callback) { * @param {Function} callback */ -Repository.prototype.createTag = function (params, callback) { +Repository.prototype.createTag = function(params, callback) { params.type = 'tags'; this.client.request('POST', this.path, params, callback); }; @@ -173,7 +173,7 @@ Repository.prototype.createTag = function (params, callback) { * - {String} sha The repo sha * @param {Function} callback */ -Repository.prototype.archive = function (params, callback) { +Repository.prototype.archive = function(params, callback) { params.type = 'archive'; params.contentType = 'buffer'; this.client.request('get', this.path, params, callback); @@ -188,7 +188,7 @@ Repository.prototype.archive = function (params, callback) { * - {String} to (required) - the commit SHA or branch name * @param {Function} callback */ -Repository.prototype.compare = function (params, callback) { +Repository.prototype.compare = function(params, callback) { params.type = 'compare'; this.client.request('get', this.path, params, callback); }; diff --git a/lib/resources/repository_branch.js b/lib/resources/repository_branch.js index 638e0cd..37390d1 100644 --- a/lib/resources/repository_branch.js +++ b/lib/resources/repository_branch.js @@ -14,8 +14,8 @@ * Module dependencies. */ -var util = require('util'); -var restful = require('restful-client'); +let util = require('util'); +let restful = require('restful-client'); module.exports = RepositoryBranch; @@ -24,12 +24,12 @@ function RepositoryBranch(client) { } util.inherits(RepositoryBranch, restful.RESTFulResource); -RepositoryBranch.prototype.protect = function (params, callback) { +RepositoryBranch.prototype.protect = function(params, callback) { this.client.request('put', this.this.onePath + '/protect', params, callback); return this; }; -RepositoryBranch.prototype.unprotect = function (params, callback) { +RepositoryBranch.prototype.unprotect = function(params, callback) { this.client.request('put', this.this.onePath + '/unprotect', params, callback); return this; }; diff --git a/lib/thunkify.js b/lib/thunkify.js index 67ce1e9..4649753 100644 --- a/lib/thunkify.js +++ b/lib/thunkify.js @@ -14,13 +14,13 @@ * Module dependencies. */ -var thunkify = require('thunkify-wrap'); -var properties = require('./properties'); +let thunkify = require('thunkify-wrap'); +let properties = require('./properties'); -module.exports = function (client) { +module.exports = function(client) { thunkify(client, 'request'); - for (var key in properties) { - var methods = properties[key]; + for (let key in properties) { + let methods = properties[key]; thunkify(client[key], methods); } return client; diff --git a/package.json b/package.json index 7ab40cf..375c743 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test": "mocha --harmony -R spec -r co-mocha -t 40000 test/*.test.js", "test-cov": "node --harmony node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -r co-mocha -t 40000 test/*.test.js", "test-travis": "node --harmony node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- -r co-mocha -t 40000 test/*.test.js", - "jshint": "jshint .", + "eslint": "eslint .", + "eslint:fix": "eslint --fix .", "autod": "autod -w --prefix '~'", "cnpm": "npm install --registry=https://registry.npm.taobao.org", "contributors": "contributors -f plain -o AUTHORS" @@ -22,6 +23,8 @@ "autod": "*", "co-mocha": "*", "contributors": "*", + "eslint": "5.15.0", + "eslint-config-usecases": "1.3.0", "istanbul-harmony": "*", "mocha": "*", "objectid": "^3.2.1", diff --git a/test/client.js b/test/client.js index 692da97..390aa2d 100644 --- a/test/client.js +++ b/test/client.js @@ -14,16 +14,16 @@ * Module dependencies. */ -var objectid = require('objectid'); +let objectid = require('objectid'); -var gitlab = require('../'); -var config = require('./config'); +let gitlab = require('../'); +let config = require('./config'); -var client = gitlab.create(config); +let client = gitlab.create(config); -client.createProject = function (callback) { - client.projectName = 'node-gitlab-test-'+objectid(); - client._list(function (err) { +client.createProject = function(callback) { + client.projectName = 'node-gitlab-test-' + objectid(); + client._list((err) => { if (err) { return client._create(callback); } @@ -31,12 +31,12 @@ client.createProject = function (callback) { }); }; -client._list = function (callback) { - client.request('get', '/projects', {}, function (err, repos) { +client._list = function(callback) { + client.request('get', '/projects', {}, (err, repos) => { if (err) { return callback(err); } - for (var i = 0; i < repos.length; i++) { + for (let i = 0; i < repos.length; i++) { if (repos[i].name.indexOf('node-gitlab-test') === 0) { client.projectName = repos[i].name; client.id = repos[i].id; @@ -48,13 +48,13 @@ client._list = function (callback) { }; client._create = function(callback) { - client.projectName = 'node-gitlab-test-'+objectid(); + client.projectName = 'node-gitlab-test-' + objectid(); client.projects.create({ - name: client.projectName, - issues_enabled: true, - merge_requests_enabled: true, - public: true - }, function (err, data) { + name: client.projectName + , issues_enabled: true + , merge_requests_enabled: true + , public: true + }, (err, data) => { if (err) { return callback(err); } @@ -63,13 +63,13 @@ client._create = function(callback) { }); }; -client.removeProject = function (callback) { - if(!client.id) { +client.removeProject = function(callback) { + if (!client.id) { return callback(); } client.projects.remove({ id: client.id - }, function () { + }, () => { delete client.id; callback(); }); diff --git a/test/config.js b/test/config.js index 5bfb4a1..305a99f 100644 --- a/test/config.js +++ b/test/config.js @@ -1,5 +1,5 @@ module.exports = { - api: process.env.NODE_GITLAB_API || 'https://gitlab.com/api/v3', - privateToken: process.env.NODE_GITLAB_TOKEN || 'enEWf516mA168tP6BiVe', - requestTimeout: 30000, + api: process.env.NODE_GITLAB_API || 'https://gitlab.com/api/v3' + , privateToken: process.env.NODE_GITLAB_TOKEN || 'enEWf516mA168tP6BiVe' + , requestTimeout: 30000, }; diff --git a/test/gitlab.test.js b/test/gitlab.test.js index 50db1cb..a4484d9 100644 --- a/test/gitlab.test.js +++ b/test/gitlab.test.js @@ -14,22 +14,22 @@ * Module dependencies. */ -var should = require('should'); -var client = require('./client'); +let should = require('should'); +let client = require('./client'); -describe('gitlab.test.js', function () { - describe('Client.request()', function () { - it('should request success', function (done) { - client.request('get', '/projects', {}, function (err, projects) { +describe('gitlab.test.js', () => { + describe('Client.request()', () => { + it('should request success', (done) => { + client.request('get', '/projects', {}, (err, projects) => { should.not.exists(err); projects.length.should.above(0); done(); }); }); - it('should request with promise way success', function (done) { + it('should request with promise way success', (done) => { client.promise.request('get', '/projects', {}) - .then(function (projects) { + .then((projects) => { projects.length.should.above(0); done(); }) @@ -37,20 +37,20 @@ describe('gitlab.test.js', function () { }); it('should request with thunk way success', function* () { - var projects = yield client.thunk.request('get', '/projects', {}); + let projects = yield client.thunk.request('get', '/projects', {}); projects.length.should.above(0); }); - it('should request 404 error', function (done) { - client.request('get', '/projects/:id/milestones', {id: 99999999}, function (err, milestones) { + it('should request 404 error', (done) => { + client.request('get', '/projects/:id/milestones', {id: 99999999}, (err, milestones) => { should.exists(err); should.not.exists(milestones); done(); }); }); - it('should request 401 error when token wrong', function (done) { - client.request('get', '/projects/:id/milestones', {id: 223, private_token: 'wrong'}, function (err, milestones) { + it('should request 401 error when token wrong', (done) => { + client.request('get', '/projects/:id/milestones', {id: 223, private_token: 'wrong'}, (err, milestones) => { should.exists(err); err.name.should.equal('Gitlab401Error'); err.message.should.containEql('401 Unauthorized'); @@ -59,9 +59,9 @@ describe('gitlab.test.js', function () { }); }); - it.skip('should request 405 error when method wrong', function (done) { + it.skip('should request 405 error when method wrong', (done) => { client.request('post', '/projects/:id/milestones/:milestone_id', {id: 1909028, milestone_id: 120370, title: '123'}, - function (err, milestones) { + (err, milestones) => { should.exists(err); err.name.should.equal('Gitlab405Error'); err.message.should.containEql('Unknow Error 405'); diff --git a/test/hook.test.js b/test/hook.test.js index a58d56a..0d31df7 100644 --- a/test/hook.test.js +++ b/test/hook.test.js @@ -7,24 +7,24 @@ * Authors: * fengmk2 (http://fengmk2.com) */ - +/* eslint-disable no-unused-expressions */ 'use strict'; /** * Module dependencies. */ -var should = require('should'); -var client = require('./client'); +let should = require('should'); +let client = require('./client'); -var hookId; -describe('hook.test.js', function () { - before(function (done) { - client.createProject(function (err) { +let hookId; +describe('hook.test.js', () => { + before((done) => { + client.createProject((err) => { client.hooks.create({ - id: client.id, - url: 'http://gitlab.com/help/api' - }, function (err, data) { + id: client.id + , url: 'http://gitlab.com/help/api' + }, (err, data) => { if (err) { return done(err); } @@ -34,21 +34,21 @@ describe('hook.test.js', function () { }); }); - after(function (done) { + after((done) => { client.hooks.remove({ - id: client.id, - hook_id: hookId - }, function (err) { + id: client.id + , hook_id: hookId + }, (err) => { should.not.exist(err); - client.removeProject(function () { + client.removeProject(() => { done(); }); }); }); - describe('client.hooks.get()', function () { + describe('client.hooks.get()', () => { it('should return a hook', function* () { - var hook = yield client.thunk.hooks.get({ id: client.id, hook_id: hookId }); + let hook = yield client.thunk.hooks.get({id: client.id, hook_id: hookId}); hook.id.should.equal(hookId); hook.should.have.keys('id', 'url', 'created_at', 'project_id', 'push_events', 'issues_events', 'merge_requests_events', 'tag_push_events', 'note_events', @@ -57,11 +57,11 @@ describe('hook.test.js', function () { }); }); - describe('client.hooks.list()', function () { + describe('client.hooks.list()', () => { it('should return hooks', function* () { - var hooks = yield client.thunk.hooks.list({id: client.id}); + let hooks = yield client.thunk.hooks.list({id: client.id}); hooks.length.should.above(0); - var hook = hooks[0]; + let hook = hooks[0]; hook.should.have.keys('id', 'url', 'created_at', 'project_id', 'push_events', 'issues_events', 'merge_requests_events', 'tag_push_events', 'note_events', 'build_events', @@ -69,22 +69,22 @@ describe('hook.test.js', function () { }); }); - describe('client.hooks.create(), update(), remove()', function () { + describe('client.hooks.create(), update(), remove()', () => { it('should create, update, remove a hook', function* () { - var hook = yield client.thunk.hooks.create({ - id: client.id, - url: 'http://gitlab.com/help/api' + let hook = yield client.thunk.hooks.create({ + id: client.id + , url: 'http://gitlab.com/help/api' }); hook.url.should.equal('http://gitlab.com/help/api'); - var hook = yield client.thunk.hooks.update({ - id: client.id, - hook_id: hook.id, - url: hook.url + '/update', - merge_requests_events: true, - push_events: true, - issues_events: true, - tag_push_events: true, + hook = yield client.thunk.hooks.update({ + id: client.id + , hook_id: hook.id + , url: hook.url + '/update' + , merge_requests_events: true + , push_events: true + , issues_events: true + , tag_push_events: true, }); hook.url.should.equal('http://gitlab.com/help/api/update'); hook.merge_requests_events.should.equal(true); @@ -95,9 +95,9 @@ describe('hook.test.js', function () { // url required try { yield client.thunk.hooks.update({ - id: client.id, - hook_id: hook.id, - issues_events: false, + id: client.id + , hook_id: hook.id + , issues_events: false, }); throw new Error('should not run this'); } catch (err) { @@ -108,7 +108,7 @@ describe('hook.test.js', function () { yield client.thunk.hooks.remove({id: client.id, hook_id: hook.id}); try { - var hook = yield client.thunk.hooks.get({id: client.id, hook_id: hook.id}); + let hook = yield client.thunk.hooks.get({id: client.id, hook_id: hook.id}); } catch (err) { err.name.should.equal('Gitlab404Error'); } diff --git a/test/issue.test.js b/test/issue.test.js index 814ab8b..3e2430f 100644 --- a/test/issue.test.js +++ b/test/issue.test.js @@ -10,19 +10,19 @@ * Module dependencies. */ -var client = require('./client'); -var should = require('should'); +let client = require('./client'); +let should = require('should'); -var issueId; -describe('issue.test.js', function () { - before(function (done) { - client.createProject(function (err) { +let issueId; +describe('issue.test.js', () => { + before((done) => { + client.createProject((err) => { client.issues.create({ - id: client.id, - title: 'test title ' + new Date(), - description: '测试 `markdown` \n [abc](/abc)', - labels: 'test,gitlabapi' - }, function (err, data) { + id: client.id + , title: 'test title ' + new Date() + , description: '测试 `markdown` \n [abc](/abc)' + , labels: 'test,gitlabapi' + }, (err, data) => { if (err) { return done(err); } @@ -34,9 +34,9 @@ describe('issue.test.js', function () { after(client.removeProject); - describe('client.issues.get()', function () { - it('should return a issue', function (done) { - client.issues.get({id: client.id, issue_id: issueId}, function (err, row) { + describe('client.issues.get()', () => { + it('should return a issue', (done) => { + client.issues.get({id: client.id, issue_id: issueId}, (err, row) => { should.not.exists(err); row.id.should.equal(issueId); row.should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'labels', @@ -46,9 +46,9 @@ describe('issue.test.js', function () { }); }); - it('should return issue with promise way', function (done) { + it('should return issue with promise way', (done) => { client.promise.issues.get({id: client.id, issue_id: issueId}) - .then(function (row) { + .then((row) => { row.id.should.equal(issueId); row.should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'labels', 'milestone', 'assignee', 'author', 'state', 'updated_at', 'created_at', @@ -59,7 +59,7 @@ describe('issue.test.js', function () { }); it('should return issue with thunk way', function* () { - var row = yield client.thunk.issues.get({id: client.id, issue_id: issueId}); + let row = yield client.thunk.issues.get({id: client.id, issue_id: issueId}); row.id.should.equal(issueId); row.should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'labels', 'milestone', 'assignee', 'author', 'state', 'updated_at', 'created_at', @@ -67,13 +67,13 @@ describe('issue.test.js', function () { }); }); - describe('client.issues.list()', function () { + describe('client.issues.list()', () => { - it('should return issues', function (done) { - client.issues.list({id: client.id}, function (err, issues) { + it('should return issues', (done) => { + client.issues.list({id: client.id}, (err, issues) => { should.not.exists(err); issues.length.should.above(0); - var row = issues[0]; + let row = issues[0]; row.should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'labels', 'milestone', 'assignee', 'author', 'state', 'updated_at', 'created_at', 'subscribed', 'user_notes_count', 'upvotes', 'downvotes', 'due_date', 'confidential', 'web_url'); @@ -83,25 +83,25 @@ describe('issue.test.js', function () { }); - describe('client.issues.create(), update()', function () { - it('should create, update a issue', function (done) { + describe('client.issues.create(), update()', () => { + it('should create, update a issue', (done) => { client.issues.create({ - id: client.id, - title: 'test title ' + new Date(), - description: '测试 `markdown` \n [abc](/abc)', - assignee_id: 142, - milestone_id: 117, - labels: 'test,gitlabapi' - }, function (err, row) { + id: client.id + , title: 'test title ' + new Date() + , description: '测试 `markdown` \n [abc](/abc)' + , assignee_id: 142 + , milestone_id: 117 + , labels: 'test,gitlabapi' + }, (err, row) => { should.not.exists(err); row.project_id.should.equal(client.id); row.state.should.equal('opened'); client.issues.update({ - id: client.id, - issue_id: row.id, - title: row.title + ' update', - state_event: 'close', - }, function (err, row) { + id: client.id + , issue_id: row.id + , title: row.title + ' update' + , state_event: 'close', + }, (err, row) => { should.not.exists(err); row.title.should.containEql(' update'); row.state.should.equal('closed'); @@ -110,21 +110,21 @@ describe('issue.test.js', function () { }); }); - it('should update a close, reopen and close issue', function (done) { + it('should update a close, reopen and close issue', (done) => { client.issues.update({ - id: client.id, - issue_id: issueId, - description: 'need to be closed!', - state_event: 'close', - }, function (err, row) { + id: client.id + , issue_id: issueId + , description: 'need to be closed!' + , state_event: 'close', + }, (err, row) => { should.not.exists(err); row.state.should.equal('closed'); client.issues.update({ - id: client.id, - issue_id: issueId, - description: 'need to be reopen!', - state_event: 'reopen', - }, function (err, row) { + id: client.id + , issue_id: issueId + , description: 'need to be reopen!' + , state_event: 'reopen', + }, (err, row) => { should.not.exists(err); row.state.should.equal('reopened'); done(); @@ -133,12 +133,12 @@ describe('issue.test.js', function () { }); }); - describe('client.issues.listNotes()', function () { - it('should return issue\'s notes', function (done) { - client.issues.listNotes({id: client.id, issue_id: issueId}, function (err, rows) { + describe('client.issues.listNotes()', () => { + it('should return issue\'s notes', (done) => { + client.issues.listNotes({id: client.id, issue_id: issueId}, (err, rows) => { should.not.exists(err); rows.length.should.above(0); - var row = rows[0]; + let row = rows[0]; row.should.have.keys('id', 'body', 'author', 'created_at', 'attachment', 'updated_at', 'system', 'noteable_id', 'noteable_type', 'upvote?', 'downvote?'); done(); @@ -146,16 +146,16 @@ describe('issue.test.js', function () { }); it('should return issue\'s notes in thunk way', function* () { - var rows = yield client.thunk.issues.listNotes({id: client.id, issue_id: issueId}); + let rows = yield client.thunk.issues.listNotes({id: client.id, issue_id: issueId}); rows.length.should.above(0); - var row = rows[0]; + let row = rows[0]; row.should.have.keys('id', 'body', 'author', 'created_at', 'attachment', 'updated_at', 'system', 'noteable_id', 'noteable_type', 'upvote?', 'downvote?'); }); }); - describe('client.issues.createNote()', function () { - it('should create to note', function (done) { + describe('client.issues.createNote()', () => { + it('should create to note', (done) => { client.issues.createNote({ id: client.id, issue_id: issueId, body: '# h1 哈哈\n fixed #1098, fix #1098 fixes #1098' }, done); diff --git a/test/milestone.test.js b/test/milestone.test.js index 0474875..cc14538 100644 --- a/test/milestone.test.js +++ b/test/milestone.test.js @@ -14,23 +14,23 @@ * Module dependencies. */ -var client = require('./client'); -var should = require('should'); -var milestoneId; +let client = require('./client'); +let should = require('should'); +let milestoneId; -describe('milestone.test.js', function () { - before(function (done) { - client.createProject(function (err) { +describe('milestone.test.js', () => { + before((done) => { + client.createProject((err) => { if (err) { return done(err); } client.milestones.create({ - id: client.id, - title: 'test create milestone' + new Date(), - description: 'description for create milestone' + new Date(), - due_date: '2013-02-14', - }, function (err, data) { + id: client.id + , title: 'test create milestone' + new Date() + , description: 'description for create milestone' + new Date() + , due_date: '2013-02-14', + }, (err, data) => { if (err) { return done(err); } @@ -42,36 +42,36 @@ describe('milestone.test.js', function () { after(client.removeProject); - describe('client.milestones.get()', function () { + describe('client.milestones.get()', () => { it('should return a milestone', function* () { - var milestone = yield client.thunk.milestones.get({id: client.id, milestone_id: milestoneId}); + let milestone = yield client.thunk.milestones.get({id: client.id, milestone_id: milestoneId}); milestone.should.have.property('id'); milestone.should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'due_date', 'state', 'updated_at', 'created_at'); }); }); - describe('client.milestones.list()', function () { + describe('client.milestones.list()', () => { it('should return a milestone', function* () { - var milestones = yield client.thunk.milestones.list({id: client.id, per_page: 1}); + let milestones = yield client.thunk.milestones.list({id: client.id, per_page: 1}); milestones.should.length(1); milestones[0].should.have.keys('id', 'iid', 'project_id', 'title', 'description', 'due_date', 'state', 'updated_at', 'created_at'); }); }); - describe('client.milestones.listIssues()', function () { + describe('client.milestones.listIssues()', () => { it('should list all issues of the milestone', function* () { - var issues = yield client.thunk.milestones.listIssues({ - id: client.id, - milestone_id: milestoneId + let issues = yield client.thunk.milestones.listIssues({ + id: client.id + , milestone_id: milestoneId }); issues.should.length(0); - var issue = yield client.thunk.issues.create({ - id: client.id, - title: 'issue on milestone ' + milestoneId, - milestone_id: milestoneId + let issue = yield client.thunk.issues.create({ + id: client.id + , title: 'issue on milestone ' + milestoneId + , milestone_id: milestoneId }); issue.id.should.above(0); issue.iid.should.equal(1); @@ -79,20 +79,20 @@ describe('milestone.test.js', function () { issue.milestone.iid.should.equal(1); issues = yield client.thunk.milestones.listIssues({ - id: client.id, - milestone_id: milestoneId + id: client.id + , milestone_id: milestoneId }); issues.should.length(1); }); }); - describe('client.milestones.create() and update()', function () { + describe('client.milestones.create() and update()', () => { it('should create a milestone and close it', function* () { - var milestone = yield client.thunk.milestones.create({ - id: client.id, - title: 'test create milestone' + new Date(), - description: 'description for create milestone' + new Date(), - due_date: '2013-02-14', + let milestone = yield client.thunk.milestones.create({ + id: client.id + , title: 'test create milestone' + new Date() + , description: 'description for create milestone' + new Date() + , due_date: '2013-02-14', }); milestone.should.have.property('id'); milestone.should.have.property('project_id', client.id); @@ -100,12 +100,12 @@ describe('milestone.test.js', function () { milestone.due_date.should.equal('2013-02-14'); milestone = yield client.thunk.milestones.update({ - id: client.id, - milestone_id: milestone.id, - title: milestone.title + ' || test update milestone' + new Date(), - description: milestone.description + ' || \n ## description for update milestone' + new Date(), - due_date: '2013-02-15', - state_event: 'close', + id: client.id + , milestone_id: milestone.id + , title: milestone.title + ' || test update milestone' + new Date() + , description: milestone.description + ' || \n ## description for update milestone' + new Date() + , due_date: '2013-02-15' + , state_event: 'close', }); milestone.should.have.keys('id', 'iid', 'project_id', 'title', 'description', diff --git a/test/project.test.js b/test/project.test.js index 8721cf2..b6eaf9a 100644 --- a/test/project.test.js +++ b/test/project.test.js @@ -14,17 +14,17 @@ * Module dependencies. */ -var client = require('./client'); -var should = require('should'); +let client = require('./client'); +let should = require('should'); -describe('project.test.js', function () { +describe('project.test.js', () => { before(client.createProject); after(client.removeProject); - describe('client.projects.get()', function () { + describe('client.projects.get()', () => { - it('should return a project', function (done) { - client.projects.get({id: client.id}, function (err, project) { + it('should return a project', (done) => { + client.projects.get({id: client.id}, (err, project) => { should.not.exists(err); project.should.have.keys('id', 'name', 'description', 'default_branch', 'owner', @@ -46,13 +46,13 @@ describe('project.test.js', function () { }); - describe('client.projects.list()', function () { + describe('client.projects.list()', () => { - it('should return projects', function (done) { - client.projects.list({per_page: 1}, function (err, projects) { + it('should return projects', (done) => { + client.projects.list({per_page: 1}, (err, projects) => { should.not.exists(err); projects.should.length(1); - var project = projects[0]; + let project = projects[0]; // project.should.have.keys('id', 'name', 'description', 'default_branch', // 'owner', // 'public', 'path', 'path_with_namespace', 'namespace', @@ -66,17 +66,18 @@ describe('project.test.js', function () { }); - describe('listEvents()', function () { + describe('listEvents()', () => { it('should list current project events', function* () { - var events = yield client.thunk.projects.listEvents({id: client.id}); + let events = yield client.thunk.projects.listEvents({id: client.id}); events.length.should.above(0); events[0].action_name.should.equal('created'); }); }); - describe('search()', function () { + /*eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/ + describe('search()', () => { it('should search and list projects', function* () { - var projects = yield client.thunk.projects.search({ + let projects = yield client.thunk.projects.search({ query: client.projectName }); projects.length.should.equal(1); diff --git a/test/project_member.test.js b/test/project_member.test.js index e73a29c..90ceb34 100644 --- a/test/project_member.test.js +++ b/test/project_member.test.js @@ -14,35 +14,35 @@ * Module dependencies. */ -var client = require('./client'); -var should = require('should'); -var pedding = require('pedding'); +let client = require('./client'); +let should = require('should'); +let pedding = require('pedding'); -describe('project_member.test.js', function () { - before(function (done) { +describe('project_member.test.js', () => { + before((done) => { done = pedding(2, done); - client.createProject(function (err) { + client.createProject((err) => { if (err) { return done(err); } client.projectMembers.create({ - id: client.id, - user_id: 5, - access_level: 10 + id: client.id + , user_id: 5 + , access_level: 10 }, done); client.projectMembers.create({ - id: client.id, - user_id: 6, - access_level: 10 + id: client.id + , user_id: 6 + , access_level: 10 }, done); }); }); after(client.removeProject); - describe('client.projectMembers.get()', function () { - it('should return a member', function (done) { - client.projectMembers.get({id: client.id, user_id: 5}, function (err, member) { + describe('client.projectMembers.get()', () => { + it('should return a member', (done) => { + client.projectMembers.get({id: client.id, user_id: 5}, (err, member) => { should.not.exists(err); member.should.have.keys('id', 'username', 'name', 'state', 'access_level', 'avatar_url', 'web_url', 'expires_at'); @@ -52,13 +52,13 @@ describe('project_member.test.js', function () { }); - describe('client.projectMembers.list()', function () { + describe('client.projectMembers.list()', () => { - it('should return members', function (done) { - client.projectMembers.list({id: client.id, per_page: 2}, function (err, members) { + it('should return members', (done) => { + client.projectMembers.list({id: client.id, per_page: 2}, (err, members) => { should.not.exists(err); members.should.length(2); - var member = members[0]; + let member = members[0]; member.should.have.keys('id', 'username', 'name', 'state', 'access_level', 'avatar_url', 'web_url', 'expires_at'); done(); diff --git a/test/repository.test.js b/test/repository.test.js index d1e5e22..a6fc271 100644 --- a/test/repository.test.js +++ b/test/repository.test.js @@ -3,39 +3,39 @@ * Copyright(c) 2013 fengmk2 * MIT Licensed */ - +/* eslint-disable no-unused-expressions */ "use strict"; /** * Module dependencies. */ -var should = require('should'); -var pedding = require('pedding'); -var client = require('./client'); +let should = require('should'); +let pedding = require('pedding'); +let client = require('./client'); -describe.skip('repository.test.js', function () { +describe.skip('repository.test.js', () => { - describe('client.repository.list()', function () { + describe('client.repository.list()', () => { - it('should return a project root / tree', function (done) { - client.repository.list({ id: client.id, type: 'tree' }, function (err, tree) { + it('should return a project root / tree', (done) => { + client.repository.list({id: client.id, type: 'tree'}, (err, tree) => { should.not.exists(err); should.exists(tree); tree.should.be.instanceof(Array); - tree.forEach(function (item) { + tree.forEach((item) => { item.should.have.keys('name', 'type', 'mode', 'id'); }); done(); }); }); - it('should return a project /lib tree', function (done) { - client.repository.list({ id: client.id, type: 'tree', path: 'lib' }, function (err, tree) { + it('should return a project /lib tree', (done) => { + client.repository.list({id: client.id, type: 'tree', path: 'lib'}, (err, tree) => { should.not.exists(err); should.exists(tree); tree.should.be.instanceof(Array); - tree.forEach(function (item) { + tree.forEach((item) => { item.should.have.keys('name', 'type', 'mode', 'id'); }); done(); @@ -44,26 +44,26 @@ describe.skip('repository.test.js', function () { }); - describe('client.repository.getTree()', function () { + describe('client.repository.getTree()', () => { - it('should return a project root / tree', function (done) { - client.repository.getTree({ id: client.id }, function (err, tree) { + it('should return a project root / tree', (done) => { + client.repository.getTree({id: client.id}, (err, tree) => { should.not.exists(err); should.exists(tree); tree.should.be.instanceof(Array); - tree.forEach(function (item) { + tree.forEach((item) => { item.should.have.keys('name', 'type', 'mode', 'id'); }); done(); }); }); - it('should return a project /lib tree', function (done) { - client.repository.getTree({ id: client.id, path: 'lib' }, function (err, tree) { + it('should return a project /lib tree', (done) => { + client.repository.getTree({id: client.id, path: 'lib'}, (err, tree) => { should.not.exists(err); should.exists(tree); tree.should.be.instanceof(Array); - tree.forEach(function (item) { + tree.forEach((item) => { item.should.have.keys('name', 'type', 'mode', 'id'); }); done(); @@ -72,13 +72,13 @@ describe.skip('repository.test.js', function () { }); - describe('client.repository.getBranches()', function () { - it('should return a project branches', function (done) { - client.repository.getBranches({ id: client.id }, function (err, branches) { + describe('client.repository.getBranches()', () => { + it('should return a project branches', (done) => { + client.repository.getBranches({id: client.id}, (err, branches) => { should.not.exists(err); should.exists(branches); branches.should.be.instanceof(Array); - branches.forEach(function (item) { + branches.forEach((item) => { item.should.have.keys('name', 'commit', 'protected'); }); done(); @@ -86,9 +86,9 @@ describe.skip('repository.test.js', function () { }); }); - describe('client.repository.getBranch()', function () { - it('should return a project master branch', function (done) { - client.repository.getBranch({ id: client.id, branch: 'master' }, function (err, branch) { + describe('client.repository.getBranch()', () => { + it('should return a project master branch', (done) => { + client.repository.getBranch({id: client.id, branch: 'master'}, (err, branch) => { should.not.exists(err); should.exists(branch); branch.should.have.keys('name', 'commit', 'protected'); @@ -97,8 +97,8 @@ describe.skip('repository.test.js', function () { }); }); - it('should return 404 branch not exists', function (done) { - client.repository.getBranch({ id: client.id, branch: 'master22' }, function (err, branch) { + it('should return 404 branch not exists', (done) => { + client.repository.getBranch({id: client.id, branch: 'master22'}, (err, branch) => { should.exists(err); err.message.should.equal('404 Branch does not exist Not Found'); err.statusCode.should.equal(404); @@ -108,16 +108,16 @@ describe.skip('repository.test.js', function () { }); }); - describe('client.repository.protectBranch() and unprotectBranch()', function () { - it('should return protect master branch', function (done) { - client.repository.protectBranch({ id: client.id, branch: 'master' }, function (err, branch) { + describe('client.repository.protectBranch() and unprotectBranch()', () => { + it('should return protect master branch', (done) => { + client.repository.protectBranch({id: client.id, branch: 'master'}, (err, branch) => { should.not.exists(err); should.exists(branch); branch.should.have.keys('name', 'commit', 'protected'); branch.name.should.equal('master'); branch.protected.should.equal(true); - client.repository.protectBranch({ id: client.id, branch: 'master' }, function (err, branch) { + client.repository.protectBranch({id: client.id, branch: 'master'}, (err, branch) => { should.not.exists(err); should.exists(branch); branch.should.have.keys('name', 'commit', 'protected'); @@ -128,15 +128,15 @@ describe.skip('repository.test.js', function () { }); }); - it('should return unprotect master branch', function (done) { - client.repository.unprotectBranch({ id: client.id, branch: 'master' }, function (err, branch) { + it('should return unprotect master branch', (done) => { + client.repository.unprotectBranch({id: client.id, branch: 'master'}, (err, branch) => { should.not.exists(err); should.exists(branch); branch.should.have.keys('name', 'commit', 'protected'); branch.name.should.equal('master'); branch.protected.should.equal(false); - client.repository.unprotectBranch({ id: client.id, branch: 'master' }, function (err, branch) { + client.repository.unprotectBranch({id: client.id, branch: 'master'}, (err, branch) => { should.not.exists(err); should.exists(branch); branch.should.have.keys('name', 'commit', 'protected'); @@ -147,8 +147,8 @@ describe.skip('repository.test.js', function () { }); }); - it('should return 404 protect branch not exists', function (done) { - client.repository.protectBranch({ id: client.id, branch: 'master22' }, function (err, branch) { + it('should return 404 protect branch not exists', (done) => { + client.repository.protectBranch({id: client.id, branch: 'master22'}, (err, branch) => { should.exists(err); err.message.should.equal('404 Not Found'); err.statusCode.should.equal(404); @@ -157,8 +157,8 @@ describe.skip('repository.test.js', function () { }); }); - it('should return 404 unprotect branch not exists', function (done) { - client.repository.unprotectBranch({ id: client.id, branch: 'master22' }, function (err, branch) { + it('should return 404 unprotect branch not exists', (done) => { + client.repository.unprotectBranch({id: client.id, branch: 'master22'}, (err, branch) => { should.exists(err); err.message.should.equal('404 Not Found'); err.statusCode.should.equal(404); @@ -168,13 +168,13 @@ describe.skip('repository.test.js', function () { }); }); - describe('client.repository.getTags()', function () { - it('should return a project tags', function (done) { - client.repository.getTags({ id: client.id }, function (err, tags) { + describe('client.repository.getTags()', () => { + it('should return a project tags', (done) => { + client.repository.getTags({id: client.id}, (err, tags) => { should.not.exists(err); should.exists(tags); tags.should.be.instanceof(Array); - tags.forEach(function (item) { + tags.forEach((item) => { item.should.have.keys('name', 'commit', 'protected'); }); done(); @@ -182,25 +182,25 @@ describe.skip('repository.test.js', function () { }); }); - describe('client.repository.getCommits()', function () { - it('should return a project commits', function (done) { + describe('client.repository.getCommits()', () => { + it('should return a project commits', (done) => { done = pedding(2, done); - client.repository.getCommits({ id: client.id }, function (err, commits) { + client.repository.getCommits({id: client.id}, (err, commits) => { should.not.exists(err); should.exists(commits); commits.should.be.instanceof(Array); - commits.forEach(function (item) { + commits.forEach((item) => { item.should.have.keys('short_id', 'title', 'author_name', 'id', 'author_email', 'created_at'); }); done(); }); - client.repository.getCommits({ id: client.id, ref_name: 'master' }, function (err, commits) { + client.repository.getCommits({id: client.id, ref_name: 'master'}, (err, commits) => { should.not.exists(err); should.exists(commits); commits.should.be.instanceof(Array); commits.length.should.above(0); - commits.forEach(function (item) { + commits.forEach((item) => { item.should.have.keys('short_id', 'title', 'author_name', 'id', 'author_email', 'created_at'); }); done(); @@ -208,9 +208,9 @@ describe.skip('repository.test.js', function () { }); }); - describe('client.repository.getBlob()', function () { - it('should return a file content', function (done) { - client.repository.getBlob({ id: client.id, sha: 'master', filepath: 'lib/alidata.js' }, function (err, blob) { + describe('client.repository.getBlob()', () => { + it('should return a file content', (done) => { + client.repository.getBlob({id: client.id, sha: 'master', filepath: 'lib/alidata.js'}, (err, blob) => { should.not.exists(err); should.exists(blob); should.ok(Buffer.isBuffer(blob)); @@ -222,9 +222,9 @@ describe.skip('repository.test.js', function () { }); }); - describe('client.repository.getRawBlob()', function () { - it('should return raw file content', function (done) { - client.repository.getRawBlob({id: 55045, sha: '946579807281bd26b75b91986c78f15ad0bd40f7'}, function (err, raw) { + describe('client.repository.getRawBlob()', () => { + it('should return raw file content', (done) => { + client.repository.getRawBlob({id: 55045, sha: '946579807281bd26b75b91986c78f15ad0bd40f7'}, (err, raw) => { should.not.exists(err); should.exists(raw); should.ok(Buffer.isBuffer(raw)); @@ -235,10 +235,10 @@ describe.skip('repository.test.js', function () { }); }); }); - - describe('client.repository.archive()', function () { - it('should return archive file', function (done) { - client.repository.archive({id: 55045, sha: '946579807281bd26b75b91986c78f15ad0bd40f7'}, function (err, raw) { + + describe('client.repository.archive()', () => { + it('should return archive file', (done) => { + client.repository.archive({id: 55045, sha: '946579807281bd26b75b91986c78f15ad0bd40f7'}, (err, raw) => { should.not.exists(err); should.exists(raw); should.ok(Buffer.isBuffer(raw)); @@ -248,10 +248,10 @@ describe.skip('repository.test.js', function () { }); }); }); - - describe('client.repository.compare()', function () { - it('should return diffs', function (done) { - client.repository.compare({id: 55045, to: 'master', from: '946579807281bd26b75b91986c78f15ad0bd40f7'}, function (err, diffs) { + + describe('client.repository.compare()', () => { + it('should return diffs', (done) => { + client.repository.compare({id: 55045, to: 'master', from: '946579807281bd26b75b91986c78f15ad0bd40f7'}, (err, diffs) => { should.not.exists(err); should.exists(diffs); diffs.should.have.keys('commit', 'commits', 'diffs', 'compare_timeout', 'compare_same_ref'); @@ -260,5 +260,5 @@ describe.skip('repository.test.js', function () { done(); }); }); - }); + }); }); diff --git a/test/repository_file.test.js b/test/repository_file.test.js index 0045b96..67525f7 100644 --- a/test/repository_file.test.js +++ b/test/repository_file.test.js @@ -7,30 +7,30 @@ * Authors: * fengmk2 (http://fengmk2.github.com) */ - +/* eslint-disable no-unused-expressions */ 'use strict'; /** * Module dependencies. */ -var should = require('should'); -var pedding = require('pedding'); -var path = require('path'); -var os = require('os'); -var fs = require('fs'); -var client = require('./client'); +let should = require('should'); +let pedding = require('pedding'); +let path = require('path'); +let os = require('os'); +let fs = require('fs'); +let client = require('./client'); -var logopath = path.join(__dirname, '..', 'logo.png'); +let logopath = path.join(__dirname, '..', 'logo.png'); -describe.skip('repository_file.test.js', function () { +describe.skip('repository_file.test.js', () => { - describe('client.repositoryFiles.get()', function () { + describe('client.repositoryFiles.get()', () => { - it('should return repository file info', function (done) { + it('should return repository file info', (done) => { done = pedding(2, done); - client.repositoryFiles.get({id: 55045, file_path: 'README.md', ref: 'master'}, function (err, row) { + client.repositoryFiles.get({id: 55045, file_path: 'README.md', ref: 'master'}, (err, row) => { should.not.exists(err); row.file_name.should.equal('README.md'); row.file_path.should.equal('README.md'); @@ -52,7 +52,7 @@ describe.skip('repository_file.test.js', function () { }); client.repositoryFiles.get({id: 55045, file_path: 'test/gitlab-client-unittest.test.js', ref: 'master'}, - function (err, row) { + (err, row) => { should.not.exists(err); row.file_name.should.equal('gitlab-client-unittest.test.js'); row.file_path.should.equal('test/gitlab-client-unittest.test.js'); @@ -76,33 +76,33 @@ describe.skip('repository_file.test.js', function () { }); - describe('client.repositoryFiles.create(), update(), remove()', function () { - after(function (done) { + describe('client.repositoryFiles.create(), update(), remove()', () => { + after((done) => { done = pedding(2, done); client.repositoryFiles.remove({ - id: 55045, - file_path: 'files_from_api/foo.txt', - branch_name: 'master', - commit_message: 'delete foo.txt from api at ' + Date() + ' by ' + os.hostname(), + id: 55045 + , file_path: 'files_from_api/foo.txt' + , branch_name: 'master' + , commit_message: 'delete foo.txt from api at ' + Date() + ' by ' + os.hostname(), }, done); client.repositoryFiles.remove({ - id: 55045, - file_path: 'files_from_api/logo.png', - branch_name: 'master', - commit_message: 'delete logo.png from api at ' + Date() + ' by ' + os.hostname(), + id: 55045 + , file_path: 'files_from_api/logo.png' + , branch_name: 'master' + , commit_message: 'delete logo.png from api at ' + Date() + ' by ' + os.hostname(), }, done); }); - it('should create a new file', function (done) { - var file = { - id: 55045, - file_path: 'files_from_api/foo.txt', - branch_name: 'master', + it('should create a new file', (done) => { + let file = { + id: 55045 + , file_path: 'files_from_api/foo.txt' + , branch_name: 'master' // encoding: 'text', text default - content: 'foo content bar at ' + Date() + ' by ' + os.hostname(), - commit_message: 'create foo.txt from api at ' + Date() + ' by ' + os.hostname(), + , content: 'foo content bar at ' + Date() + ' by ' + os.hostname() + , commit_message: 'create foo.txt from api at ' + Date() + ' by ' + os.hostname(), }; - client.repositoryFiles.create(file, function (err, info) { + client.repositoryFiles.create(file, (err, info) => { should.not.exist(err); should.exist(info); info.should.have.keys('file_path', 'branch_name'); @@ -112,15 +112,15 @@ describe.skip('repository_file.test.js', function () { }); }); - it('should create a exist file error', function (done) { - var file = { - id: 55045, - file_path: 'files_from_api/foo.txt', - branch_name: 'master', - content: 'foo content bar at ' + Date() + ' by ' + os.hostname(), - commit_message: 'create foo.txt from api at ' + Date() + ' by ' + os.hostname(), + it('should create a exist file error', (done) => { + let file = { + id: 55045 + , file_path: 'files_from_api/foo.txt' + , branch_name: 'master' + , content: 'foo content bar at ' + Date() + ' by ' + os.hostname() + , commit_message: 'create foo.txt from api at ' + Date() + ' by ' + os.hostname(), }; - client.repositoryFiles.create(file, function (err, info) { + client.repositoryFiles.create(file, (err, info) => { should.exist(err); err.name.should.equal('Gitlab400Error'); err.message.should.equal('Your changes could not be committed, because file with such name exists'); @@ -129,15 +129,15 @@ describe.skip('repository_file.test.js', function () { }); }); - it('should update a exists file', function (done) { - var file = { - id: 55045, - file_path: 'files_from_api/foo.txt', - branch_name: 'master', - content: 'foo update content bar at ' + Date() + ' by ' + os.hostname(), - commit_message: 'update foo.txt from api at ' + Date() + ' by ' + os.hostname(), + it('should update a exists file', (done) => { + let file = { + id: 55045 + , file_path: 'files_from_api/foo.txt' + , branch_name: 'master' + , content: 'foo update content bar at ' + Date() + ' by ' + os.hostname() + , commit_message: 'update foo.txt from api at ' + Date() + ' by ' + os.hostname(), }; - client.repositoryFiles.update(file, function (err, info) { + client.repositoryFiles.update(file, (err, info) => { should.not.exist(err); should.exist(info); info.should.have.keys('file_path', 'branch_name'); @@ -147,15 +147,15 @@ describe.skip('repository_file.test.js', function () { }); }); - it('should update a not exists file error', function (done) { - var file = { - id: 55045, - file_path: 'files_from_api/foo-not-exists.txt', - branch_name: 'master', - content: 'foo update content bar at ' + Date() + ' by ' + os.hostname(), - commit_message: 'update foo-not-exists.txt from api at ' + Date() + ' by ' + os.hostname(), + it('should update a not exists file error', (done) => { + let file = { + id: 55045 + , file_path: 'files_from_api/foo-not-exists.txt' + , branch_name: 'master' + , content: 'foo update content bar at ' + Date() + ' by ' + os.hostname() + , commit_message: 'update foo-not-exists.txt from api at ' + Date() + ' by ' + os.hostname(), }; - client.repositoryFiles.update(file, function (err, info) { + client.repositoryFiles.update(file, (err, info) => { should.exist(err); err.name.should.equal('Gitlab400Error'); err.message.should.equal('You can only edit text files'); @@ -163,16 +163,16 @@ describe.skip('repository_file.test.js', function () { }); }); - it('should create a new base64 encoding image file', function (done) { - var file = { - id: 55045, - file_path: 'files_from_api/logo.png', - branch_name: 'master', - encoding: 'base64', - content: fs.readFileSync(logopath, 'base64'), - commit_message: 'create logo.png from api at ' + Date() + ' by ' + os.hostname(), + it('should create a new base64 encoding image file', (done) => { + let file = { + id: 55045 + , file_path: 'files_from_api/logo.png' + , branch_name: 'master' + , encoding: 'base64' + , content: fs.readFileSync(logopath, 'base64')// eslint-disable-line + , commit_message: 'create logo.png from api at ' + Date() + ' by ' + os.hostname(), }; - client.repositoryFiles.create(file, function (err, info) { + client.repositoryFiles.create(file, (err, info) => { should.not.exist(err); should.exist(info); info.should.have.keys('file_path', 'branch_name'); @@ -182,13 +182,13 @@ describe.skip('repository_file.test.js', function () { }); }); - it('should remove a not exists file error', function (done) { + it('should remove a not exists file error', (done) => { client.repositoryFiles.remove({ - id: 55045, - file_path: 'files_from_api/logo-not-exists.png', - branch_name: 'master', - commit_message: 'delete logo-not-exists.png from api at ' + Date() + ' by ' + os.hostname(), - }, function (err) { + id: 55045 + , file_path: 'files_from_api/logo-not-exists.png' + , branch_name: 'master' + , commit_message: 'delete logo-not-exists.png from api at ' + Date() + ' by ' + os.hostname(), + }, (err) => { should.exist(err); err.name.should.equal('Gitlab400Error'); err.message.should.equal('You can only edit text files');