diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..aff8802 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[.*ignore] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[**.{coffee,js,json}] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = false +trim_trailing_whitespace = true + +[*.md] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 184785d..cc4b897 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: node_js node_js: + - "0.12" - "0.11" - "0.10" - - "0.8" +sudo: false notifications: webhooks: urls: diff --git a/Cakefile b/Cakefile index 5b175e2..f985fcf 100644 --- a/Cakefile +++ b/Cakefile @@ -1,5 +1,7 @@ {spawn, exec} = require 'child_process' +coffee = './node_modules/.bin/coffee' + call = (command, args = [], fn = null) -> exec "#{command} #{args.join(' ')}", (err, stdout, stderr) -> if err? @@ -11,14 +13,14 @@ system = (command, args) -> spawn command, args, stdio: "inherit" build = (fn = null) -> - call 'coffee', ['-c', '--no-header', '-o', 'lib', 'src'] - call 'coffee', ['-c', '--no-header', '-o', 'examples', 'examples'] - call 'coffee', ['-c', '--no-header', '-o', 'tests', 'tests'] + call coffee, ['-c', '--no-header', '-o', 'lib', 'src'] + call coffee, ['-c', '--no-header', '-o', 'examples', 'examples'] + call coffee, ['-c', '--no-header', '-o', 'tests', 'tests'] watch = (fn = null) -> - system 'coffee', ['-w', '--no-header', '-c', '-o', 'lib', 'src'] - system 'coffee', ['-w', '--no-header', '-c', '-o', 'examples', 'examples'] - system 'coffee', ['-w', '--no-header', '-c', '-o', 'tests', 'tests'] + system coffee, ['-w', '--no-header', '-c', '-o', 'lib', 'src'] + system coffee, ['-w', '--no-header', '-c', '-o', 'examples', 'examples'] + system coffee, ['-w', '--no-header', '-c', '-o', 'tests', 'tests'] task 'watch', 'continually build the JavaScript code', -> watch -> diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..f401f49 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,24 @@ +The MIT License +=============== + +Copyright (c) + **2012-2015 Manfred Touron** ([@moul](https://twitter.com/moul)), + **2013-2015 Dave Irvine** ([@dave_irvine](https://twitter.com/dave_irvine)) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 617dd4c..a563ffe 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,14 @@ node-gitlab [![Build Status (Travis)](https://travis-ci.org/node-gitlab/node-gitlab.png?branch=master)](https://travis-ci.org/node-gitlab/node-gitlab) [![Dependency Status](https://david-dm.org/node-gitlab/node-gitlab.png?theme=shields.io)](https://david-dm.org/node-gitlab/node-gitlab) -[![authors](https://sourcegraph.com/api/repos/github.com/node-gitlab/node-gitlab/badges/authors.png)](https://sourcegraph.com/github.com/node-gitlab/node-gitlab) -[![library users](https://sourcegraph.com/api/repos/github.com/node-gitlab/node-gitlab/badges/library-users.png)](https://sourcegraph.com/github.com/node-gitlab/node-gitlab) -[![Total views](https://sourcegraph.com/api/repos/github.com/node-gitlab/node-gitlab/counters/views.png)](https://sourcegraph.com/github.com/node-gitlab/node-gitlab) -[![Views in the last 24 hours](https://sourcegraph.com/api/repos/github.com/node-gitlab/node-gitlab/counters/views-24h.png)](https://sourcegraph.com/github.com/node-gitlab/node-gitlab) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/node-gitlab/node-gitlab/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +[![Code Climate](https://codeclimate.com/github/node-gitlab/node-gitlab/badges/gpa.svg)](https://codeclimate.com/github/node-gitlab/node-gitlab) [![NPM Badge](https://nodei.co/npm/gitlab.png?downloads=true&stars=true)](https://npmjs.org/package/gitlab) -- [GitLab](https://github.com/gitlabhq/gitlabhq) API Nodejs library. -It wraps the HTTP api library described [here](https://github.com/node-gitlab/gitlabhq/tree/master/doc/api). +It wraps the HTTP api library described [here](https://github.com/gitlabhq/gitlabhq/tree/master/doc/api). Maintained by [Manfred Touron](https://github.com/moul) and [Dave Irvine](https://github.com/dave-irvine) @@ -105,6 +102,10 @@ Contributors - [shaoshuai0102](https://github.com/shaoshuai0102) - [Sakesan Panjamawat](https://github.com/sakp) - [Jose Jiménez](https://github.com/jjimenezlopez) +- [huhgawz](https://github.com/huhgawz) +- [Connor Weng](https://github.com/ConnorWeng) +- [Felix Fichte](https://github.com/spruce) +- [Steve Norman](https://github.com/stevenorman) License ------- @@ -115,7 +116,27 @@ MIT Changelog ========= -1.3.0 (2015-02-09) +[1.4.0](https://github.com/node-gitlab/node-gitlab/tree/v1.4.0) (2015-08-11) +------------------ + +- Now using headers for PRIVATE-TOKEN +- Add `Groups.create`, `Groups.addProject` and `Groups.search` methods +- Add `Projects.remove` and `Projects.search` methods +- Add `UserKeys` resource +- Add `Users.search` method +- Rename `ProjectMielstones.get` to `ProjectMilestones.all` +- Handling pagination on multiple new `.all()` methods +- Various stability and performance fixes + +Thanks to [@huhgawz](https://github.com/huhgawz), +[@ConnorWeng](https://github.com/ConnorWeng), [@langma](https://github.com/langma), +[@spruce](https://github.com/spruce), [@stevenorman](https://github.com/stevenorman) +and [@nogs](https://github.com/nogs) + + +[Full commits list](https://github.com/node-gitlab/node-gitlab/compare/v1.3.0...develop) + +[1.3.0](https://github.com/node-gitlab/node-gitlab/tree/v1.3.0) (2015-02-09) ------------------ - Now handling notes @@ -125,7 +146,7 @@ Changelog - Added tests - Code cleanup and various small improvements -1.2.0 (2014-12-24) +[1.2.0](https://github.com/node-gitlab/node-gitlab/tree/v1.2.0) (2014-12-24) ------------------ - Switched to new organization, some urls changed @@ -134,7 +155,7 @@ Changelog - Changed AddHook parameters - Happy Christmas -1.1.0 (2014-11-04) +[1.1.0](https://github.com/node-gitlab/node-gitlab/tree/v1.1.0) (2014-11-04) ------------------ - Added project branch support @@ -142,8 +163,13 @@ Changelog - Improved global error handling - Rebuilt javascript using latest Coffee-Script -1.0.0 (2014-08-19) +[1.0.0](https://github.com/node-gitlab/node-gitlab/tree/v1.0.0) (2014-08-19) ------------------ - Not fully stable, need more tests - Now we have a CHANGELOG + +[POC](https://github.com/node-gitlab/node-gitlab/tree/e7a5eedea4c27aed8bd567a3c455ec311b915d60) (2012-12-11) +---------------- + +- POC diff --git a/examples/list-projects.js b/examples/list-projects.js index afee024..c06d86a 100755 --- a/examples/list-projects.js +++ b/examples/list-projects.js @@ -13,13 +13,13 @@ }); gitlab.projects.all(function(projects) { - var project, _i, _len, _results; - _results = []; - for (_i = 0, _len = projects.length; _i < _len; _i++) { - project = projects[_i]; - _results.push(console.log("#" + project.id + ": " + project.name + ", path: " + project.path + ", default_branch: " + project.default_branch + ", private: " + project["private"] + ", owner: " + project.owner.name + " (" + project.owner.email + "), date: " + project.created_at)); + var i, len, project, results; + results = []; + for (i = 0, len = projects.length; i < len; i++) { + project = projects[i]; + results.push(console.log("#" + project.id + ": " + project.name + ", path: " + project.path + ", default_branch: " + project.default_branch + ", private: " + project["private"] + ", owner: " + project.owner.name + " (" + project.owner.email + "), date: " + project.created_at)); } - return _results; + return results; }); }).call(this); diff --git a/examples/list-users.js b/examples/list-users.js index 458899a..272bad1 100644 --- a/examples/list-users.js +++ b/examples/list-users.js @@ -13,13 +13,13 @@ }); gitlab.users.all(function(users) { - var user, _i, _len, _results; - _results = []; - for (_i = 0, _len = users.length; _i < _len; _i++) { - user = users[_i]; - _results.push(console.log("#" + user.id + ": " + user.email + ", " + user.name + ", " + user.created_at)); + var i, len, results, user; + results = []; + for (i = 0, len = users.length; i < len; i++) { + user = users[i]; + results.push(console.log("#" + user.id + ": " + user.email + ", " + user.name + ", " + user.created_at)); } - return _results; + return results; }); }).call(this); diff --git a/examples/reset-hooks.js b/examples/reset-hooks.js index 3ec48ac..87f4221 100644 --- a/examples/reset-hooks.js +++ b/examples/reset-hooks.js @@ -13,21 +13,21 @@ }); gitlab.projects.all(function(projects) { - var _i, _len, _project, _results; - _results = []; - for (_i = 0, _len = projects.length; _i < _len; _i++) { - _project = projects[_i]; - _results.push((function() { + var _project, i, len, results; + results = []; + for (i = 0, len = projects.length; i < len; i++) { + _project = projects[i]; + results.push((function() { var project; project = _project; return gitlab.projects.hooks.list(project.id, function(hooks) { - var hook, url, _j, _len1; + var hook, j, len1, url; url = "" + credentials.service_hook_base + project.path_with_namespace; if (hooks.length > 1) { return console.log(url + " too much hooks"); } else if (hooks.length === 1) { - for (_j = 0, _len1 = hooks.length; _j < _len1; _j++) { - hook = hooks[_j]; + for (j = 0, len1 = hooks.length; j < len1; j++) { + hook = hooks[j]; if (hook.url !== url) { gitlab.projects.hooks.remove(project.id, hook.id, function(ret) { return console.log(ret); @@ -43,7 +43,7 @@ }); })()); } - return _results; + return results; }); }).call(this); diff --git a/examples/show-project.coffee b/examples/show-project.coffee index a68540b..4e077ab 100755 --- a/examples/show-project.coffee +++ b/examples/show-project.coffee @@ -23,3 +23,8 @@ gitlab.projects.members.list projectId, (members) -> console.log "" console.log "=== Members ===" console.log members + +gitlab.projects.milestones.list projectId, {per_page: 100}, (milestones) -> + console.log "" + console.log "=== Milestones ===" + console.log milestones diff --git a/lib/ApiBase.js b/lib/ApiBase.js index 0f4a07f..2b14332 100644 --- a/lib/ApiBase.js +++ b/lib/ApiBase.js @@ -1,23 +1,23 @@ (function() { var debug, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; debug = require('debug')('gitlab:ApiBase'); module.exports.ApiBase = (function() { - function ApiBase(_at_options) { - this.options = _at_options; - this.init = __bind(this.init, this); - this.handleOptions = __bind(this.handleOptions, this); + function ApiBase(options) { + this.options = options; + this.init = bind(this.init, this); + this.handleOptions = bind(this.handleOptions, this); this.handleOptions(); this.init(); debug("constructor()"); } ApiBase.prototype.handleOptions = function() { - var _base; - if ((_base = this.options).verbose == null) { - _base.verbose = false; + var base; + if ((base = this.options).verbose == null) { + base.verbose = false; } return debug("handleOptions()"); }; diff --git a/lib/ApiBaseHTTP.js b/lib/ApiBaseHTTP.js index 9dd4b99..807d670 100644 --- a/lib/ApiBaseHTTP.js +++ b/lib/ApiBaseHTTP.js @@ -1,8 +1,8 @@ (function() { var ApiBase, debug, querystring, slumber, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; debug = require('debug')('gitlab:ApiBaseHTTP'); @@ -12,27 +12,27 @@ slumber = require('slumber'); - module.exports.ApiBaseHTTP = (function(_super) { - __extends(ApiBaseHTTP, _super); + module.exports.ApiBaseHTTP = (function(superClass) { + extend(ApiBaseHTTP, superClass); function ApiBaseHTTP() { - this.patch = __bind(this.patch, this); - this.put = __bind(this.put, this); - this.post = __bind(this.post, this); - this["delete"] = __bind(this["delete"], this); - this.get = __bind(this.get, this); - this.fn_wrapper = __bind(this.fn_wrapper, this); - this.prepare_opts = __bind(this.prepare_opts, this); - this.init = __bind(this.init, this); - this.handleOptions = __bind(this.handleOptions, this); + this.patch = bind(this.patch, this); + this.put = bind(this.put, this); + this.post = bind(this.post, this); + this["delete"] = bind(this["delete"], this); + this.get = bind(this.get, this); + this.fn_wrapper = bind(this.fn_wrapper, this); + this.prepare_opts = bind(this.prepare_opts, this); + this.init = bind(this.init, this); + this.handleOptions = bind(this.handleOptions, this); return ApiBaseHTTP.__super__.constructor.apply(this, arguments); } ApiBaseHTTP.prototype.handleOptions = function() { - var _base, _base1, _base2; + var base, base1, base2; ApiBaseHTTP.__super__.handleOptions.apply(this, arguments); - if ((_base = this.options).base_url == null) { - _base.base_url = ''; + if ((base = this.options).base_url == null) { + base.base_url = ''; } if (!this.options.url) { throw "`url` is mandatory"; @@ -40,11 +40,11 @@ if (!this.options.token) { throw "`private_token` is mandatory"; } - if ((_base1 = this.options).slumber == null) { - _base1.slumber = {}; + if ((base1 = this.options).slumber == null) { + base1.slumber = {}; } - if ((_base2 = this.options.slumber).append_slash == null) { - _base2.append_slash = false; + if ((base2 = this.options.slumber).append_slash == null) { + base2.append_slash = false; } this.options.url = this.options.url.replace(/\/api\/v3/, ''); if (this.options.auth != null) { @@ -64,17 +64,19 @@ if (opts.__query == null) { opts.__query = {}; } - opts.__query.private_token = this.options.token; + opts.headers = { + 'PRIVATE-TOKEN': this.options.token + }; return opts; }; ApiBaseHTTP.prototype.fn_wrapper = function(fn) { return (function(_this) { return function(err, response, ret) { - var arity, _ref; + var arity, ref; if (err) { debug('an error has occured', err); - if ((400 <= (_ref = err.statusCode) && _ref <= 499)) { + if ((400 <= (ref = err.statusCode) && ref <= 499)) { throw "Authorisation error. " + err.statusCode + ". Check your key."; } } diff --git a/lib/ApiV3.js b/lib/ApiV3.js index 5fc586a..6b5c3fb 100644 --- a/lib/ApiV3.js +++ b/lib/ApiV3.js @@ -1,18 +1,18 @@ (function() { var ApiBaseHTTP, debug, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; debug = require('debug')('gitlab:ApiV3'); ApiBaseHTTP = require('./ApiBaseHTTP').ApiBaseHTTP; - module.exports.ApiV3 = (function(_super) { - __extends(ApiV3, _super); + module.exports.ApiV3 = (function(superClass) { + extend(ApiV3, superClass); function ApiV3() { - this.handleOptions = __bind(this.handleOptions, this); + this.handleOptions = bind(this.handleOptions, this); return ApiV3.__super__.constructor.apply(this, arguments); } diff --git a/lib/BaseModel.js b/lib/BaseModel.js index 86cac3c..80e44c4 100644 --- a/lib/BaseModel.js +++ b/lib/BaseModel.js @@ -1,14 +1,14 @@ (function() { var debug, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; debug = require('debug')('gitlab:BaseModel'); module.exports = (function() { - function exports(_at_client) { - this.client = _at_client; - this._init = __bind(this._init, this); - this.load = __bind(this.load, this); + function exports(client) { + this.client = client; + this._init = bind(this._init, this); + this.load = bind(this.load, this); this._init(); } diff --git a/lib/Models/Groups.js b/lib/Models/Groups.js index 27ac0f5..1d233d4 100644 --- a/lib/Models/Groups.js +++ b/lib/Models/Groups.js @@ -1,21 +1,24 @@ (function() { var BaseModel, Groups, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); - Groups = (function(_super) { - __extends(Groups, _super); + Groups = (function(superClass) { + extend(Groups, superClass); function Groups() { - this.addMember = __bind(this.addMember, this); - this.listMembers = __bind(this.listMembers, this); - this.listProjects = __bind(this.listProjects, this); - this.show = __bind(this.show, this); - this.all = __bind(this.all, this); - this.init = __bind(this.init, this); + this.search = bind(this.search, this); + this.addProject = bind(this.addProject, this); + this.create = bind(this.create, this); + this.addMember = bind(this.addMember, this); + this.listMembers = bind(this.listMembers, this); + this.listProjects = bind(this.listProjects, this); + this.show = bind(this.show, this); + this.all = bind(this.all, this); + this.init = bind(this.init, this); return Groups.__super__.constructor.apply(this, arguments); } @@ -68,13 +71,7 @@ } }; })(this); - return this.get("groups", params, (function(_this) { - return function(data) { - if (fn) { - return fn(data); - } - }; - })(this)); + return this.get("groups", params, cb); }; Groups.prototype.show = function(groupId, fn) { @@ -127,10 +124,10 @@ this.debug("addMember(" + groupId + ", " + userId + ", " + accessLevel + ")"); checkAccessLevel = (function(_this) { return function() { - var access_level, k, _ref; - _ref = _this.access_levels; - for (k in _ref) { - access_level = _ref[k]; + var access_level, k, ref; + ref = _this.access_levels; + for (k in ref) { + access_level = ref[k]; if (accessLevel === access_level) { return true; } @@ -152,6 +149,49 @@ }); }; + Groups.prototype.create = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Groups::create()"); + return this.post("groups", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Groups.prototype.addProject = function(groupId, projectId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Groups::addProject(" + groupId + ", " + projectId + ")"); + return this.post("groups/" + (parseInt(groupId)) + "/projects/" + (parseInt(projectId)), null, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Groups.prototype.search = function(nameOrPath, fn) { + var params; + if (fn == null) { + fn = null; + } + this.debug("Groups::search(" + nameOrPath + ")"); + params = { + search: nameOrPath + }; + return this.get("groups", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + return Groups; })(BaseModel); diff --git a/lib/Models/IssueNotes.js b/lib/Models/IssueNotes.js index 4749d45..54bd415 100644 --- a/lib/Models/IssueNotes.js +++ b/lib/Models/IssueNotes.js @@ -1,18 +1,18 @@ (function() { var BaseModel, IssueNotes, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - IssueNotes = (function(_super) { - __extends(IssueNotes, _super); + IssueNotes = (function(superClass) { + extend(IssueNotes, superClass); function IssueNotes() { - this.all = __bind(this.all, this); + this.all = bind(this.all, this); return IssueNotes.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/Issues.js b/lib/Models/Issues.js index 5a64b32..093f018 100644 --- a/lib/Models/Issues.js +++ b/lib/Models/Issues.js @@ -1,19 +1,19 @@ (function() { var BaseModel, Issues, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); - Issues = (function(_super) { - __extends(Issues, _super); + Issues = (function(superClass) { + extend(Issues, superClass); function Issues() { - this.edit = __bind(this.edit, this); - this.create = __bind(this.create, this); - this.show = __bind(this.show, this); - this.all = __bind(this.all, this); + this.edit = bind(this.edit, this); + this.create = bind(this.create, this); + this.show = bind(this.show, this); + this.all = bind(this.all, this); return Issues.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/Labels.js b/lib/Models/Labels.js index 2796966..339700d 100644 --- a/lib/Models/Labels.js +++ b/lib/Models/Labels.js @@ -1,18 +1,18 @@ (function() { var BaseModel, Labels, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - Labels = (function(_super) { - __extends(Labels, _super); + Labels = (function(superClass) { + extend(Labels, superClass); function Labels() { - this.create = __bind(this.create, this); + this.create = bind(this.create, this); return Labels.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/Notes.js b/lib/Models/Notes.js index c720b6a..c0f1e89 100644 --- a/lib/Models/Notes.js +++ b/lib/Models/Notes.js @@ -1,18 +1,18 @@ (function() { var BaseModel, Notes, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - Notes = (function(_super) { - __extends(Notes, _super); + Notes = (function(superClass) { + extend(Notes, superClass); function Notes() { - this.create = __bind(this.create, this); + this.create = bind(this.create, this); return Notes.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectDeployKeys.js b/lib/Models/ProjectDeployKeys.js index 3b55632..929a99d 100644 --- a/lib/Models/ProjectDeployKeys.js +++ b/lib/Models/ProjectDeployKeys.js @@ -1,20 +1,20 @@ (function() { var BaseModel, ProjectKeys, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectKeys = (function(_super) { - __extends(ProjectKeys, _super); + ProjectKeys = (function(superClass) { + extend(ProjectKeys, superClass); function ProjectKeys() { - this.addKey = __bind(this.addKey, this); - this.getKey = __bind(this.getKey, this); - this.listKeys = __bind(this.listKeys, this); + this.addKey = bind(this.addKey, this); + this.getKey = bind(this.getKey, this); + this.listKeys = bind(this.listKeys, this); return ProjectKeys.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectHooks.js b/lib/Models/ProjectHooks.js index 4860f08..20e1aff 100644 --- a/lib/Models/ProjectHooks.js +++ b/lib/Models/ProjectHooks.js @@ -1,22 +1,22 @@ (function() { var BaseModel, ProjectHooks, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectHooks = (function(_super) { - __extends(ProjectHooks, _super); + ProjectHooks = (function(superClass) { + extend(ProjectHooks, superClass); function ProjectHooks() { - this.remove = __bind(this.remove, this); - this.update = __bind(this.update, this); - this.add = __bind(this.add, this); - this.show = __bind(this.show, this); - this.list = __bind(this.list, this); + this.remove = bind(this.remove, this); + this.update = bind(this.update, this); + this.add = bind(this.add, this); + this.show = bind(this.show, this); + this.list = bind(this.list, this); return ProjectHooks.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectIssues.js b/lib/Models/ProjectIssues.js index a0f46ed..2844f80 100644 --- a/lib/Models/ProjectIssues.js +++ b/lib/Models/ProjectIssues.js @@ -1,19 +1,19 @@ (function() { var BaseModel, ProjectIssues, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectIssues = (function(_super) { - __extends(ProjectIssues, _super); + ProjectIssues = (function(superClass) { + extend(ProjectIssues, superClass); function ProjectIssues() { - this.list = __bind(this.list, this); - this.init = __bind(this.init, this); + this.list = bind(this.list, this); + this.init = bind(this.init, this); return ProjectIssues.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectLabels.js b/lib/Models/ProjectLabels.js index 075c2ff..c9da1ea 100644 --- a/lib/Models/ProjectLabels.js +++ b/lib/Models/ProjectLabels.js @@ -1,18 +1,18 @@ (function() { var BaseModel, ProjectLabels, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectLabels = (function(_super) { - __extends(ProjectLabels, _super); + ProjectLabels = (function(superClass) { + extend(ProjectLabels, superClass); function ProjectLabels() { - this.all = __bind(this.all, this); + this.all = bind(this.all, this); return ProjectLabels.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectMembers.js b/lib/Models/ProjectMembers.js index 346f1cb..72b4b1d 100644 --- a/lib/Models/ProjectMembers.js +++ b/lib/Models/ProjectMembers.js @@ -1,22 +1,22 @@ (function() { var BaseModel, ProjectMembers, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectMembers = (function(_super) { - __extends(ProjectMembers, _super); + ProjectMembers = (function(superClass) { + extend(ProjectMembers, superClass); function ProjectMembers() { - this.remove = __bind(this.remove, this); - this.update = __bind(this.update, this); - this.add = __bind(this.add, this); - this.show = __bind(this.show, this); - this.list = __bind(this.list, this); + this.remove = bind(this.remove, this); + this.update = bind(this.update, this); + this.add = bind(this.add, this); + this.show = bind(this.show, this); + this.list = bind(this.list, this); return ProjectMembers.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectMergeRequests.js b/lib/Models/ProjectMergeRequests.js index e6ceea3..edfab59 100644 --- a/lib/Models/ProjectMergeRequests.js +++ b/lib/Models/ProjectMergeRequests.js @@ -1,22 +1,22 @@ (function() { var BaseModel, ProjectMergeRequests, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectMergeRequests = (function(_super) { - __extends(ProjectMergeRequests, _super); + ProjectMergeRequests = (function(superClass) { + extend(ProjectMergeRequests, superClass); function ProjectMergeRequests() { - this.comment = __bind(this.comment, this); - this.update = __bind(this.update, this); - this.add = __bind(this.add, this); - this.show = __bind(this.show, this); - this.list = __bind(this.list, this); + this.comment = bind(this.comment, this); + this.update = bind(this.update, this); + this.add = bind(this.add, this); + this.show = bind(this.show, this); + this.list = bind(this.list, this); return ProjectMergeRequests.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectMilestones.js b/lib/Models/ProjectMilestones.js index 8f2af7e..b01231c 100644 --- a/lib/Models/ProjectMilestones.js +++ b/lib/Models/ProjectMilestones.js @@ -1,21 +1,21 @@ (function() { var BaseModel, ProjectMilestones, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectMilestones = (function(_super) { - __extends(ProjectMilestones, _super); + ProjectMilestones = (function(superClass) { + extend(ProjectMilestones, superClass); function ProjectMilestones() { - this.update = __bind(this.update, this); - this.add = __bind(this.add, this); - this.show = __bind(this.show, this); - this.list = __bind(this.list, this); + this.update = bind(this.update, this); + this.add = bind(this.add, this); + this.show = bind(this.show, this); + this.list = bind(this.list, this); return ProjectMilestones.__super__.constructor.apply(this, arguments); } diff --git a/lib/Models/ProjectRepository.js b/lib/Models/ProjectRepository.js index 4a0ec10..8384838 100644 --- a/lib/Models/ProjectRepository.js +++ b/lib/Models/ProjectRepository.js @@ -1,31 +1,31 @@ (function() { var BaseModel, ProjectRepository, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - ProjectRepository = (function(_super) { - __extends(ProjectRepository, _super); + ProjectRepository = (function(superClass) { + extend(ProjectRepository, superClass); function ProjectRepository() { - this.updateFile = __bind(this.updateFile, this); - this.createFile = __bind(this.createFile, this); - this.showFile = __bind(this.showFile, this); - this.listTree = __bind(this.listTree, this); - this.diffCommit = __bind(this.diffCommit, this); - this.showCommit = __bind(this.showCommit, this); - this.listCommits = __bind(this.listCommits, this); - this.listTags = __bind(this.listTags, this); - this.deleteBranch = __bind(this.deleteBranch, this); - this.createBranch = __bind(this.createBranch, this); - this.unprotectBranch = __bind(this.unprotectBranch, this); - this.protectBranch = __bind(this.protectBranch, this); - this.showBranch = __bind(this.showBranch, this); - this.listBranches = __bind(this.listBranches, this); + this.updateFile = bind(this.updateFile, this); + this.createFile = bind(this.createFile, this); + this.showFile = bind(this.showFile, this); + this.listTree = bind(this.listTree, this); + this.diffCommit = bind(this.diffCommit, this); + this.showCommit = bind(this.showCommit, this); + this.listCommits = bind(this.listCommits, this); + this.listTags = bind(this.listTags, this); + this.deleteBranch = bind(this.deleteBranch, this); + this.createBranch = bind(this.createBranch, this); + this.unprotectBranch = bind(this.unprotectBranch, this); + this.protectBranch = bind(this.protectBranch, this); + this.showBranch = bind(this.showBranch, this); + this.listBranches = bind(this.listBranches, this); return ProjectRepository.__super__.constructor.apply(this, arguments); } @@ -163,7 +163,7 @@ fn = null; } this.debug("Projects::diffCommit()"); - return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + sha, (function(_this) { + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/commits/" + sha + "/diff", (function(_this) { return function(data) { if (fn) { return fn(data); diff --git a/lib/Models/Projects.js b/lib/Models/Projects.js index aac71c2..7102c3b 100644 --- a/lib/Models/Projects.js +++ b/lib/Models/Projects.js @@ -1,26 +1,28 @@ (function() { var BaseModel, Projects, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); Utils = require('../Utils'); - Projects = (function(_super) { - __extends(Projects, _super); + Projects = (function(superClass) { + extend(Projects, superClass); function Projects() { - this.listTags = __bind(this.listTags, this); - this.listCommits = __bind(this.listCommits, this); - this.listMembers = __bind(this.listMembers, this); - this.editMember = __bind(this.editMember, this); - this.addMember = __bind(this.addMember, this); - this.create = __bind(this.create, this); - this.show = __bind(this.show, this); - this.all = __bind(this.all, this); - this.init = __bind(this.init, this); + this.search = bind(this.search, this); + this.remove = bind(this.remove, this); + this.listTags = bind(this.listTags, this); + this.listCommits = bind(this.listCommits, this); + this.listMembers = bind(this.listMembers, this); + this.editMember = bind(this.editMember, this); + this.addMember = bind(this.addMember, this); + this.create = bind(this.create, this); + this.show = bind(this.show, this); + this.all = bind(this.all, this); + this.init = bind(this.init, this); return Projects.__super__.constructor.apply(this, arguments); } @@ -185,6 +187,41 @@ })(this)); }; + Projects.prototype.remove = function(projectId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::remove()"); + return this["delete"]("projects/" + (Utils.parseProjectId(projectId)), (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + Projects.prototype.search = function(projectName, params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + if ('function' === typeof params) { + fn = params; + params = {}; + } + this.debug("Projects::search()"); + return this.get("projects/search/" + projectName, params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + return Projects; })(BaseModel); diff --git a/lib/Models/UserKeys.js b/lib/Models/UserKeys.js new file mode 100644 index 0000000..a5abc35 --- /dev/null +++ b/lib/Models/UserKeys.js @@ -0,0 +1,38 @@ +(function() { + var BaseModel, UserKeys, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + BaseModel = require('../BaseModel'); + + UserKeys = (function(superClass) { + extend(UserKeys, superClass); + + function UserKeys() { + this.all = bind(this.all, this); + return UserKeys.__super__.constructor.apply(this, arguments); + } + + UserKeys.prototype.all = function(userId, fn) { + if (fn == null) { + fn = null; + } + return this.get("users/" + (parseInt(userId)) + "/keys", (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + return UserKeys; + + })(BaseModel); + + module.exports = function(client) { + return new UserKeys(client); + }; + +}).call(this); diff --git a/lib/Models/Users.js b/lib/Models/Users.js index 1aa5f75..7e95fe6 100644 --- a/lib/Models/Users.js +++ b/lib/Models/Users.js @@ -1,23 +1,29 @@ (function() { var BaseModel, Users, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - __hasProp = {}.hasOwnProperty; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; BaseModel = require('../BaseModel'); - Users = (function(_super) { - __extends(Users, _super); + Users = (function(superClass) { + extend(Users, superClass); function Users() { - this.session = __bind(this.session, this); - this.create = __bind(this.create, this); - this.show = __bind(this.show, this); - this.current = __bind(this.current, this); - this.all = __bind(this.all, this); + this.search = bind(this.search, this); + this.session = bind(this.session, this); + this.create = bind(this.create, this); + this.show = bind(this.show, this); + this.current = bind(this.current, this); + this.all = bind(this.all, this); + this.init = bind(this.init, this); return Users.__super__.constructor.apply(this, arguments); } + Users.prototype.init = function() { + return this.keys = this.load('UserKeys'); + }; + Users.prototype.all = function(params, fn) { var cb, data; if (params == null) { @@ -57,13 +63,7 @@ } }; })(this); - return this.get("users", params, (function(_this) { - return function(data) { - if (fn) { - return fn(data); - } - }; - })(this)); + return this.get("users", params, cb); }; Users.prototype.current = function(fn) { @@ -124,6 +124,22 @@ }); }; + Users.prototype.search = function(emailOrUsername, fn) { + var params; + if (fn == null) { + fn = null; + } + this.debug("Users::search(" + emailOrUsername + ")"); + params = { + search: emailOrUsername + }; + return this.get("users", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + return Users; })(BaseModel); diff --git a/package.json b/package.json index c268c21..623cdac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitlab", - "version": "1.3.0", + "version": "1.4.0", "description": "GitLab API Nodejs library.", "main": "lib/index.js", "directories": { @@ -8,8 +8,8 @@ "test": "test" }, "scripts": { - "test": "./node_modules/mocha/bin/mocha tests", - "build": "./node_modules/coffee-script/bin/cake build" + "test": "./node_modules/.bin/mocha tests", + "build": "./node_modules/.bin/cake build" }, "repository": { "type": "git", @@ -17,10 +17,10 @@ }, "dependencies": { "debug": "*", - "slumber": ">=0.5.0" + "slumber": ">=0.7.0" }, "devDependencies": { - "coffee-script": "*", + "coffee-script": ">=1.9.1", "mocha": "", "proxyquire": "~1.0.1", "chai": "~1.9.2", diff --git a/src/ApiBaseHTTP.coffee b/src/ApiBaseHTTP.coffee index ae418a2..9948f81 100644 --- a/src/ApiBaseHTTP.coffee +++ b/src/ApiBaseHTTP.coffee @@ -32,15 +32,11 @@ class module.exports.ApiBaseHTTP extends ApiBase prepare_opts: (opts) => opts.__query ?= {} - opts.__query.private_token = @options.token + opts.headers = { 'PRIVATE-TOKEN': @options.token } return opts fn_wrapper: (fn) => return (err, response, ret) => - if err - debug 'an error has occured', err - if 400 <= err.statusCode <= 499 - throw "Authorisation error. #{err.statusCode}. Check your key." arity = fn.length switch arity when 1 then fn ret diff --git a/src/Models/Groups.coffee b/src/Models/Groups.coffee index 6da1eba..7f20729 100644 --- a/src/Models/Groups.coffee +++ b/src/Models/Groups.coffee @@ -14,7 +14,7 @@ class Groups extends BaseModel fn = params params = {} @debug "Groups::all()" - + params.page ?= 1 params.per_page ?= 100 @@ -31,7 +31,7 @@ class Groups extends BaseModel data = data.concat(retData) return fn data if fn - @get "groups", params, (data) => fn data if fn + @get "groups", params, cb show: (groupId, fn = null) => @debug "Groups::show()" @@ -40,7 +40,7 @@ class Groups extends BaseModel listProjects: (groupId, fn = null) => @debug "Groups::listProjects()" @get "groups/#{parseInt groupId}", (data) => fn data.projects if fn - + listMembers: (groupId, fn = null) => @debug "Groups::listMembers()" @get "groups/#{parseInt groupId}/members", (data) => fn data if fn @@ -62,5 +62,18 @@ class Groups extends BaseModel @post "groups/#{parseInt groupId}/members", params, (data) -> fn data if fn + create: (params = {}, fn = null) => + @debug "Groups::create()" + @post "groups", params, (data) -> fn data if fn + + addProject: (groupId, projectId, fn = null) => + @debug "Groups::addProject(#{groupId}, #{projectId})" + @post "groups/#{parseInt groupId}/projects/#{parseInt projectId}", null, (data) -> fn data if fn + + search: (nameOrPath, fn = null) => + @debug "Groups::search(#{nameOrPath})" + params = + search: nameOrPath + @get "groups", params, (data) -> fn data if fn module.exports = (client) -> new Groups client diff --git a/src/Models/ProjectMilestones.coffee b/src/Models/ProjectMilestones.coffee index 6b0360c..bd68cec 100644 --- a/src/Models/ProjectMilestones.coffee +++ b/src/Models/ProjectMilestones.coffee @@ -2,9 +2,29 @@ BaseModel = require '../BaseModel' Utils = require '../Utils' class ProjectMilestones extends BaseModel - list: (projectId, fn = null) => - @debug "Projects::milestones()" - @get "projects/#{Utils.parseProjectId projectId}/milestones", (data) => fn data if fn + list = (projectId, fn = null) -> + console.log 'DEPRECATED: milestone.list. Use milestone.all instead' + @all arguments... + all: (projectId, fn = null) => + @debug "Projects::Milestones::all()" + params = {} + params.page ?= 1 + params.per_page ?= 100 + + data = [] + cb = (err, retData) => + if err + return fn(retData || data) if fn + else if retData.length == params.per_page + @debug "Recurse Projects::Milestones::all()" + data = data.concat(retData) + params.page++ + return @get "projects/#{Utils.parseProjectId projectId}/milestones", params, cb + else + data = data.concat(retData) + return fn data if fn + + @get "projects/#{Utils.parseProjectId projectId}/milestones", params, cb show: (projectId, milestoneId, fn = null) => @debug "Projects::milestone()" diff --git a/src/Models/ProjectRepository.coffee b/src/Models/ProjectRepository.coffee index 48c1e8c..b955dc0 100644 --- a/src/Models/ProjectRepository.coffee +++ b/src/Models/ProjectRepository.coffee @@ -44,7 +44,7 @@ class ProjectRepository extends BaseModel diffCommit: (projectId, sha, fn = null) => @debug "Projects::diffCommit()" - @get "projects/#{Utils.parseProjectId projectId}/repository/branches/#{sha}", (data) => fn data if fn + @get "projects/#{Utils.parseProjectId projectId}/repository/commits/#{sha}/diff", (data) => fn data if fn # === Tree listTree: (projectId, params = {}, fn = null) => diff --git a/src/Models/Projects.coffee b/src/Models/Projects.coffee index a43a05d..515f4e2 100644 --- a/src/Models/Projects.coffee +++ b/src/Models/Projects.coffee @@ -64,4 +64,16 @@ class Projects extends BaseModel @debug "Projects::listTags()" @get "projects/#{params.id}/repository/tags", (data) => fn data if fn + remove: (projectId, fn = null) => + @debug "Projects::remove()" + @delete "projects/#{Utils.parseProjectId projectId}", (data) => fn data if fn + + search: (projectName, params={}, fn=null) => + if 'function' is typeof params + fn = params + params={} + + @debug "Projects::search()" + @get "projects/search/#{projectName}", params, (data) => fn data if fn + module.exports = (client) -> new Projects client diff --git a/src/Models/UserKeys.coffee b/src/Models/UserKeys.coffee new file mode 100644 index 0000000..75a9705 --- /dev/null +++ b/src/Models/UserKeys.coffee @@ -0,0 +1,7 @@ +BaseModel = require '../BaseModel' + +class UserKeys extends BaseModel + all: (userId, fn = null) => + @get "users/#{parseInt userId}/keys", (data) => fn data if fn + +module.exports = (client) -> new UserKeys client diff --git a/src/Models/Users.coffee b/src/Models/Users.coffee index 2e61b74..5f84cbe 100644 --- a/src/Models/Users.coffee +++ b/src/Models/Users.coffee @@ -1,6 +1,9 @@ BaseModel = require '../BaseModel' class Users extends BaseModel + init: => + @keys = @load 'UserKeys' + all: (params = {}, fn = null) => if 'function' is typeof params fn = params @@ -23,7 +26,7 @@ class Users extends BaseModel data = data.concat(retData) return fn data if fn - @get "users", params, (data) => fn data if fn + @get "users", params, cb current: (fn = null) => @debug "Users::current()" @@ -44,4 +47,10 @@ class Users extends BaseModel password: password @post "session", params, (data) -> fn data if fn + search: (emailOrUsername, fn = null) => + @debug "Users::search(#{emailOrUsername})" + params = + search: emailOrUsername + @get "users", params, (data) -> fn data if fn + module.exports = (client) -> new Users client diff --git a/tests/Projects.test.js b/tests/Projects.test.js index 40bc89a..8116a5b 100644 --- a/tests/Projects.test.js +++ b/tests/Projects.test.js @@ -53,9 +53,9 @@ arrayOf99 = []; arrayOf1 = []; before(function() { - var i, _i, _results; - _results = []; - for (i = _i = 0; _i <= 102; i = ++_i) { + var i, j, results; + results = []; + for (i = j = 0; j <= 102; i = ++j) { if (i < 1) { arrayOf1.push({}); } @@ -66,12 +66,12 @@ arrayOf100.push({}); } if (i < 101) { - _results.push(arrayOf101.push({})); + results.push(arrayOf101.push({})); } else { - _results.push(void 0); + results.push(void 0); } } - return _results; + return results; }); it("should use GET verb", function() { var getStub; diff --git a/tests/mock.js b/tests/mock.js index 3320c9c..f32e234 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -1,12 +1,12 @@ (function() { var Mock, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; Mock = (function() { function Mock() { - this.beforeEach = __bind(this.beforeEach, this); - this.update_path = __bind(this.update_path, this); - this.setup = __bind(this.setup, this); + this.beforeEach = bind(this.beforeEach, this); + this.update_path = bind(this.update_path, this); + this.setup = bind(this.setup, this); var project; this.path = ''; this.projects = []; @@ -63,8 +63,8 @@ })(this)); }; - Mock.prototype.update_path = function(_at_path) { - this.path = _at_path; + Mock.prototype.update_path = function(path1) { + this.path = path1; return this; }; @@ -97,14 +97,14 @@ }; Mock.prototype.beforeEach = function() { - var method, _i, _len, _ref, _results; - _ref = ['get', 'delete', 'post', 'put', 'patch']; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - method = _ref[_i]; - _results.push(this[method] = this.defaults[method]); + var i, len, method, ref, results; + ref = ['get', 'delete', 'post', 'put', 'patch']; + results = []; + for (i = 0, len = ref.length; i < len; i++) { + method = ref[i]; + results.push(this[method] = this.defaults[method]); } - return _results; + return results; }; return Mock; diff --git a/tests/test.js b/tests/test.js index e682d50..71368c4 100644 --- a/tests/test.js +++ b/tests/test.js @@ -69,10 +69,10 @@ }); return it('should retrieve array of projects without error', function(done) { return gitlab.projects.all(function(projects) { - var project, _i, _len; + var i, len, project; assert(projects.length > 0); - for (_i = 0, _len = projects.length; _i < _len; _i++) { - project = projects[_i]; + for (i = 0, len = projects.length; i < len; i++) { + project = projects[i]; validate_project(project); } return done();