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/.gitignore b/.gitignore index 61495c9..ef1ae4c 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ npm-debug.log .idea *.iml + +/docs \ No newline at end of file diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 0000000..0564610 --- /dev/null +++ b/.hound.yml @@ -0,0 +1,2 @@ +javascript: + enabled: false diff --git a/.travis.yml b/.travis.yml index 184785d..e664de8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: node_js node_js: - - "0.11" - - "0.10" - - "0.8" + - "lts/boron" + - "lts/carbon" + - "stable" +sudo: false notifications: webhooks: urls: diff --git a/Cakefile b/Cakefile index 2d5d61f..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', '-o', 'lib', 'src'] - call 'coffee', ['-c', '-o', 'examples', 'examples'] - call 'coffee', ['-c', '-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', '-c', '-o', 'lib', 'src'] - system 'coffee', ['-w', '-c', '-o', 'examples', 'examples'] - system 'coffee', ['-w', '-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 -> @@ -27,10 +29,3 @@ task 'watch', 'continually build the JavaScript code', -> task 'build', 'build the JavaScript code', -> build -> console.log "Done !" - -task 'doc', 'rebuild the Docco documentation', -> - exec([ - 'docco src/*.coffee' - ].join(' && '), (err) -> - throw err if err - ) 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/Makefile b/Makefile new file mode 100644 index 0000000..71452a3 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +PACKAGE_VERSION = $(shell node -e 'console.log(require("./package.json").version);') + +develop: + npm install + npm install -g coffee-script + +build: + cake build + +watch: + cake watch + +doc: + npm install docco + ./node_modules/docco/bin/docco $(shell find src -name "*.coffee") + +tag: + git commit -am "v$(PACKAGE_VERSION)" + git tag v$(PACKAGE_VERSION) + git push + git push --tags + +test: build + npm test + +release: test + npm publish diff --git a/README.md b/README.md index 6b9cccf..0ff3cb6 100644 --- a/README.md +++ b/README.md @@ -1,120 +1 @@ -node-gitlab -=========== - -[![Build Status (Travis)](https://travis-ci.org/moul/node-gitlab.png?branch=master)](https://travis-ci.org/moul/node-gitlab) -[![Build Status (Shippable)](https://api.shippable.com/projects/5371096b93ac868700b434d9/badge/develop)](https://www.shippable.com/projects/5371096b93ac868700b434d9) -[![Dependency Status](https://david-dm.org/moul/node-gitlab.png?theme=shields.io)](https://david-dm.org/moul/node-gitlab) -[![authors](https://sourcegraph.com/api/repos/github.com/moul/node-gitlab/badges/authors.png)](https://sourcegraph.com/github.com/moul/node-gitlab) -[![library users](https://sourcegraph.com/api/repos/github.com/moul/node-gitlab/badges/library-users.png)](https://sourcegraph.com/github.com/moul/node-gitlab) -[![Total views](https://sourcegraph.com/api/repos/github.com/moul/node-gitlab/counters/views.png)](https://sourcegraph.com/github.com/moul/node-gitlab) -[![Views in the last 24 hours](https://sourcegraph.com/api/repos/github.com/moul/node-gitlab/counters/views-24h.png)](https://sourcegraph.com/github.com/moul/node-gitlab) -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/moul/node-gitlab/trend.png)](https://bitdeli.com/free "Bitdeli Badge") - -[![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/moul/gitlabhq/tree/master/doc/api). - -Maintained by [Manfred Touron](https://github.com/moul) and [Dave Irvine](https://github.com/dave-irvine) - - -Install -======= - -```bash -# Install from npm -npm install gitlab -``` - -Usage -===== - -Coffee-Script -------------- -```coffee -# Connection -gitlab = (require 'gitlab') - url: 'http://example.com' - token: 'abcdefghij123456' - -# Listing users -gitlab.users.all (users) -> - console.log "##{user.id}: #{user.email}, #{user.name}, #{user.created_at}" for user in users - -# Listing projects -gitlab.projects.all (projects) -> - for project in projects - 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}" -``` - -Javascript ----------- -```javascript -// Connection -var gitlab = require('gitlab')({ - url: 'http://example.com', - token: 'abcdefghij123456' -}); - -// Listing users -gitlab.users.all(function(users) { - for (var i = 0; i < users.length; i++) { - console.log("#" + users[i].id + ": " + users[i].email + ", " + users[i].name + ", " + users[i].created_at); - } -}); - -// Listing projects -gitlab.projects.all(function(projects) { - for (var i = 0; i < projects.length; i++) { - console.log("#" + projects[i].id + ": " + projects[i].name + ", path: " + projects[i].path + ", default_branch: " + projects[i].default_branch + ", private: " + projects[i]["private"] + ", owner: " + projects[i].owner.name + " (" + projects[i].owner.email + "), date: " + projects[i].created_at); - } -}); -``` - -See [Examples directory](https://github.com/moul/node-gitlab/tree/master/examples) for more examples - -Develop -======= - -[![Gitter chat](https://badges.gitter.im/moul/node-gitlab.png)](https://gitter.im/moul/node-gitlab) - -Edit the Coffee-Script files in `src`, then build them using `cake build`. -Use `cake watch` to build files continuously while developing. - -CLI ---- - -Check out [cli-gitlab](https://github.com/mdsb100/cli-gitlab) - - -Contributors ------------- - -- [Glavin Wiechert](https://github.com/Glavin001) -- [Florian Quiblier](https://github.com/fofoy) -- [Anthony Heber](https://github.com/aheber) -- [Evan Heidtmann](https://github.com/ezheidtmann) -- [luoqpolyvi](https://github.com/luoqpolyvi) -- [Brian Vanderbusch](https://github.com/LongLiveCHIEF) -- [daprahamian](https://github.com/daprahamian) -- [pgorecki](https://github.com/pgorecki) -- [CaoJun](https://github.com/mdsb100) -- [nalabjp](https://github.com/nalabjp) -- [shaoshuai0102](https://github.com/shaoshuai0102) -- [Sakesan Panjamawat](https://github.com/sakp) - -License -------- - -MIT - - -Changelog -========= - -1.0.0 (2014-08-19) ------------------- - -- Not fully stable, need more tests -- Now we have a CHANGELOG +## DEPRECATED, see https://github.com/node-gitlab/node-gitlab diff --git a/examples/bad-token.coffee b/examples/bad-token.coffee new file mode 100644 index 0000000..1052d56 --- /dev/null +++ b/examples/bad-token.coffee @@ -0,0 +1,19 @@ +#!/usr/bin/env coffee + +# clear terminal +process.stdout.write '\u001B[2J\u001B[0;0f' + + +Gitlab = require('..') + +credentials = + url: 'http://demo.gitlab.com' + token: 'bad-token' + +gitlab = new Gitlab + url: credentials.url + token: credentials.token + +gitlab.projects.all (err, resp, result) -> + console.log "having: ", err: err, resp: resp, result: result + console.log "should get: { err: '401 Unauthorized', resp: undefined, result: undefined }" diff --git a/examples/bad-token.js b/examples/bad-token.js new file mode 100644 index 0000000..398bfef --- /dev/null +++ b/examples/bad-token.js @@ -0,0 +1,27 @@ +(function() { + var Gitlab, credentials, gitlab; + + process.stdout.write('\u001B[2J\u001B[0;0f'); + + Gitlab = require('..'); + + credentials = { + url: 'http://demo.gitlab.com', + token: 'bad-token' + }; + + gitlab = new Gitlab({ + url: credentials.url, + token: credentials.token + }); + + gitlab.projects.all(function(err, resp, result) { + console.log("having: ", { + err: err, + resp: resp, + result: result + }); + return console.log("should get: { err: '401 Unauthorized', resp: undefined, result: undefined }"); + }); + +}).call(this); diff --git a/examples/create-service.coffee b/examples/create-service.coffee new file mode 100644 index 0000000..c141a44 --- /dev/null +++ b/examples/create-service.coffee @@ -0,0 +1,27 @@ +#!/usr/bin/env coffee + +# clear terminal +process.stdout.write '\u001B[2J\u001B[0;0f' + + +Gitlab = require('..') + +credentials = require './credentials' + +gitlab = new Gitlab + url: credentials.url + token: credentials.token + +projectId = parseInt process.argv[2] +serviceName = process.argv[3] +serviceParams = + webhook: process.argv[4] + username: process.argv[5] + channel: process.argv[6] + + + +gitlab.projects.services.update projectId, serviceName, serviceParams, (service) -> + console.log + console.log "=== Service ===" + console.log service diff --git a/examples/create-service.js b/examples/create-service.js new file mode 100644 index 0000000..6ae516e --- /dev/null +++ b/examples/create-service.js @@ -0,0 +1,31 @@ +(function() { + var Gitlab, credentials, gitlab, projectId, serviceName, serviceParams; + + process.stdout.write('\u001B[2J\u001B[0;0f'); + + Gitlab = require('..'); + + credentials = require('./credentials'); + + gitlab = new Gitlab({ + url: credentials.url, + token: credentials.token + }); + + projectId = parseInt(process.argv[2]); + + serviceName = process.argv[3]; + + serviceParams = { + webhook: process.argv[4], + username: process.argv[5], + channel: process.argv[6] + }; + + gitlab.projects.services.update(projectId, serviceName, serviceParams, function(service) { + console.log; + console.log("=== Service ==="); + return console.log(service); + }); + +}).call(this); diff --git a/examples/delete-service.coffee b/examples/delete-service.coffee new file mode 100644 index 0000000..25abe3d --- /dev/null +++ b/examples/delete-service.coffee @@ -0,0 +1,23 @@ +#!/usr/bin/env coffee + +# clear terminal +process.stdout.write '\u001B[2J\u001B[0;0f' + + +Gitlab = require('..') + +credentials = require './credentials' + +gitlab = new Gitlab + url: credentials.url + token: credentials.token + +projectId = parseInt process.argv[2] +serviceName = process.argv[3] + + + +gitlab.projects.services.remove projectId, serviceName, (service) -> + console.log + console.log "=== Service ===" + console.log service diff --git a/examples/delete-service.js b/examples/delete-service.js new file mode 100644 index 0000000..57364e7 --- /dev/null +++ b/examples/delete-service.js @@ -0,0 +1,25 @@ +(function() { + var Gitlab, credentials, gitlab, projectId, serviceName; + + process.stdout.write('\u001B[2J\u001B[0;0f'); + + Gitlab = require('..'); + + credentials = require('./credentials'); + + gitlab = new Gitlab({ + url: credentials.url, + token: credentials.token + }); + + projectId = parseInt(process.argv[2]); + + serviceName = process.argv[3]; + + gitlab.projects.services.remove(projectId, serviceName, function(service) { + console.log; + console.log("=== Service ==="); + return console.log(service); + }); + +}).call(this); diff --git a/examples/example.credentials.js b/examples/example.credentials.js index f1dcef6..2561918 100755 --- a/examples/example.credentials.js +++ b/examples/example.credentials.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { module.exports = { url: 'http://demo.gitlab.com', diff --git a/examples/list-projects.js b/examples/list-projects.js index c388fdf..c06d86a 100755 --- a/examples/list-projects.js +++ b/examples/list-projects.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var Gitlab, credentials, gitlab; @@ -14,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 3787886..272bad1 100644 --- a/examples/list-users.js +++ b/examples/list-users.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var Gitlab, credentials, gitlab; @@ -14,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 91612dc..87f4221 100644 --- a/examples/reset-hooks.js +++ b/examples/reset-hooks.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var Gitlab, credentials, gitlab; @@ -14,37 +13,37 @@ }); 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"); + 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); }); } } - return console.log("" + url + " is already OK"); + return console.log(url + " is already OK"); } else { return gitlab.projects.hooks.add(project.id, url, function() { - return console.log("" + url + " has been added"); + return console.log(url + " has been added"); }); } }); })()); } - return _results; + return results; }); }).call(this); diff --git a/examples/show-file.coffee b/examples/show-file.coffee new file mode 100644 index 0000000..1f1adef --- /dev/null +++ b/examples/show-file.coffee @@ -0,0 +1,24 @@ +#!/usr/bin/env coffee + +# clear terminal +process.stdout.write '\u001B[2J\u001B[0;0f' + + +Gitlab = require('..') + +credentials = require './credentials' + +gitlab = new Gitlab + url: credentials.url + token: credentials.token + +projectId = parseInt process.argv[2] + +gitlab.projects.repository.showFile {projectId: projectId, ref: 'master', file_path: 'README.md'}, (file) -> + console.log + console.log "=== File ===" + console.log file + if file + console.log + console.log "=== Content ===" + console.log (new Buffer(file.content, 'base64')).toString() diff --git a/examples/show-file.js b/examples/show-file.js new file mode 100644 index 0000000..00c17ff --- /dev/null +++ b/examples/show-file.js @@ -0,0 +1,32 @@ +(function() { + var Gitlab, credentials, gitlab, projectId; + + process.stdout.write('\u001B[2J\u001B[0;0f'); + + Gitlab = require('..'); + + credentials = require('./credentials'); + + gitlab = new Gitlab({ + url: credentials.url, + token: credentials.token + }); + + projectId = parseInt(process.argv[2]); + + gitlab.projects.repository.showFile({ + projectId: projectId, + ref: 'master', + file_path: 'README.md' + }, function(file) { + console.log; + console.log("=== File ==="); + console.log(file); + if (file) { + console.log; + console.log("=== Content ==="); + return console.log((new Buffer(file.content, 'base64')).toString()); + } + }); + +}).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/examples/show-project.js b/examples/show-project.js index 2cdf52b..df2f87a 100755 --- a/examples/show-project.js +++ b/examples/show-project.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var Gitlab, credentials, gitlab, projectId; @@ -27,4 +26,12 @@ return console.log(members); }); + gitlab.projects.milestones.list(projectId, { + per_page: 100 + }, function(milestones) { + console.log(""); + console.log("=== Milestones ==="); + return console.log(milestones); + }); + }).call(this); diff --git a/examples/show-service.coffee b/examples/show-service.coffee new file mode 100644 index 0000000..ebbe7d2 --- /dev/null +++ b/examples/show-service.coffee @@ -0,0 +1,21 @@ +#!/usr/bin/env coffee + +# clear terminal +process.stdout.write '\u001B[2J\u001B[0;0f' + + +Gitlab = require('..') + +credentials = require './credentials' + +gitlab = new Gitlab + url: credentials.url + token: credentials.token + +projectId = parseInt process.argv[2] +serviceName = process.argv[3] + +gitlab.projects.services.show projectId, serviceName, (service) -> + console.log + console.log "=== Service ===" + console.log service diff --git a/examples/show-service.js b/examples/show-service.js new file mode 100644 index 0000000..c73c096 --- /dev/null +++ b/examples/show-service.js @@ -0,0 +1,25 @@ +(function() { + var Gitlab, credentials, gitlab, projectId, serviceName; + + process.stdout.write('\u001B[2J\u001B[0;0f'); + + Gitlab = require('..'); + + credentials = require('./credentials'); + + gitlab = new Gitlab({ + url: credentials.url, + token: credentials.token + }); + + projectId = parseInt(process.argv[2]); + + serviceName = process.argv[3]; + + gitlab.projects.services.show(projectId, serviceName, function(service) { + console.log; + console.log("=== Service ==="); + return console.log(service); + }); + +}).call(this); diff --git a/examples/show-user.js b/examples/show-user.js index d692363..29a8298 100755 --- a/examples/show-user.js +++ b/examples/show-user.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var Gitlab, credentials, gitlab, userId; diff --git a/lib/ApiBase.js b/lib/ApiBase.js index 631134d..2b14332 100644 --- a/lib/ApiBase.js +++ b/lib/ApiBase.js @@ -1,24 +1,23 @@ -// Generated by CoffeeScript 1.7.1 (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(options) { this.options = options; - this.init = __bind(this.init, this); - this.handleOptions = __bind(this.handleOptions, this); + 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()"); }; @@ -29,7 +28,9 @@ this.groups = require('./Models/Groups')(this.client); this.projects = require('./Models/Projects')(this.client); this.issues = require('./Models/Issues')(this.client); - return this.users = require('./Models/Users')(this.client); + this.notes = require('./Models/Notes')(this.client); + this.users = require('./Models/Users')(this.client); + return this.labels = require('./Models/Labels')(this.client); }; return ApiBase; diff --git a/lib/ApiBaseHTTP.js b/lib/ApiBaseHTTP.js index 52ae2c8..b9c30e8 100644 --- a/lib/ApiBaseHTTP.js +++ b/lib/ApiBaseHTTP.js @@ -1,9 +1,8 @@ -// Generated by CoffeeScript 1.7.1 (function() { var ApiBase, debug, querystring, slumber, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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'); @@ -13,40 +12,41 @@ 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"; } - if (!this.options.token) { - throw "`private_token` is mandatory"; + if (!(this.options.token || this.options.oauth_token)) { + throw "`private_token` or `oauth_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) { this.options.slumber.auth = this.options.auth; } @@ -64,7 +64,15 @@ if (opts.__query == null) { opts.__query = {}; } - opts.__query.private_token = this.options.token; + if (this.options.token) { + opts.headers = { + 'PRIVATE-TOKEN': this.options.token + }; + } else { + opts.headers = { + 'Authorization': 'Bearer ' + this.options.oauth_token + }; + } return opts; }; @@ -72,15 +80,12 @@ return (function(_this) { return function(err, response, ret) { var arity; - if (err) { - debug('an error has occured', err); - } arity = fn.length; switch (arity) { case 1: return fn(ret); case 2: - return fn(err, ret); + return fn(err, ret || JSON.parse(response.body).message); case 3: return fn(err, response, ret); } diff --git a/lib/ApiV3.js b/lib/ApiV3.js index 61f9ee7..6b5c3fb 100644 --- a/lib/ApiV3.js +++ b/lib/ApiV3.js @@ -1,19 +1,18 @@ -// Generated by CoffeeScript 1.7.1 (function() { var ApiBaseHTTP, debug, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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 d621e47..80e44c4 100644 --- a/lib/BaseModel.js +++ b/lib/BaseModel.js @@ -1,15 +1,14 @@ -// Generated by CoffeeScript 1.7.1 (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(client) { this.client = client; - this._init = __bind(this._init, this); - this.load = __bind(this.load, this); + this._init = bind(this._init, this); + this.load = bind(this.load, this); this._init(); } diff --git a/lib/Models/BaseModel.js b/lib/Models/BaseModel.js deleted file mode 100644 index c02febc..0000000 --- a/lib/Models/BaseModel.js +++ /dev/null @@ -1,32 +0,0 @@ -// Generated by CoffeeScript 1.6.3 -(function() { - var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - - module.exports = (function() { - function exports(client) { - this.client = client; - this._init = __bind(this._init, this); - this.load = __bind(this.load, this); - this._init(); - } - - exports.prototype.load = function(model) { - return require("./" + model)(this.client); - }; - - exports.prototype._init = function() { - this.debug = this.client.debug; - this.get = this.client.get; - this.post = this.client.post; - this.put = this.client.put; - this["delete"] = this.client["delete"]; - if (this.init != null) { - return this.init(); - } - }; - - return exports; - - })(); - -}).call(this); diff --git a/lib/Models/Groups.js b/lib/Models/Groups.js index d29e3f2..9678ad3 100644 --- a/lib/Models/Groups.js +++ b/lib/Models/Groups.js @@ -1,24 +1,42 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, Groups, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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.listMembers = __bind(this.listMembers, this); - this.listProjects = __bind(this.listProjects, this); - this.show = __bind(this.show, this); - this.all = __bind(this.all, this); + this.search = bind(this.search, this); + this.deleteGroup = bind(this.deleteGroup, this); + this.addProject = bind(this.addProject, this); + this.create = bind(this.create, this); + this.removeMember = bind(this.removeMember, this); + this.editMember = bind(this.editMember, 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); } + Groups.prototype.init = function() { + return this.access_levels = { + GUEST: 10, + REPORTER: 20, + DEVELOPER: 30, + MASTER: 40, + OWNER: 50 + }; + }; + Groups.prototype.all = function(params, fn) { + var cb, data; if (params == null) { params = {}; } @@ -30,16 +48,33 @@ params = {}; } this.debug("Groups::all()"); + if (params.page == null) { + params.page = 1; + } if (params.per_page == null) { params.per_page = 100; } - return this.get("groups", params, (function(_this) { - return function(data) { - if (fn) { - return fn(data); + data = []; + cb = (function(_this) { + return function(err, retData) { + if (err) { + if (fn) { + return fn(retData || data); + } + } else if (retData.length === params.per_page) { + _this.debug("Recurse Groups::all()"); + data = data.concat(retData); + params.page++; + return _this.get("groups", params, cb); + } else { + data = data.concat(retData); + if (fn) { + return fn(data); + } } }; - })(this)); + })(this); + return this.get("groups", params, cb); }; Groups.prototype.show = function(groupId, fn) { @@ -84,6 +119,138 @@ })(this)); }; + Groups.prototype.addMember = function(groupId, userId, accessLevel, fn) { + var checkAccessLevel, params; + if (fn == null) { + fn = null; + } + 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]; + if (accessLevel === access_level) { + return true; + } + } + return false; + }; + })(this); + if (!checkAccessLevel()) { + throw "`accessLevel` must be one of " + (JSON.stringify(this.access_levels)); + } + params = { + user_id: userId, + access_level: accessLevel + }; + return this.post("groups/" + (parseInt(groupId)) + "/members", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Groups.prototype.editMember = function(groupId, userId, accessLevel, fn) { + var checkAccessLevel, params; + if (fn == null) { + fn = null; + } + this.debug("Groups::editMember(" + 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]; + if (accessLevel === access_level) { + return true; + } + } + return false; + }; + })(this); + if (!checkAccessLevel()) { + throw "`accessLevel` must be one of " + (JSON.stringify(this.access_levels)); + } + params = { + access_level: accessLevel + }; + return this.put("groups/" + (parseInt(groupId)) + "/members/" + (parseInt(userId)), params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Groups.prototype.removeMember = function(groupId, userId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Groups::removeMember(" + groupId + ", " + userId + ")"); + return this["delete"]("groups/" + (parseInt(groupId)) + "/members/" + (parseInt(userId)), function(data) { + if (fn) { + return fn(data); + } + }); + }; + + 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.deleteGroup = function(groupId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Groups::delete(" + groupId + ")"); + return this["delete"]("groups/" + (parseInt(groupId)), 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 new file mode 100644 index 0000000..54bd415 --- /dev/null +++ b/lib/Models/IssueNotes.js @@ -0,0 +1,69 @@ +(function() { + var BaseModel, IssueNotes, Utils, + 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(superClass) { + extend(IssueNotes, superClass); + + function IssueNotes() { + this.all = bind(this.all, this); + return IssueNotes.__super__.constructor.apply(this, arguments); + } + + IssueNotes.prototype.all = function(projectId, issueId, params, fn) { + var cb, data; + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("IssueNotes::notes()"); + if ('function' === typeof params) { + fn = params; + params = {}; + } + if (params.page == null) { + params.page = 1; + } + if (params.per_page == null) { + params.per_page = 100; + } + data = []; + cb = (function(_this) { + return function(err, retData) { + if (err) { + if (fn) { + return fn(data); + } + } else if (retData.length === params.per_page) { + _this.debug("Recurse IssueNotes::all()"); + data = data.concat(retData); + params.page++; + return _this.get("projects/" + (Utils.parseProjectId(projectId)) + "/issues/" + (parseInt(issueId)) + "/notes", params, cb); + } else { + data = data.concat(retData); + if (fn) { + return fn(data); + } + } + }; + })(this); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/issues/" + (parseInt(issueId)) + "/notes", params, cb); + }; + + return IssueNotes; + + })(BaseModel); + + module.exports = function(client) { + return new IssueNotes(client); + }; + +}).call(this); diff --git a/lib/Models/Issues.js b/lib/Models/Issues.js index c1dab62..aa48f0e 100644 --- a/lib/Models/Issues.js +++ b/lib/Models/Issues.js @@ -1,20 +1,22 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, Issues, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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.unsubscribe = bind(this.unsubscribe, this); + this.subscribe = bind(this.subscribe, this); + this.remove = bind(this.remove, 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); } @@ -63,7 +65,7 @@ fn = null; } this.debug("Issues::show()"); - if (projectId.indexOf("/") !== -1) { + if (projectId.toString().indexOf("/") !== -1) { projectId = encodeURIComponent(projectId); } else { projectId = parseInt(projectId); @@ -127,6 +129,75 @@ }); }; + Issues.prototype.remove = function(projectId, issueId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Issues::remove()"); + if (projectId.toString().indexOf("/") !== -1) { + projectId = encodeURIComponent(projectId); + } else { + projectId = parseInt(projectId); + } + if (issueId.toString().indexOf("/") !== -1) { + issueId = encodeURIComponent(issueId); + } else { + issueId = parseInt(issueId); + } + return this["delete"]("projects/" + projectId + "/issues/" + issueId, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Issues.prototype.subscribe = function(projectId, issueId, params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Issues::subscribe()"); + if (projectId.toString().indexOf("/") !== -1) { + projectId = encodeURIComponent(projectId); + } else { + projectId = parseInt(projectId); + } + if (issueId.toString().indexOf("/") !== -1) { + issueId = encodeURIComponent(issueId); + } else { + issueId = parseInt(issueId); + } + return this.post("projects/" + projectId + "/issues/" + issueId + "/subscription", function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Issues.prototype.unsubscribe = function(projectId, issueId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Issues::unsubscribe()"); + if (projectId.toString().indexOf("/") !== -1) { + projectId = encodeURIComponent(projectId); + } else { + projectId = parseInt(projectId); + } + if (issueId.toString().indexOf("/") !== -1) { + issueId = encodeURIComponent(issueId); + } else { + issueId = parseInt(issueId); + } + return this["delete"]("projects/" + projectId + "/issues/" + issueId + "/subscription", function(data) { + if (fn) { + return fn(data); + } + }); + }; + return Issues; })(BaseModel); diff --git a/lib/Models/Labels.js b/lib/Models/Labels.js new file mode 100644 index 0000000..339700d --- /dev/null +++ b/lib/Models/Labels.js @@ -0,0 +1,42 @@ +(function() { + var BaseModel, Labels, Utils, + 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(superClass) { + extend(Labels, superClass); + + function Labels() { + this.create = bind(this.create, this); + return Labels.__super__.constructor.apply(this, arguments); + } + + Labels.prototype.create = function(projectId, params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Labels::create()"); + return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/labels", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + return Labels; + + })(BaseModel); + + module.exports = function(client) { + return new Labels(client); + }; + +}).call(this); diff --git a/lib/Models/Notes.js b/lib/Models/Notes.js new file mode 100644 index 0000000..c0f1e89 --- /dev/null +++ b/lib/Models/Notes.js @@ -0,0 +1,42 @@ +(function() { + var BaseModel, Notes, Utils, + 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(superClass) { + extend(Notes, superClass); + + function Notes() { + this.create = bind(this.create, this); + return Notes.__super__.constructor.apply(this, arguments); + } + + Notes.prototype.create = function(projectId, issueId, params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Notes::create()"); + return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/issues/" + (parseInt(issueId)) + "/notes", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + return Notes; + + })(BaseModel); + + module.exports = function(client) { + return new Notes(client); + }; + +}).call(this); diff --git a/lib/Models/Pipelines.js b/lib/Models/Pipelines.js new file mode 100644 index 0000000..c4cc687 --- /dev/null +++ b/lib/Models/Pipelines.js @@ -0,0 +1,41 @@ +(function() { + var BaseModel, Pipelines, Utils, + 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'); + + Pipelines = (function(superClass) { + extend(Pipelines, superClass); + + function Pipelines() { + this.all = bind(this.all, this); + return Pipelines.__super__.constructor.apply(this, arguments); + } + + Pipelines.prototype.all = function(projectId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Pipelines::all()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/pipelines", (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + return Pipelines; + + })(BaseModel); + + module.exports = function(client) { + return new Pipelines(client); + }; + +}).call(this); diff --git a/lib/Models/ProjectBuilds.js b/lib/Models/ProjectBuilds.js new file mode 100644 index 0000000..6c97b6f --- /dev/null +++ b/lib/Models/ProjectBuilds.js @@ -0,0 +1,85 @@ +(function() { + var BaseModel, ProjectBuilds, Utils, + 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'); + + ProjectBuilds = (function(superClass) { + extend(ProjectBuilds, superClass); + + function ProjectBuilds() { + this.triggerBuild = bind(this.triggerBuild, this); + this.showBuild = bind(this.showBuild, this); + this.listBuilds = bind(this.listBuilds, this); + return ProjectBuilds.__super__.constructor.apply(this, arguments); + } + + ProjectBuilds.prototype.listBuilds = function(projectId, params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + if ('function' === typeof params) { + fn = params; + params = {}; + } + if (params.page == null) { + params.page = 1; + } + if (params.per_page == null) { + params.per_page = 100; + } + this.debug("Projects::listBuilds()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectBuilds.prototype.showBuild = function(projectId, buildId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::build()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds/" + buildId, null, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectBuilds.prototype.triggerBuild = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::triggerBuild()"); + return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/trigger/builds", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + return ProjectBuilds; + + })(BaseModel); + + module.exports = function(client) { + return new ProjectBuilds(client); + }; + +}).call(this); diff --git a/lib/Models/ProjectDeployKeys.js b/lib/Models/ProjectDeployKeys.js index ec366b0..929a99d 100644 --- a/lib/Models/ProjectDeployKeys.js +++ b/lib/Models/ProjectDeployKeys.js @@ -1,21 +1,20 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, ProjectKeys, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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 c2c210c..20e1aff 100644 --- a/lib/Models/ProjectHooks.js +++ b/lib/Models/ProjectHooks.js @@ -1,23 +1,22 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, ProjectHooks, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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); } @@ -49,15 +48,16 @@ })(this)); }; - ProjectHooks.prototype.add = function(projectId, url, fn) { - var params; + ProjectHooks.prototype.add = function(projectId, params, fn) { if (fn == null) { fn = null; } + if ('string' === typeof params) { + params = { + url: params + }; + } this.debug("Projects::addHook()"); - params = { - url: url - }; return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/hooks", params, (function(_this) { return function(data) { if (fn) { diff --git a/lib/Models/ProjectIssues.js b/lib/Models/ProjectIssues.js index 35fccec..2844f80 100644 --- a/lib/Models/ProjectIssues.js +++ b/lib/Models/ProjectIssues.js @@ -1,22 +1,26 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, ProjectIssues, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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.list = bind(this.list, this); + this.init = bind(this.init, this); return ProjectIssues.__super__.constructor.apply(this, arguments); } + ProjectIssues.prototype.init = function() { + return this.notes = this.load('IssueNotes'); + }; + ProjectIssues.prototype.list = function(projectId, params, fn) { if (params == null) { params = {}; diff --git a/lib/Models/ProjectLabels.js b/lib/Models/ProjectLabels.js new file mode 100644 index 0000000..c9da1ea --- /dev/null +++ b/lib/Models/ProjectLabels.js @@ -0,0 +1,69 @@ +(function() { + var BaseModel, ProjectLabels, Utils, + 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(superClass) { + extend(ProjectLabels, superClass); + + function ProjectLabels() { + this.all = bind(this.all, this); + return ProjectLabels.__super__.constructor.apply(this, arguments); + } + + ProjectLabels.prototype.all = function(projectId, params, fn) { + var cb, data; + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("ProjectLabels::labels()"); + if ('function' === typeof params) { + fn = params; + params = {}; + } + if (params.page == null) { + params.page = 1; + } + if (params.per_page == null) { + params.per_page = 100; + } + data = []; + cb = (function(_this) { + return function(err, retData) { + if (err) { + if (fn) { + return fn(data); + } + } else if (retData.length === params.per_page) { + _this.debug("Recurse ProjectLabels::all()"); + data = data.concat(retData); + params.page++; + return _this.get("projects/" + (Utils.parseProjectId(projectId)) + "/labels", params, cb); + } else { + data = data.concat(retData); + if (fn) { + return fn(data); + } + } + }; + })(this); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/labels", params, cb); + }; + + return ProjectLabels; + + })(BaseModel); + + module.exports = function(client) { + return new ProjectLabels(client); + }; + +}).call(this); diff --git a/lib/Models/ProjectMembers.js b/lib/Models/ProjectMembers.js index 815103d..72b4b1d 100644 --- a/lib/Models/ProjectMembers.js +++ b/lib/Models/ProjectMembers.js @@ -1,23 +1,22 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, ProjectMembers, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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 43f2ca4..40a6283 100644 --- a/lib/Models/ProjectMergeRequests.js +++ b/lib/Models/ProjectMergeRequests.js @@ -1,23 +1,23 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, ProjectMergeRequests, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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.merge = bind(this.merge, 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); } @@ -72,9 +72,11 @@ id: Utils.parseProjectId(projectId), source_branch: sourceBranch, target_branch: targetBranch, - assignee_id: parseInt(assigneeId), title: title }; + if (assigneeId !== void 0) { + params.assigneeId = parseInt(assigneeId); + } return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/merge_requests", params, (function(_this) { return function(data) { if (fn) { @@ -120,6 +122,22 @@ })(this)); }; + ProjectMergeRequests.prototype.merge = function(projectId, mergerequestId, params, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::acceptMergeRequest()"); + params.id = Utils.parseProjectId(projectId); + params.merge_request_id = parseInt(mergerequestId); + return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/merge_request/" + (parseInt(mergerequestId)) + "/merge", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + return ProjectMergeRequests; })(BaseModel); diff --git a/lib/Models/ProjectMilestones.js b/lib/Models/ProjectMilestones.js index 3e25fef..8ae0082 100644 --- a/lib/Models/ProjectMilestones.js +++ b/lib/Models/ProjectMilestones.js @@ -1,37 +1,68 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, ProjectMilestones, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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) { + var list; + + 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.all = bind(this.all, this); return ProjectMilestones.__super__.constructor.apply(this, arguments); } - ProjectMilestones.prototype.list = function(projectId, fn) { + list = function(projectId, fn) { if (fn == null) { fn = null; } - this.debug("Projects::milestones()"); - return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/milestones", (function(_this) { - return function(data) { - if (fn) { - return fn(data); + console.log('DEPRECATED: milestone.list. Use milestone.all instead'); + return this.all.apply(this, arguments); + }; + + ProjectMilestones.prototype.all = function(projectId, fn) { + var cb, data, params; + if (fn == null) { + fn = null; + } + this.debug("Projects::Milestones::all()"); + params = {}; + if (params.page == null) { + params.page = 1; + } + if (params.per_page == null) { + params.per_page = 100; + } + data = []; + cb = (function(_this) { + return function(err, retData) { + if (err) { + if (fn) { + return fn(retData || data); + } + } else if (retData.length === params.per_page) { + _this.debug("Recurse Projects::Milestones::all()"); + data = data.concat(retData); + params.page++; + return _this.get("projects/" + (Utils.parseProjectId(projectId)) + "/milestones", params, cb); + } else { + data = data.concat(retData); + if (fn) { + return fn(data); + } } }; - })(this)); + })(this); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/milestones", params, cb); }; ProjectMilestones.prototype.show = function(projectId, milestoneId, fn) { diff --git a/lib/Models/ProjectRepository.js b/lib/Models/ProjectRepository.js index 2440a18..90e3df1 100644 --- a/lib/Models/ProjectRepository.js +++ b/lib/Models/ProjectRepository.js @@ -1,32 +1,35 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, ProjectRepository, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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.compare = bind(this.compare, 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.showTag = bind(this.showTag, this); + this.deleteTag = bind(this.deleteTag, this); + this.addTag = bind(this.addTag, 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); } @@ -58,12 +61,15 @@ })(this)); }; - ProjectRepository.prototype.protectBranch = function(projectId, branchId, fn) { + ProjectRepository.prototype.protectBranch = function(projectId, branchId, params, fn) { + if (params == null) { + params = {}; + } if (fn == null) { fn = null; } this.debug("Projects::protectBranch()"); - return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + (encodeURI(branchId)) + "/protect", null, (function(_this) { + return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + (encodeURI(branchId)) + "/protect", params, (function(_this) { return function(data) { if (fn) { return fn(data); @@ -117,6 +123,51 @@ })(this)); }; + ProjectRepository.prototype.addTag = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::addTag()"); + return this.post("projects/" + (Utils.parseProjectId(params.id)) + "/repository/tags", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectRepository.prototype.deleteTag = function(projectId, tagName, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::deleteTag()"); + return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/repository/tags/" + (encodeURI(tagName)), (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectRepository.prototype.showTag = function(projectId, tagName, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::showTag()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/tags/" + (encodeURI(tagName)), (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + ProjectRepository.prototype.listTags = function(projectId, fn) { if (fn == null) { fn = null; @@ -145,12 +196,12 @@ })(this)); }; - ProjectRepository.prototype.showCommit = function(projectId, commitId, fn) { + ProjectRepository.prototype.showCommit = function(projectId, sha, fn) { if (fn == null) { fn = null; } this.debug("Projects::commit()"); - return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + (parseInt(commitId)), (function(_this) { + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/commits/" + sha, (function(_this) { return function(data) { if (fn) { return fn(data); @@ -164,7 +215,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); @@ -195,12 +246,29 @@ }; ProjectRepository.prototype.showFile = function(projectId, params, fn) { + if (params == null) { + params = {}; + } if (fn == null) { fn = null; } + if ('function' === typeof params) { + fn = params; + params = projectId; + } else { + params.projectId = projectId; + } this.debug("Projects::showFile()", params); if (params.file_path && params.ref) { - return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/files", params, (function(_this) { + return this.get("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/files", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + } else if (params.file_path && params.file_id) { + return this.get(("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/raw_blobs/") + params.file_id, params, (function(_this) { return function(data) { if (fn) { return fn(data); @@ -244,6 +312,23 @@ })(this)); }; + ProjectRepository.prototype.compare = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::compare()", params); + return this.get("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/compare", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + return ProjectRepository; })(BaseModel); diff --git a/lib/Models/ProjectServices.js b/lib/Models/ProjectServices.js new file mode 100644 index 0000000..846733c --- /dev/null +++ b/lib/Models/ProjectServices.js @@ -0,0 +1,71 @@ +(function() { + var BaseModel, ProjectServices, Utils, + 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'); + + ProjectServices = (function(superClass) { + extend(ProjectServices, superClass); + + function ProjectServices() { + this.remove = bind(this.remove, this); + this.update = bind(this.update, this); + this.show = bind(this.show, this); + return ProjectServices.__super__.constructor.apply(this, arguments); + } + + ProjectServices.prototype.show = function(projectId, serviceName, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::showService()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/services/" + serviceName, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectServices.prototype.update = function(projectId, serviceName, params, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::updateService()"); + return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/services/" + serviceName, params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectServices.prototype.remove = function(projectId, serviceName, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects:removeService()"); + return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/services/" + serviceName, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + return ProjectServices; + + })(BaseModel); + + module.exports = function(client) { + return new ProjectServices(client); + }; + +}).call(this); diff --git a/lib/Models/Projects.js b/lib/Models/Projects.js index 837686e..7f3351e 100644 --- a/lib/Models/Projects.js +++ b/lib/Models/Projects.js @@ -1,27 +1,37 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, Projects, Utils, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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.removeTrigger = bind(this.removeTrigger, this); + this.createTrigger = bind(this.createTrigger, this); + this.showTrigger = bind(this.showTrigger, this); + this.listTriggers = bind(this.listTriggers, this); + this.search = bind(this.search, this); + this.share = bind(this.share, this); + this.fork = bind(this.fork, 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.edit = bind(this.edit, this); + this.create_for_user = bind(this.create_for_user, this); + this.create = bind(this.create, this); + this.show = bind(this.show, this); + this.allAdmin = bind(this.allAdmin, this); + this.all = bind(this.all, this); + this.init = bind(this.init, this); return Projects.__super__.constructor.apply(this, arguments); } @@ -29,13 +39,19 @@ this.members = this.load('ProjectMembers'); this.hooks = this.load('ProjectHooks'); this.issues = this.load('ProjectIssues'); + this.labels = this.load('ProjectLabels'); this.repository = this.load('ProjectRepository'); this.milestones = this.load('ProjectMilestones'); this.deploy_keys = this.load('ProjectDeployKeys'); - return this.merge_requests = this.load('ProjectMergeRequests'); + this.merge_requests = this.load('ProjectMergeRequests'); + this.services = this.load('ProjectServices'); + this.builds = this.load('ProjectBuilds'); + this.pipelines = this.load('Pipelines'); + return this.runners = this.load('Runners'); }; Projects.prototype.all = function(params, fn) { + var cb, data; if (params == null) { params = {}; } @@ -53,30 +69,69 @@ if (params.per_page == null) { params.per_page = 100; } - return (function() { - var cb, data; - data = []; - cb = (function(_this) { - return function(err, retData) { - if (err) { - if (fn) { - return fn(data); - } - } else if (retData.length === params.per_page) { - _this.debug("Recurse Projects::all()"); - data = data.concat(retData); - params.page++; - return _this.get("projects", params, cb); - } else { - data = data.concat(retData); - if (fn) { - return fn(data); - } + data = []; + cb = (function(_this) { + return function(err, retData) { + if (err) { + if (fn) { + return fn(retData || data); } - }; - })(this); - return this.get("projects", params, cb); - }).bind(this)(); + } else if (retData.length === params.per_page) { + _this.debug("Recurse Projects::all()"); + data = data.concat(retData); + params.page++; + return _this.get("projects", params, cb); + } else { + data = data.concat(retData); + if (fn) { + return fn(data); + } + } + }; + })(this); + return this.get("projects", params, cb); + }; + + Projects.prototype.allAdmin = function(params, fn) { + var cb, data; + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + if ('function' === typeof params) { + fn = params; + params = {}; + } + this.debug("Projects::allAdmin()"); + if (params.page == null) { + params.page = 1; + } + if (params.per_page == null) { + params.per_page = 100; + } + data = []; + cb = (function(_this) { + return function(err, retData) { + if (err) { + if (fn) { + return fn(retData || data); + } + } else if (retData.length === params.per_page) { + _this.debug("Recurse Projects::allAdmin()"); + data = data.concat(retData); + params.page++; + return _this.get("projects/all", params, cb); + } else { + data = data.concat(retData); + if (fn) { + return fn(data); + } + } + }; + })(this); + return this.get("projects/all", params, cb); }; Projects.prototype.show = function(projectId, fn) { @@ -108,6 +163,36 @@ }); }; + Projects.prototype.create_for_user = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::create_for_user()"); + return this.post("projects/user/" + params.user_id, params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Projects.prototype.edit = function(projectId, params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::edit()"); + return this.put("projects/" + (Utils.parseProjectId(projectId)), params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + Projects.prototype.addMember = function(params, fn) { if (params == null) { params = {}; @@ -161,7 +246,7 @@ fn = null; } this.debug("Projects::listCommits()"); - return this.get("projects/" + params.id + "/repository/commits", (function(_this) { + return this.get("projects/" + params.id + "/repository/commits", params, (function(_this) { return function(data) { if (fn) { return fn(data); @@ -187,6 +272,128 @@ })(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.fork = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::fork()"); + return this.post("projects/fork/" + params.id, params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Projects.prototype.share = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::share()"); + return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/share", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + 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)); + }; + + Projects.prototype.listTriggers = function(projectId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::listTriggers()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/triggers", (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + Projects.prototype.showTrigger = function(projectId, token, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::showTrigger()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/triggers/" + token, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + Projects.prototype.createTrigger = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::createTrigger()"); + return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/triggers", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Projects.prototype.removeTrigger = function(projectId, token, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::removeTrigger()"); + return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/triggers/" + token, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + return Projects; })(BaseModel); diff --git a/lib/Models/Runners.js b/lib/Models/Runners.js new file mode 100644 index 0000000..b37ab4d --- /dev/null +++ b/lib/Models/Runners.js @@ -0,0 +1,134 @@ +(function() { + var BaseModel, Runners, Utils, + 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'); + + Runners = (function(superClass) { + extend(Runners, superClass); + + function Runners() { + this.disable = bind(this.disable, this); + this.enable = bind(this.enable, this); + this.remove = bind(this.remove, this); + this.update = bind(this.update, this); + this.show = bind(this.show, this); + this.all = bind(this.all, this); + return Runners.__super__.constructor.apply(this, arguments); + } + + Runners.prototype.all = function(projectId, params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + if ('function' === typeof params) { + fn = params; + params = {}; + } + this.debug("Projects::Runners::all()"); + if (projectId != null) { + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/runners", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + } else { + return this.get("runners", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + } + }; + + Runners.prototype.show = function(runnerId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::Runners::show()"); + return this.get("runners/" + (parseInt(runnerId)), (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + Runners.prototype.update = function(runnerId, attributes, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::Runners::update"); + return this.put("runners/" + (parseInt(runnerId)), attributes, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + Runners.prototype.remove = function(runnerId, projectId, enable, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::Runners::runners()"); + return this["delete"]("runners/" + (parseInt(runnerId)), (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + Runners.prototype.enable = function(projectId, runnerId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::Runners::enable()"); + ({ + attributes: { + runner_id: parseInt(runnerId) + } + }); + return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/runners", attributes, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + Runners.prototype.disable = function(projectId, runnerId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::Runners::disable()"); + return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/runners/" + (parseInt(runnerId)), function(data) { + if (fn) { + return fn(data); + } + }); + }; + + return Runners; + + })(BaseModel); + + module.exports = function(client) { + return new Runners(client); + }; + +}).call(this); diff --git a/lib/Models/UserKeys.js b/lib/Models/UserKeys.js new file mode 100644 index 0000000..5cdb336 --- /dev/null +++ b/lib/Models/UserKeys.js @@ -0,0 +1,55 @@ +(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.addKey = bind(this.addKey, this); + 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)); + }; + + UserKeys.prototype.addKey = function(userId, title, key, fn) { + var params; + if (fn == null) { + fn = null; + } + params = { + title: title, + key: key + }; + return this.post("users/" + userId + "/keys", params, function(data) { + if (fn) { + return fn(data); + } + }); + }; + + 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 b11498d..7e95fe6 100644 --- a/lib/Models/Users.js +++ b/lib/Models/Users.js @@ -1,36 +1,69 @@ -// Generated by CoffeeScript 1.7.1 (function() { var BaseModel, Users, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __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; }; + 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.all = function(fn) { + Users.prototype.init = function() { + return this.keys = this.load('UserKeys'); + }; + + Users.prototype.all = function(params, fn) { + var cb, data; + if (params == null) { + params = {}; + } if (fn == null) { fn = null; } + if ('function' === typeof params) { + fn = params; + params = {}; + } this.debug("Users::all()"); - return this.get("users", (function(_this) { - return function(data) { - if (fn) { - return fn(data); + if (params.page == null) { + params.page = 1; + } + if (params.per_page == null) { + params.per_page = 100; + } + data = []; + cb = (function(_this) { + return function(err, retData) { + if (err) { + if (fn) { + return fn(retData || data); + } + } else if (retData.length === params.per_page) { + _this.debug("Recurse Users::all()"); + data = data.concat(retData); + params.page++; + return _this.get("users", params, cb); + } else { + data = data.concat(retData); + if (fn) { + return fn(data); + } } }; - })(this)); + })(this); + return this.get("users", params, cb); }; Users.prototype.current = function(fn) { @@ -91,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/lib/Utils.js b/lib/Utils.js index 8b895fa..50951fd 100644 --- a/lib/Utils.js +++ b/lib/Utils.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var Utils; diff --git a/lib/index.js b/lib/index.js index dd2ccc8..0a4b62a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var ApiV3; diff --git a/package.json b/package.json index 9d411ce..8dc7278 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitlab", - "version": "1.0.0", + "version": "1.8.0", "description": "GitLab API Nodejs library.", "main": "lib/index.js", "directories": { @@ -8,20 +8,24 @@ "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", - "url": "https://github.com/moul/node-gitlab" + "url": "https://github.com/node-gitlab/node-gitlab" }, "dependencies": { "debug": "*", - "slumber": "0.4.1" + "slumber": "0.9.0" }, "devDependencies": { - "coffee-script": "*", - "mocha": "" + "coffee-script": ">=1.9.1", + "mocha": "", + "proxyquire": "~1.0.1", + "chai": "~1.9.2", + "sinon": "~1.10.3", + "sinon-chai": "~2.6.0" }, "keywords": [ "gitlab", diff --git a/src/ApiBase.coffee b/src/ApiBase.coffee index 78bc959..11e77ed 100644 --- a/src/ApiBase.coffee +++ b/src/ApiBase.coffee @@ -16,6 +16,8 @@ class module.exports.ApiBase @groups = require('./Models/Groups') @client @projects = require('./Models/Projects') @client @issues = require('./Models/Issues') @client + @notes = require('./Models/Notes') @client #@repositories = require('./Models/Repositories') @client @users = require('./Models/Users') @client #@mergeRequests = require('./Models/MergeRequests') @client + @labels = require('./Models/Labels') @client diff --git a/src/ApiBaseHTTP.coffee b/src/ApiBaseHTTP.coffee index dcacdcf..2aa87cc 100644 --- a/src/ApiBaseHTTP.coffee +++ b/src/ApiBaseHTTP.coffee @@ -12,12 +12,14 @@ class module.exports.ApiBaseHTTP extends ApiBase unless @options.url throw "`url` is mandatory" - unless @options.token - throw "`private_token` is mandatory" + unless @options.token or @options.oauth_token + throw "`private_token` or `oauth_token` is mandatory" @options.slumber ?= {} @options.slumber.append_slash ?= false + @options.url = @options.url.replace(/\/api\/v3/, '') + if @options.auth? @options.slumber.auth = @options.auth @@ -30,17 +32,22 @@ class module.exports.ApiBaseHTTP extends ApiBase prepare_opts: (opts) => opts.__query ?= {} - opts.__query.private_token = @options.token + if @options.token + opts.headers = { 'PRIVATE-TOKEN': @options.token } + else + opts.headers = { 'Authorization': 'Bearer ' + @options.oauth_token } return opts fn_wrapper: (fn) => return (err, response, ret) => - if err - debug 'an error has occured', err arity = fn.length switch arity when 1 then fn ret - when 2 then fn err, ret + when 2 + if typeof response.body == 'object' + fn err, ret || response.body.message + else + fn err, ret || JSON.parse(response.body).message when 3 then fn err, response, ret get: (path, query={}, fn=null) => diff --git a/src/Models/Groups.coffee b/src/Models/Groups.coffee index 683a5cb..2f2f1d4 100644 --- a/src/Models/Groups.coffee +++ b/src/Models/Groups.coffee @@ -1,13 +1,37 @@ BaseModel = require '../BaseModel' class Groups extends BaseModel + init: => + @access_levels = + GUEST: 10 + REPORTER: 20 + DEVELOPER: 30 + MASTER: 40 + OWNER: 50 + all: (params = {}, fn = null) => if 'function' is typeof params fn = params params = {} @debug "Groups::all()" + + params.page ?= 1 params.per_page ?= 100 - @get "groups", params, (data) => fn data if fn + + data = [] + cb = (err, retData) => + if err + return fn(retData || data) if fn + else if retData.length == params.per_page + @debug "Recurse Groups::all()" + data = data.concat(retData) + params.page++ + return @get "groups", params, cb + else + data = data.concat(retData) + return fn data if fn + + @get "groups", params, cb show: (groupId, fn = null) => @debug "Groups::show()" @@ -16,9 +40,64 @@ 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 + addMember: (groupId, userId, accessLevel, fn=null) => + @debug "addMember(#{groupId}, #{userId}, #{accessLevel})" + + checkAccessLevel = => + for k, access_level of @access_levels + return true if accessLevel == access_level + false + + unless do checkAccessLevel + throw "`accessLevel` must be one of #{JSON.stringify @access_levels}" + + params = + user_id: userId + access_level: accessLevel + + @post "groups/#{parseInt groupId}/members", params, (data) -> fn data if fn + + editMember: (groupId, userId, accessLevel, fn = null) => + @debug "Groups::editMember(#{groupId}, #{userId}, #{accessLevel})" + + checkAccessLevel = => + for k, access_level of @access_levels + return true if accessLevel == access_level + false + + unless do checkAccessLevel + throw "`accessLevel` must be one of #{JSON.stringify @access_levels}" + + params = + access_level: accessLevel + + @put "groups/#{parseInt groupId}/members/#{parseInt userId}", params, (data) -> fn data if fn + + removeMember: (groupId, userId, fn = null) => + @debug "Groups::removeMember(#{groupId}, #{userId})" + @delete "groups/#{parseInt groupId}/members/#{parseInt userId}", (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 + + deleteGroup: (groupId, fn = null) => + @debug "Groups::delete(#{groupId})" + @delete "groups/#{parseInt groupId}", (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/IssueNotes.coffee b/src/Models/IssueNotes.coffee new file mode 100644 index 0000000..3e1ef8b --- /dev/null +++ b/src/Models/IssueNotes.coffee @@ -0,0 +1,29 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class IssueNotes extends BaseModel + all: (projectId, issueId, params = {}, fn = null) => + @debug "IssueNotes::notes()" + + if 'function' is typeof params + fn = params + params = {} + params.page ?= 1 + params.per_page ?= 100 + + data = [] + cb = (err, retData) => + if err + return fn data if fn + else if retData.length == params.per_page + @debug "Recurse IssueNotes::all()" + data = data.concat(retData) + params.page++ + return @get "projects/#{Utils.parseProjectId projectId}/issues/#{parseInt issueId}/notes", params, cb + else + data = data.concat(retData) + return fn data if fn + + @get "projects/#{Utils.parseProjectId projectId}/issues/#{parseInt issueId}/notes", params, cb + +module.exports = (client) -> new IssueNotes client diff --git a/src/Models/Issues.coffee b/src/Models/Issues.coffee index 4a1c783..7d381ce 100644 --- a/src/Models/Issues.coffee +++ b/src/Models/Issues.coffee @@ -1,7 +1,6 @@ BaseModel = require '../BaseModel' class Issues extends BaseModel - all: (params = {}, fn = null) => if 'function' is typeof params fn = params @@ -27,7 +26,7 @@ class Issues extends BaseModel show: (projectId, issueId, fn = null) => @debug "Issues::show()" - if projectId.indexOf("/") isnt -1 + if projectId.toString().indexOf("/") isnt -1 projectId = encodeURIComponent(projectId) else projectId = parseInt(projectId) @@ -43,21 +42,64 @@ class Issues extends BaseModel projectId = encodeURIComponent(projectId) else projectId = parseInt(projectId) - + @post "projects/#{projectId}/issues", params, (data) -> fn data if fn - + edit: (projectId, issueId, params = {}, fn = null) => @debug "Issues::edit()" if projectId.toString().indexOf("/") isnt -1 projectId = encodeURIComponent(projectId) else projectId = parseInt(projectId) - + if issueId.toString().indexOf("/") isnt -1 issueId = encodeURIComponent(issueId) else issueId = parseInt(issueId) - + @put "projects/#{projectId}/issues/#{issueId}", params, (data) -> fn data if fn + remove: (projectId, issueId, fn = null) => + @debug "Issues::remove()" + if projectId.toString().indexOf("/") isnt -1 + projectId = encodeURIComponent(projectId) + else + projectId = parseInt(projectId) + + if issueId.toString().indexOf("/") isnt -1 + issueId = encodeURIComponent(issueId) + else + issueId = parseInt(issueId) + + @delete "projects/#{projectId}/issues/#{issueId}", (data) -> fn data if fn + + subscribe: (projectId, issueId, params = {}, fn = null) => + @debug "Issues::subscribe()" + if projectId.toString().indexOf("/") isnt -1 + projectId = encodeURIComponent(projectId) + else + projectId = parseInt(projectId) + + if issueId.toString().indexOf("/") isnt -1 + issueId = encodeURIComponent(issueId) + else + issueId = parseInt(issueId) + + @post "projects/#{projectId}/issues/#{issueId}/subscription", (data) -> fn data if fn + + unsubscribe: (projectId, issueId, fn = null) => + @debug "Issues::unsubscribe()" + if projectId.toString().indexOf("/") isnt -1 + projectId = encodeURIComponent(projectId) + else + projectId = parseInt(projectId) + + if issueId.toString().indexOf("/") isnt -1 + issueId = encodeURIComponent(issueId) + else + issueId = parseInt(issueId) + + @delete "projects/#{projectId}/issues/#{issueId}/subscription", (data) -> fn data if fn + + module.exports = (client) -> new Issues client diff --git a/src/Models/Labels.coffee b/src/Models/Labels.coffee new file mode 100644 index 0000000..8f2f5a3 --- /dev/null +++ b/src/Models/Labels.coffee @@ -0,0 +1,10 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class Labels extends BaseModel + + create: (projectId, params = {}, fn = null) => + @debug "Labels::create()" + @post "projects/#{Utils.parseProjectId projectId}/labels", params, (data) -> fn data if fn + +module.exports = (client) -> new Labels client diff --git a/src/Models/Notes.coffee b/src/Models/Notes.coffee new file mode 100644 index 0000000..ae63b40 --- /dev/null +++ b/src/Models/Notes.coffee @@ -0,0 +1,10 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class Notes extends BaseModel + + create: (projectId, issueId, params = {}, fn = null) => + @debug "Notes::create()" + @post "projects/#{Utils.parseProjectId projectId}/issues/#{parseInt issueId}/notes", params, (data) -> fn data if fn + +module.exports = (client) -> new Notes client diff --git a/src/Models/Pipelines.coffee b/src/Models/Pipelines.coffee new file mode 100644 index 0000000..3c4bbde --- /dev/null +++ b/src/Models/Pipelines.coffee @@ -0,0 +1,9 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class Pipelines extends BaseModel + all: (projectId, fn = null) => + @debug "Pipelines::all()" + @get "projects/#{Utils.parseProjectId projectId}/pipelines", (data) => fn data if fn + +module.exports = (client) -> new Pipelines client diff --git a/src/Models/ProjectBuilds.coffee b/src/Models/ProjectBuilds.coffee new file mode 100644 index 0000000..a4699b1 --- /dev/null +++ b/src/Models/ProjectBuilds.coffee @@ -0,0 +1,26 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class ProjectBuilds extends BaseModel + + # === Builds + listBuilds: (projectId, params={}, fn = null) => + if 'function' is typeof params + fn = params + params={} + + params.page ?= 1 + params.per_page ?= 100 + + @debug "Projects::listBuilds()" + @get "projects/#{Utils.parseProjectId projectId}/builds", params, (data) => fn data if fn + + showBuild: (projectId, buildId, fn = null) => + @debug "Projects::build()" + @get "projects/#{Utils.parseProjectId projectId}/builds/#{buildId}", null, (data) => fn data if fn + + triggerBuild: (params={}, fn = null) => + @debug "Projects::triggerBuild()" + @post "projects/#{Utils.parseProjectId params.projectId}/trigger/builds", params, (data) -> fn data if fn + +module.exports = (client) -> new ProjectBuilds client diff --git a/src/Models/ProjectHooks.coffee b/src/Models/ProjectHooks.coffee index ab13603..36f3e74 100644 --- a/src/Models/ProjectHooks.coffee +++ b/src/Models/ProjectHooks.coffee @@ -10,10 +10,11 @@ class ProjectHooks extends BaseModel @debug "Projects::hook()" @get "projects/#{Utils.parseProjectId projectId}/hooks/#{parseInt hookId}", (data) => fn data if fn - add: (projectId, url, fn = null) => + add: (projectId, params, fn = null) => + if 'string' is typeof params + params = + url: params @debug "Projects::addHook()" - params = - url: url @post "projects/#{Utils.parseProjectId projectId}/hooks", params, (data) => fn data if fn update: (projectId, hookId, url, fn = null) => @@ -26,4 +27,4 @@ class ProjectHooks extends BaseModel @debug "Projects::removeHook()" @delete "projects/#{Utils.parseProjectId projectId}/hooks/#{parseInt hookId}", (data) => fn data if fn -module.exports = (client) -> new ProjectHooks client \ No newline at end of file +module.exports = (client) -> new ProjectHooks client diff --git a/src/Models/ProjectIssues.coffee b/src/Models/ProjectIssues.coffee index 4a8e28a..778b3e1 100644 --- a/src/Models/ProjectIssues.coffee +++ b/src/Models/ProjectIssues.coffee @@ -2,6 +2,9 @@ BaseModel = require '../BaseModel' Utils = require '../Utils' class ProjectIssues extends BaseModel + init: => + @notes = @load 'IssueNotes' + list: (projectId, params = {}, fn = null) => @debug "ProjectIssues::issues()" diff --git a/src/Models/ProjectLabels.coffee b/src/Models/ProjectLabels.coffee new file mode 100644 index 0000000..d8b1450 --- /dev/null +++ b/src/Models/ProjectLabels.coffee @@ -0,0 +1,29 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class ProjectLabels extends BaseModel + all: (projectId, params = {}, fn = null) => + @debug "ProjectLabels::labels()" + + if 'function' is typeof params + fn = params + params = {} + params.page ?= 1 + params.per_page ?= 100 + + data = [] + cb = (err, retData) => + if err + return fn data if fn + else if retData.length == params.per_page + @debug "Recurse ProjectLabels::all()" + data = data.concat(retData) + params.page++ + return @get "projects/#{Utils.parseProjectId projectId}/labels", params, cb + else + data = data.concat(retData) + return fn data if fn + + @get "projects/#{Utils.parseProjectId projectId}/labels", params, cb + +module.exports = (client) -> new ProjectLabels client diff --git a/src/Models/ProjectMergeRequests.coffee b/src/Models/ProjectMergeRequests.coffee index 067fbc8..7d7e80e 100644 --- a/src/Models/ProjectMergeRequests.coffee +++ b/src/Models/ProjectMergeRequests.coffee @@ -23,8 +23,8 @@ class ProjectMergeRequests extends BaseModel id: Utils.parseProjectId projectId source_branch: sourceBranch target_branch: targetBranch - assignee_id: parseInt assigneeId title: title + params.assigneeId = parseInt assigneeId unless assigneeId is undefined @post "projects/#{Utils.parseProjectId projectId}/merge_requests", params, (data) => fn data if fn update: (projectId, mergerequestId, params, fn = null) => @@ -43,4 +43,13 @@ class ProjectMergeRequests extends BaseModel note: note @post "projects/#{Utils.parseProjectId projectId}/merge_request/#{parseInt mergerequestId}/comments", params, (data) => fn data if fn + merge: (projectId, mergerequestId, params, fn = null) => + @debug "Projects::acceptMergeRequest()" + + params.id = Utils.parseProjectId projectId + params.merge_request_id = parseInt mergerequestId + + @put "projects/#{Utils.parseProjectId projectId}/merge_request/#{parseInt mergerequestId}/merge", params, (data) => fn data if fn + + module.exports = (client) -> new ProjectMergeRequests 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 e6777b9..9832901 100644 --- a/src/Models/ProjectRepository.coffee +++ b/src/Models/ProjectRepository.coffee @@ -12,9 +12,9 @@ class ProjectRepository extends BaseModel @debug "Projects::branch()" @get "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}", (data) => fn data if fn - protectBranch: (projectId, branchId, fn = null) => + protectBranch: (projectId, branchId, params = {}, fn = null) => @debug "Projects::protectBranch()" - @put "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}/protect", null, (data) => fn data if fn + @put "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}/protect", params, (data) => fn data if fn unprotectBranch: (projectId, branchId, fn = null) => @debug "Projects::unprotectBranch()" @@ -28,9 +28,19 @@ class ProjectRepository extends BaseModel @debug "Projects::deleteBranch()" @delete "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}", (data) => fn data if fn + # === Tags + addTag: (params = {}, fn = null) => + @debug "Projects::addTag()" + @post "projects/#{Utils.parseProjectId params.id}/repository/tags", params, (data) => fn data if fn + deleteTag: (projectId, tagName, fn = null) => + @debug "Projects::deleteTag()" + @delete "projects/#{Utils.parseProjectId projectId}/repository/tags/#{encodeURI tagName}", (data) => fn data if fn + + showTag: (projectId, tagName, fn = null) => + @debug "Projects::showTag()" + @get "projects/#{Utils.parseProjectId projectId}/repository/tags/#{encodeURI tagName}", (data) => fn data if fn - # === Tags listTags: (projectId, fn = null) => @debug "Projects::listTags()" @get "projects/#{Utils.parseProjectId projectId}/repository/tags", (data) => fn data if fn @@ -40,13 +50,13 @@ class ProjectRepository extends BaseModel @debug "Projects::listCommits()" @get "projects/#{Utils.parseProjectId projectId}/repository/commits", (data) => fn data if fn - showCommit: (projectId, commitId, fn = null) => + showCommit: (projectId, sha, fn = null) => @debug "Projects::commit()" - @get "projects/#{Utils.parseProjectId projectId}/repository/branches/#{parseInt commitId}", (data) => fn data if fn + @get "projects/#{Utils.parseProjectId projectId}/repository/commits/#{sha}", (data) => fn data if fn 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) => @@ -57,10 +67,18 @@ class ProjectRepository extends BaseModel @get "projects/#{Utils.parseProjectId projectId}/repository/tree", params, (data) => fn data if fn # == Files - showFile: (projectId, params, fn = null) => + showFile: (projectId, params = {}, fn = null) => + if 'function' is typeof params + fn = params + params = projectId + else + params.projectId = projectId + @debug "Projects::showFile()", params if params.file_path and params.ref - @post "projects/#{Utils.parseProjectId params.projectId}/repository/files", params, (data) => fn data if fn + @get "projects/#{Utils.parseProjectId params.projectId}/repository/files", params, (data) => fn data if fn + else if params.file_path and params.file_id + @get "projects/#{Utils.parseProjectId params.projectId}/repository/raw_blobs/" + params.file_id, params, (data) => fn data if fn createFile: (params = {}, fn = null) => @debug "Projects::createFile()", params @@ -70,6 +88,10 @@ class ProjectRepository extends BaseModel @debug "Projects::updateFile()", params @put "projects/#{Utils.parseProjectId params.projectId}/repository/files", params, (data) => fn data if fn + compare: (params = {}, fn = null) => + @debug "Projects::compare()", params + @get "projects/#{Utils.parseProjectId params.projectId}/repository/compare", params, (data) => fn data if fn + ## TODO: # - Raw file content # - Raw blob content diff --git a/src/Models/ProjectServices.coffee b/src/Models/ProjectServices.coffee new file mode 100644 index 0000000..551af7a --- /dev/null +++ b/src/Models/ProjectServices.coffee @@ -0,0 +1,18 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class ProjectServices extends BaseModel + + show: (projectId, serviceName, fn = null) => + @debug "Projects::showService()" + @get "projects/#{Utils.parseProjectId projectId}/services/#{serviceName}", (data) => fn data if fn + + update: (projectId, serviceName, params, fn = null) => + @debug "Projects::updateService()" + @put "projects/#{Utils.parseProjectId projectId}/services/#{serviceName}", params, (data) => fn data if fn + + remove: (projectId, serviceName, fn = null) => + @debug "Projects:removeService()" + @delete "projects/#{Utils.parseProjectId projectId}/services/#{serviceName}", (data) => fn data if fn + +module.exports = (client) -> new ProjectServices client diff --git a/src/Models/Projects.coffee b/src/Models/Projects.coffee index 2cb34c7..86ea8dd 100644 --- a/src/Models/Projects.coffee +++ b/src/Models/Projects.coffee @@ -6,10 +6,15 @@ class Projects extends BaseModel @members = @load 'ProjectMembers' @hooks = @load 'ProjectHooks' @issues = @load 'ProjectIssues' + @labels = @load 'ProjectLabels' @repository = @load 'ProjectRepository' @milestones = @load 'ProjectMilestones' @deploy_keys = @load 'ProjectDeployKeys' @merge_requests = @load 'ProjectMergeRequests' + @services = @load 'ProjectServices' + @builds = @load 'ProjectBuilds' + @pipelines = @load 'Pipelines' + @runners = @load 'Runners' all: (params={}, fn=null) => if 'function' is typeof params @@ -20,22 +25,44 @@ class Projects extends BaseModel params.page ?= 1 params.per_page ?= 100 - do (-> - data = [] - cb = (err, retData) => - if err - return fn data if fn - else if retData.length == params.per_page - @debug "Recurse Projects::all()" - data = data.concat(retData) - params.page++ - return @get "projects", params, cb - else - data = data.concat(retData) - return fn data if fn - - @get "projects", params, cb - ).bind(@) + data = [] + cb = (err, retData) => + if err + return fn(retData || data) if fn + else if retData.length == params.per_page + @debug "Recurse Projects::all()" + data = data.concat(retData) + params.page++ + return @get "projects", params, cb + else + data = data.concat(retData) + return fn data if fn + + @get "projects", params, cb + + allAdmin: (params={}, fn=null) => + if 'function' is typeof params + fn = params + params={} + @debug "Projects::allAdmin()" + + 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::allAdmin()" + data = data.concat(retData) + params.page++ + return @get "projects/all", params, cb + else + data = data.concat(retData) + return fn data if fn + + @get "projects/all", params, cb show: (projectId, fn=null) => @debug "Projects::show()" @@ -45,6 +72,14 @@ class Projects extends BaseModel @debug "Projects::create()" @post "projects", params, (data) -> fn data if fn + create_for_user: (params={}, fn=null) => + @debug "Projects::create_for_user()" + @post "projects/user/#{params.user_id}", params, (data) -> fn data if fn + + edit: (projectId, params={}, fn=null) => + @debug "Projects::edit()" + @put "projects/#{Utils.parseProjectId projectId}", params, (data) -> fn data if fn + addMember: (params={}, fn=null) => @debug "Projects::addMember()" @post "projects/#{params.id}/members", params, (data) -> fn data if fn @@ -59,10 +94,46 @@ class Projects extends BaseModel listCommits: (params={}, fn=null) => @debug "Projects::listCommits()" - @get "projects/#{params.id}/repository/commits", (data) => fn data if fn + @get "projects/#{params.id}/repository/commits", params, (data) => fn data if fn listTags: (params={}, fn=null) => @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 + + fork: (params={}, fn=null) => + @debug "Projects::fork()" + @post "projects/fork/#{params.id}", params, (data) -> fn data if fn + + share: (params={}, fn=null) => + @debug "Projects::share()" + @post "projects/#{Utils.parseProjectId params.projectId}/share", params, (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 + + listTriggers: (projectId, fn = null) => + @debug "Projects::listTriggers()" + @get "projects/#{Utils.parseProjectId projectId}/triggers", (data) => fn data if fn + + showTrigger: (projectId, token, fn = null) => + @debug "Projects::showTrigger()" + @get "projects/#{Utils.parseProjectId projectId}/triggers/#{token}", (data) => fn data if fn + + createTrigger: (params={}, fn=null) => + @debug "Projects::createTrigger()" + @post "projects/#{Utils.parseProjectId params.projectId}/triggers", params, (data) -> fn data if fn + + removeTrigger: (projectId, token, fn = null) => + @debug "Projects::removeTrigger()" + @delete "projects/#{Utils.parseProjectId projectId}/triggers/#{token}", (data) => fn data if fn + module.exports = (client) -> new Projects client diff --git a/src/Models/Runners.coffee b/src/Models/Runners.coffee new file mode 100644 index 0000000..4bee932 --- /dev/null +++ b/src/Models/Runners.coffee @@ -0,0 +1,39 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class Runners extends BaseModel + all: (projectId, params={}, fn = null) => + if 'function' is typeof params + fn = params + params={} + + @debug "Projects::Runners::all()" + + if projectId? + @get "projects/#{Utils.parseProjectId projectId}/runners", params, (data) => fn data if fn + else + @get "runners", params, (data) => fn data if fn + + show: (runnerId, fn = null) => + @debug "Projects::Runners::show()" + @get "runners/#{parseInt runnerId}", (data) => fn data if fn + + update: (runnerId, attributes, fn = null) => + @debug "Projects::Runners::update" + @put "runners/#{parseInt runnerId}", attributes, (data) => fn data if fn + + remove: (runnerId, projectId, enable, fn = null) => + @debug "Projects::Runners::runners()" + @delete "runners/#{parseInt runnerId}", (data) => fn data if fn + + enable: (projectId, runnerId, fn = null) => + @debug "Projects::Runners::enable()" + attributes: + runner_id: parseInt runnerId + @post "projects/#{Utils.parseProjectId projectId}/runners", attributes, (data) -> fn data if fn + + disable: (projectId, runnerId, fn = null) => + @debug "Projects::Runners::disable()" + @delete "projects/#{Utils.parseProjectId projectId}/runners/#{parseInt runnerId}", (data) -> fn data if fn + +module.exports = (client) -> new Runners client diff --git a/src/Models/UserKeys.coffee b/src/Models/UserKeys.coffee new file mode 100644 index 0000000..394de00 --- /dev/null +++ b/src/Models/UserKeys.coffee @@ -0,0 +1,14 @@ +BaseModel = require '../BaseModel' + +class UserKeys extends BaseModel + all: (userId, fn = null) => + @get "users/#{parseInt userId}/keys", (data) => fn data if fn + + addKey: (userId, title, key, fn = null) => + params = + title: title + key: key + + @post "users/#{userId}/keys", params, (data) -> fn data if fn + +module.exports = (client) -> new UserKeys client diff --git a/src/Models/Users.coffee b/src/Models/Users.coffee index 81cef07..5f84cbe 100644 --- a/src/Models/Users.coffee +++ b/src/Models/Users.coffee @@ -1,9 +1,32 @@ BaseModel = require '../BaseModel' class Users extends BaseModel - all: (fn = null) => + init: => + @keys = @load 'UserKeys' + + all: (params = {}, fn = null) => + if 'function' is typeof params + fn = params + params = {} @debug "Users::all()" - @get "users", (data) => fn data if fn + + 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 Users::all()" + data = data.concat(retData) + params.page++ + return @get "users", params, cb + else + data = data.concat(retData) + return fn data if fn + + @get "users", params, cb current: (fn = null) => @debug "Users::current()" @@ -24,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/ApiBaseHTTP.test.coffee b/tests/ApiBaseHTTP.test.coffee new file mode 100644 index 0000000..8c9ac76 --- /dev/null +++ b/tests/ApiBaseHTTP.test.coffee @@ -0,0 +1,33 @@ +chai = require 'chai' +expect = chai.expect +sinon = require 'sinon' +proxyquire = require 'proxyquire' +sinonChai = require 'sinon-chai' + +chai.use sinonChai + +describe "ApiBaseHTTP", -> + ApiBaseHTTP = null + apibasehttp = null + + before -> + ApiBaseHTTP = require('../lib/ApiBaseHTTP').ApiBaseHTTP + + beforeEach -> + + describe "handleOptions()", -> + it "should strip /api/v3 from `url` parameter if provided", -> + apibasehttp = new ApiBaseHTTP + base_url: "api/v3" + url: "http://gitlab.mydomain.com/api/v3" + token: "test" + + expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com") + + it "should not strip /api/v3 from `url` parameter if not provided", -> + apibasehttp = new ApiBaseHTTP + base_url: "api/v3" + url: "http://gitlab.mydomain.com" + token: "test" + + expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com") diff --git a/tests/ApiBaseHTTP.test.js b/tests/ApiBaseHTTP.test.js new file mode 100644 index 0000000..324bd2c --- /dev/null +++ b/tests/ApiBaseHTTP.test.js @@ -0,0 +1,44 @@ +(function() { + var chai, expect, proxyquire, sinon, sinonChai; + + chai = require('chai'); + + expect = chai.expect; + + sinon = require('sinon'); + + proxyquire = require('proxyquire'); + + sinonChai = require('sinon-chai'); + + chai.use(sinonChai); + + describe("ApiBaseHTTP", function() { + var ApiBaseHTTP, apibasehttp; + ApiBaseHTTP = null; + apibasehttp = null; + before(function() { + return ApiBaseHTTP = require('../lib/ApiBaseHTTP').ApiBaseHTTP; + }); + beforeEach(function() {}); + return describe("handleOptions()", function() { + it("should strip /api/v3 from `url` parameter if provided", function() { + apibasehttp = new ApiBaseHTTP({ + base_url: "api/v3", + url: "http://gitlab.mydomain.com/api/v3", + token: "test" + }); + return expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com"); + }); + return it("should not strip /api/v3 from `url` parameter if not provided", function() { + apibasehttp = new ApiBaseHTTP({ + base_url: "api/v3", + url: "http://gitlab.mydomain.com", + token: "test" + }); + return expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com"); + }); + }); + }); + +}).call(this); diff --git a/tests/ProjectMembers.test.coffee b/tests/ProjectMembers.test.coffee new file mode 100644 index 0000000..2b057e1 --- /dev/null +++ b/tests/ProjectMembers.test.coffee @@ -0,0 +1,80 @@ +chai = require 'chai' +expect = chai.expect +sinon = require 'sinon' +sinonChai = require 'sinon-chai' + +chai.use sinonChai + +describe "ProjectMembers", -> + gitlab = null + projects = null + members = null + + before -> + gitlab = (require '../') + url: 'test' + token: 'test' + + projects = gitlab.projects + members = projects.members + + beforeEach -> + + describe "list()", -> + it "should use GET verb", -> + getStub = sinon.stub members, "get" + + members.list 1 + + getStub.restore() + expect(getStub).to.have.been.called + + it "should pass Numeric projectIDs to Utils.parseProjectId", -> + getStub = sinon.stub members, "get" + + members.list 1 + + getStub.restore() + expect(getStub).to.have.been.calledWith "projects/1/members" + + it "should pass Namespaced projectIDs to Utils.parseProjectId", -> + getStub = sinon.stub members, "get" + + members.list "abc/def" + + getStub.restore() + expect(getStub).to.have.been.calledWith "projects/abc%2Fdef/members" + + describe "show()", -> + it "should use GET verb", -> + getStub = sinon.stub members, "get" + + members.show 1, 2 + + getStub.restore() + expect(getStub).to.have.been.called + + it "should pass Numeric projectIDs to Utils.parseProjectId", -> + getStub = sinon.stub members, "get" + + members.show 1, 2 + + getStub.restore() + expect(getStub).to.have.been.calledWith "projects/1/members/2" + + it "should pass Namespaced projectIDs to Utils.parseProjectId", -> + getStub = sinon.stub members, "get" + + members.show "abc/def", 2 + + getStub.restore() + expect(getStub).to.have.been.calledWith "projects/abc%2Fdef/members/2" + + describe "add()", -> + it "should use POST verb", -> + postStub = sinon.stub members, "post" + + members.add 1, 1, 30 + + postStub.restore() + expect(postStub).to.have.been.called diff --git a/tests/ProjectMembers.test.js b/tests/ProjectMembers.test.js new file mode 100644 index 0000000..5adabba --- /dev/null +++ b/tests/ProjectMembers.test.js @@ -0,0 +1,85 @@ +(function() { + var chai, expect, sinon, sinonChai; + + chai = require('chai'); + + expect = chai.expect; + + sinon = require('sinon'); + + sinonChai = require('sinon-chai'); + + chai.use(sinonChai); + + describe("ProjectMembers", function() { + var gitlab, members, projects; + gitlab = null; + projects = null; + members = null; + before(function() { + gitlab = (require('../'))({ + url: 'test', + token: 'test' + }); + projects = gitlab.projects; + return members = projects.members; + }); + beforeEach(function() {}); + describe("list()", function() { + it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(members, "get"); + members.list(1); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + it("should pass Numeric projectIDs to Utils.parseProjectId", function() { + var getStub; + getStub = sinon.stub(members, "get"); + members.list(1); + getStub.restore(); + return expect(getStub).to.have.been.calledWith("projects/1/members"); + }); + return it("should pass Namespaced projectIDs to Utils.parseProjectId", function() { + var getStub; + getStub = sinon.stub(members, "get"); + members.list("abc/def"); + getStub.restore(); + return expect(getStub).to.have.been.calledWith("projects/abc%2Fdef/members"); + }); + }); + describe("show()", function() { + it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(members, "get"); + members.show(1, 2); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + it("should pass Numeric projectIDs to Utils.parseProjectId", function() { + var getStub; + getStub = sinon.stub(members, "get"); + members.show(1, 2); + getStub.restore(); + return expect(getStub).to.have.been.calledWith("projects/1/members/2"); + }); + return it("should pass Namespaced projectIDs to Utils.parseProjectId", function() { + var getStub; + getStub = sinon.stub(members, "get"); + members.show("abc/def", 2); + getStub.restore(); + return expect(getStub).to.have.been.calledWith("projects/abc%2Fdef/members/2"); + }); + }); + return describe("add()", function() { + return it("should use POST verb", function() { + var postStub; + postStub = sinon.stub(members, "post"); + members.add(1, 1, 30); + postStub.restore(); + return expect(postStub).to.have.been.called; + }); + }); + }); + +}).call(this); diff --git a/tests/ProjectRepository.test.coffee b/tests/ProjectRepository.test.coffee new file mode 100644 index 0000000..a1ab87d --- /dev/null +++ b/tests/ProjectRepository.test.coffee @@ -0,0 +1,84 @@ +chai = require 'chai' +expect = chai.expect +sinon = require 'sinon' +sinonChai = require 'sinon-chai' + +chai.use sinonChai + +describe "ProjectRepository", -> + gitlab = null + projects = null + repository = null + + before -> + gitlab = (require '../') + url: 'test' + token: 'test' + + projects = gitlab.projects + repository = projects.repository + + beforeEach -> + + describe "listBranches()", -> + it "should use GET verb", -> + getStub = sinon.stub repository, "get" + + repository.listBranches 1 + + getStub.restore() + expect(getStub).to.have.been.called + + describe "listCommits()", -> + it "should use GET verb", -> + getStub = sinon.stub repository, "get" + + repository.listCommits 1 + + getStub.restore() + expect(getStub).to.have.been.called + + describe "addTag()", -> + it "should use POST verb", -> + postStub = sinon.stub repository, "post" + + opts = + id: 1, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + repository.addTag opts + + postStub.restore() + expect(postStub).to.have.been.called + + describe "listTags()", -> + it "should use GET verb", -> + getStub = sinon.stub repository, "get" + + repository.listTags 1 + + getStub.restore() + expect(getStub).to.have.been.called + + describe "listTree()", -> + it "should use GET verb", -> + getStub = sinon.stub repository, "get" + + repository.listTree 1 + + getStub.restore() + expect(getStub).to.have.been.called + + describe "showFile()", -> + it "should use GET verb", -> + getStub = sinon.stub repository, "get" + + repository.showFile 1, { + file_path: "test", + ref: "test" + } + + getStub.restore() + expect(getStub).to.have.been.called diff --git a/tests/ProjectRepository.test.js b/tests/ProjectRepository.test.js new file mode 100644 index 0000000..692deb7 --- /dev/null +++ b/tests/ProjectRepository.test.js @@ -0,0 +1,94 @@ +(function() { + var chai, expect, sinon, sinonChai; + + chai = require('chai'); + + expect = chai.expect; + + sinon = require('sinon'); + + sinonChai = require('sinon-chai'); + + chai.use(sinonChai); + + describe("ProjectRepository", function() { + var gitlab, projects, repository; + gitlab = null; + projects = null; + repository = null; + before(function() { + gitlab = (require('../'))({ + url: 'test', + token: 'test' + }); + projects = gitlab.projects; + return repository = projects.repository; + }); + beforeEach(function() {}); + describe("listBranches()", function() { + return it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(repository, "get"); + repository.listBranches(1); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + }); + describe("listCommits()", function() { + return it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(repository, "get"); + repository.listCommits(1); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + }); + describe("addTag()", function() { + return it("should use POST verb", function() { + var opts, postStub; + postStub = sinon.stub(repository, "post"); + opts = { + id: 1, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + }; + repository.addTag(opts); + postStub.restore(); + return expect(postStub).to.have.been.called; + }); + }); + describe("listTags()", function() { + return it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(repository, "get"); + repository.listTags(1); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + }); + describe("listTree()", function() { + return it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(repository, "get"); + repository.listTree(1); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + }); + return describe("showFile()", function() { + return it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(repository, "get"); + repository.showFile(1, { + file_path: "test", + ref: "test" + }); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + }); + }); + +}).call(this); diff --git a/tests/Projects.test.coffee b/tests/Projects.test.coffee new file mode 100644 index 0000000..8e716dc --- /dev/null +++ b/tests/Projects.test.coffee @@ -0,0 +1,89 @@ +chai = require 'chai' +expect = chai.expect +sinon = require 'sinon' +sinonChai = require 'sinon-chai' + +chai.use sinonChai + +describe "Projects", -> + gitlab = null + projects = null + + before -> + gitlab = (require '../') + url: 'test' + token: 'test' + + projects = gitlab.projects + + beforeEach -> + + describe "show()", -> + it "should use GET verb", -> + getStub = sinon.stub projects, "get" + + projects.show 1 + + getStub.restore() + expect(getStub).to.have.been.called + + it "should pass Numeric projectIDs to Utils.parseProjectId", -> + getStub = sinon.stub projects, "get" + + projects.show 1 + + getStub.restore() + expect(getStub).to.have.been.calledWith "projects/1" + + it "should pass Namespaced projectIDs to Utils.parseProjectId", -> + getStub = sinon.stub projects, "get" + + projects.show "abc/def" + + getStub.restore() + expect(getStub).to.have.been.calledWith "projects/abc%2Fdef" + + describe "all()", -> + arrayOf101 = [] + arrayOf100 = [] + arrayOf99 = [] + arrayOf1 = [] + + before -> + for i in [0..102] + if i < 1 + arrayOf1.push {} + if i < 99 + arrayOf99.push {} + if i < 100 + arrayOf100.push {} + if i < 101 + arrayOf101.push {} + + it "should use GET verb", -> + getStub = sinon.stub projects, "get" + + projects.all() + + getStub.restore() + expect(getStub).to.have.been.called + + it "should recurse if more than 100 records are returned", -> + getStub = sinon.stub projects, "get", (a,b,c)-> + if getStub.callCount < 3 + c null, arrayOf100 + else + c null, arrayOf99 + + projects.all() + + expect(getStub).to.have.been.calledThrice + + describe "create()", -> + it "should use POST verb", -> + postStub = sinon.stub projects, "post" + + projects.create {} + + postStub.restore() + expect(postStub).to.have.been.called diff --git a/tests/Projects.test.js b/tests/Projects.test.js new file mode 100644 index 0000000..8116a5b --- /dev/null +++ b/tests/Projects.test.js @@ -0,0 +1,107 @@ +(function() { + var chai, expect, sinon, sinonChai; + + chai = require('chai'); + + expect = chai.expect; + + sinon = require('sinon'); + + sinonChai = require('sinon-chai'); + + chai.use(sinonChai); + + describe("Projects", function() { + var gitlab, projects; + gitlab = null; + projects = null; + before(function() { + gitlab = (require('../'))({ + url: 'test', + token: 'test' + }); + return projects = gitlab.projects; + }); + beforeEach(function() {}); + describe("show()", function() { + it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(projects, "get"); + projects.show(1); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + it("should pass Numeric projectIDs to Utils.parseProjectId", function() { + var getStub; + getStub = sinon.stub(projects, "get"); + projects.show(1); + getStub.restore(); + return expect(getStub).to.have.been.calledWith("projects/1"); + }); + return it("should pass Namespaced projectIDs to Utils.parseProjectId", function() { + var getStub; + getStub = sinon.stub(projects, "get"); + projects.show("abc/def"); + getStub.restore(); + return expect(getStub).to.have.been.calledWith("projects/abc%2Fdef"); + }); + }); + describe("all()", function() { + var arrayOf1, arrayOf100, arrayOf101, arrayOf99; + arrayOf101 = []; + arrayOf100 = []; + arrayOf99 = []; + arrayOf1 = []; + before(function() { + var i, j, results; + results = []; + for (i = j = 0; j <= 102; i = ++j) { + if (i < 1) { + arrayOf1.push({}); + } + if (i < 99) { + arrayOf99.push({}); + } + if (i < 100) { + arrayOf100.push({}); + } + if (i < 101) { + results.push(arrayOf101.push({})); + } else { + results.push(void 0); + } + } + return results; + }); + it("should use GET verb", function() { + var getStub; + getStub = sinon.stub(projects, "get"); + projects.all(); + getStub.restore(); + return expect(getStub).to.have.been.called; + }); + return it("should recurse if more than 100 records are returned", function() { + var getStub; + getStub = sinon.stub(projects, "get", function(a, b, c) { + if (getStub.callCount < 3) { + return c(null, arrayOf100); + } else { + return c(null, arrayOf99); + } + }); + projects.all(); + return expect(getStub).to.have.been.calledThrice; + }); + }); + return describe("create()", function() { + return it("should use POST verb", function() { + var postStub; + postStub = sinon.stub(projects, "post"); + projects.create({}); + postStub.restore(); + return expect(postStub).to.have.been.called; + }); + }); + }); + +}).call(this); diff --git a/tests/Utils.test.coffee b/tests/Utils.test.coffee new file mode 100644 index 0000000..7e18b84 --- /dev/null +++ b/tests/Utils.test.coffee @@ -0,0 +1,21 @@ +chai = require 'chai' +expect = chai.expect +proxyquire = require 'proxyquire' +Utils = require '../lib/Utils.js' + +describe "Utils", -> + describe "parseProjectId", -> + it "should return a Number if passed a Number", -> + expect(Utils.parseProjectId 0).to.be.a 'number' + + it "should URI encode strings containing '/'", -> + expect(Utils.parseProjectId "/abc").to.equal '%2Fabc' + expect(Utils.parseProjectId "a/bc").to.equal 'a%2Fbc' + expect(Utils.parseProjectId "ab/c").to.equal 'ab%2Fc' + expect(Utils.parseProjectId "abc/").to.equal 'abc%2F' + + it "should return NaN for unparseable strings without '/'", -> + expect(isNaN Utils.parseProjectId "abc").to.be.true + + it "should return a Number for parseable strings without '/'", -> + expect(Utils.parseProjectId "1").to.equal 1 diff --git a/tests/Utils.test.js b/tests/Utils.test.js new file mode 100644 index 0000000..7aea4d4 --- /dev/null +++ b/tests/Utils.test.js @@ -0,0 +1,32 @@ +(function() { + var Utils, chai, expect, proxyquire; + + chai = require('chai'); + + expect = chai.expect; + + proxyquire = require('proxyquire'); + + Utils = require('../lib/Utils.js'); + + describe("Utils", function() { + return describe("parseProjectId", function() { + it("should return a Number if passed a Number", function() { + return expect(Utils.parseProjectId(0)).to.be.a('number'); + }); + it("should URI encode strings containing '/'", function() { + expect(Utils.parseProjectId("/abc")).to.equal('%2Fabc'); + expect(Utils.parseProjectId("a/bc")).to.equal('a%2Fbc'); + expect(Utils.parseProjectId("ab/c")).to.equal('ab%2Fc'); + return expect(Utils.parseProjectId("abc/")).to.equal('abc%2F'); + }); + it("should return NaN for unparseable strings without '/'", function() { + return expect(isNaN(Utils.parseProjectId("abc"))).to.be["true"]; + }); + return it("should return a Number for parseable strings without '/'", function() { + return expect(Utils.parseProjectId("1")).to.equal(1); + }); + }); + }); + +}).call(this); diff --git a/tests/mock.js b/tests/mock.js index 37e9aa8..f32e234 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -1,13 +1,12 @@ -// Generated by CoffeeScript 1.7.1 (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 = []; @@ -64,8 +63,8 @@ })(this)); }; - Mock.prototype.update_path = function(path) { - this.path = path; + Mock.prototype.update_path = function(path1) { + this.path = path1; return this; }; @@ -98,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.coffee b/tests/test.coffee index 7165515..473b3e7 100644 --- a/tests/test.coffee +++ b/tests/test.coffee @@ -89,6 +89,17 @@ describe 'Project', -> gitlab.projects.repository.listCommits projectId, (result) -> done() + describe '#addTag()', -> + it 'should add a tag to a given project', (done) -> + opts = + id: projectId, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + gitlab.projects.repository.addTag opts, (result) -> + done() + describe '#listTags()', -> it 'should retrieve tags of a given project', (done) -> gitlab.projects.repository.listTags projectId, (result) -> @@ -99,6 +110,17 @@ describe 'Project', -> gitlab.projects.repository.listTree projectId, (result) -> done() + describe '#showFile()', -> + it 'should retrieve specified file with arity=3', (done) -> + opts = file_path: 'README.md', ref: 'master' + gitlab.projects.repository.showFile projectId, opts, (result) -> + done() + + it 'should retrieve specified file with arity=2', (done) -> + opts = projectId: projectId, file_path: 'README.md', ref: 'master' + gitlab.projects.repository.showFile opts, (result) -> + done() + describe 'Issue', -> describe '#all()', -> diff --git a/tests/test.js b/tests/test.js index 3b98b84..699c1c4 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var Gitlab, assert, credentials, gitlab, mock, projectId, userId, validate_project; @@ -70,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(); @@ -123,6 +122,21 @@ }); }); }); + describe('#addTag()', function() { + return it('should add a tag to a given project', function(done) { + var opts; + opts = { + id: projectId, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + }; + return gitlab.projects.repository.addTag(opts, function(result) { + return done(); + }); + }); + }); describe('#listTags()', function() { return it('should retrieve tags of a given project', function(done) { return gitlab.projects.repository.listTags(projectId, function(result) { @@ -130,13 +144,36 @@ }); }); }); - return describe('#listTree()', function() { + describe('#listTree()', function() { return it('should retrieve tree of a given project', function(done) { return gitlab.projects.repository.listTree(projectId, function(result) { return done(); }); }); }); + return describe('#showFile()', function() { + it('should retrieve specified file with arity=3', function(done) { + var opts; + opts = { + file_path: 'README.md', + ref: 'master' + }; + return gitlab.projects.repository.showFile(projectId, opts, function(result) { + return done(); + }); + }); + return it('should retrieve specified file with arity=2', function(done) { + var opts; + opts = { + projectId: projectId, + file_path: 'README.md', + ref: 'master' + }; + return gitlab.projects.repository.showFile(opts, function(result) { + return done(); + }); + }); + }); }); }); diff --git a/tests/validators.js b/tests/validators.js index 3b46e7a..9def427 100644 --- a/tests/validators.js +++ b/tests/validators.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.7.1 (function() { var assert;