├── .editorconfig ├── .gitignore ├── .hound.yml ├── .npmignore ├── .travis.yml ├── Cakefile ├── LICENSE.md ├── Makefile ├── README.md ├── examples ├── bad-token.coffee ├── bad-token.js ├── create-service.coffee ├── create-service.js ├── delete-service.coffee ├── delete-service.js ├── example.credentials.coffee ├── example.credentials.js ├── list-projects.coffee ├── list-projects.js ├── list-users.coffee ├── list-users.js ├── reset-hooks.coffee ├── reset-hooks.js ├── show-file.coffee ├── show-file.js ├── show-project.coffee ├── show-project.js ├── show-service.coffee ├── show-service.js ├── show-user.coffee └── show-user.js ├── lib ├── ApiBase.js ├── ApiBaseHTTP.js ├── ApiV3.js ├── BaseModel.js ├── Models │ ├── Groups.js │ ├── IssueNotes.js │ ├── Issues.js │ ├── Labels.js │ ├── Notes.js │ ├── Pipelines.js │ ├── ProjectBuilds.js │ ├── ProjectDeployKeys.js │ ├── ProjectHooks.js │ ├── ProjectIssues.js │ ├── ProjectLabels.js │ ├── ProjectMembers.js │ ├── ProjectMergeRequests.js │ ├── ProjectMilestones.js │ ├── ProjectRepository.js │ ├── ProjectServices.js │ ├── Projects.js │ ├── Runners.js │ ├── UserKeys.js │ └── Users.js ├── Utils.js └── index.js ├── package.json ├── src ├── ApiBase.coffee ├── ApiBaseHTTP.coffee ├── ApiV3.coffee ├── BaseModel.coffee ├── Models │ ├── Groups.coffee │ ├── IssueNotes.coffee │ ├── Issues.coffee │ ├── Labels.coffee │ ├── Notes.coffee │ ├── Pipelines.coffee │ ├── ProjectBuilds.coffee │ ├── ProjectDeployKeys.coffee │ ├── ProjectHooks.coffee │ ├── ProjectIssues.coffee │ ├── ProjectLabels.coffee │ ├── ProjectMembers.coffee │ ├── ProjectMergeRequests.coffee │ ├── ProjectMilestones.coffee │ ├── ProjectRepository.coffee │ ├── ProjectServices.coffee │ ├── Projects.coffee │ ├── Runners.coffee │ ├── UserKeys.coffee │ └── Users.coffee ├── Utils.coffee └── index.coffee └── tests ├── ApiBaseHTTP.test.coffee ├── ApiBaseHTTP.test.js ├── ProjectMembers.test.coffee ├── ProjectMembers.test.js ├── ProjectRepository.test.coffee ├── ProjectRepository.test.js ├── Projects.test.coffee ├── Projects.test.js ├── Utils.test.coffee ├── Utils.test.js ├── mock.coffee ├── mock.js ├── test.coffee ├── test.js ├── validators.coffee └── validators.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [.*ignore] 7 | charset = utf-8 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [**.{coffee,js,json}] 13 | charset = utf-8 14 | end_of_line = lf 15 | indent_size = 2 16 | indent_style = space 17 | insert_final_newline = false 18 | trim_trailing_whitespace = true 19 | 20 | [*.md] 21 | charset = utf-8 22 | end_of_line = lf 23 | insert_final_newline = true 24 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | NOTES 3 | *~ 4 | *# 5 | .#* 6 | node_modules 7 | examples/credentials* 8 | 9 | lib-cov 10 | *.seed 11 | *.log 12 | *.csv 13 | *.dat 14 | *.out 15 | *.pid 16 | *.gz 17 | 18 | pids 19 | logs 20 | results 21 | 22 | npm-debug.log 23 | 24 | .idea 25 | *.iml 26 | 27 | /docs -------------------------------------------------------------------------------- /.hound.yml: -------------------------------------------------------------------------------- 1 | javascript: 2 | enabled: false 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | ./src/ 2 | .DS_Store 3 | NOTES 4 | *~ 5 | *# 6 | .#* 7 | node_modules 8 | examples/credentials* 9 | 10 | lib-cov 11 | *.seed 12 | *.log 13 | *.csv 14 | *.dat 15 | *.out 16 | *.pid 17 | *.gz 18 | 19 | pids 20 | logs 21 | results 22 | 23 | npm-debug.log 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "lts/boron" 4 | - "lts/carbon" 5 | - "stable" 6 | sudo: false 7 | notifications: 8 | webhooks: 9 | urls: 10 | - https://webhooks.gitter.im/e/6f1f69c4ed2fc4bdfeff 11 | on_success: change # options: [always|never|change] default: always 12 | on_failure: always # options: [always|never|change] default: always 13 | on_start: false # default: false 14 | -------------------------------------------------------------------------------- /Cakefile: -------------------------------------------------------------------------------- 1 | {spawn, exec} = require 'child_process' 2 | 3 | coffee = './node_modules/.bin/coffee' 4 | 5 | call = (command, args = [], fn = null) -> 6 | exec "#{command} #{args.join(' ')}", (err, stdout, stderr) -> 7 | if err? 8 | console.error "Error :" 9 | return console.dir err 10 | fn err if fn 11 | 12 | system = (command, args) -> 13 | spawn command, args, stdio: "inherit" 14 | 15 | build = (fn = null) -> 16 | call coffee, ['-c', '--no-header', '-o', 'lib', 'src'] 17 | call coffee, ['-c', '--no-header', '-o', 'examples', 'examples'] 18 | call coffee, ['-c', '--no-header', '-o', 'tests', 'tests'] 19 | 20 | watch = (fn = null) -> 21 | system coffee, ['-w', '--no-header', '-c', '-o', 'lib', 'src'] 22 | system coffee, ['-w', '--no-header', '-c', '-o', 'examples', 'examples'] 23 | system coffee, ['-w', '--no-header', '-c', '-o', 'tests', 'tests'] 24 | 25 | task 'watch', 'continually build the JavaScript code', -> 26 | watch -> 27 | console.log "Done !" 28 | 29 | task 'build', 'build the JavaScript code', -> 30 | build -> 31 | console.log "Done !" 32 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | =============== 3 | 4 | Copyright (c) 5 | **2012-2015 Manfred Touron** ([@moul](https://twitter.com/moul)), 6 | **2013-2015 Dave Irvine** ([@dave_irvine](https://twitter.com/dave_irvine)) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PACKAGE_VERSION = $(shell node -e 'console.log(require("./package.json").version);') 2 | 3 | develop: 4 | npm install 5 | npm install -g coffee-script 6 | 7 | build: 8 | cake build 9 | 10 | watch: 11 | cake watch 12 | 13 | doc: 14 | npm install docco 15 | ./node_modules/docco/bin/docco $(shell find src -name "*.coffee") 16 | 17 | tag: 18 | git commit -am "v$(PACKAGE_VERSION)" 19 | git tag v$(PACKAGE_VERSION) 20 | git push 21 | git push --tags 22 | 23 | test: build 24 | npm test 25 | 26 | release: test 27 | npm publish 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## DEPRECATED, see https://github.com/node-gitlab/node-gitlab 2 | -------------------------------------------------------------------------------- /examples/bad-token.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = 10 | url: 'http://demo.gitlab.com' 11 | token: 'bad-token' 12 | 13 | gitlab = new Gitlab 14 | url: credentials.url 15 | token: credentials.token 16 | 17 | gitlab.projects.all (err, resp, result) -> 18 | console.log "having: ", err: err, resp: resp, result: result 19 | console.log "should get: { err: '401 Unauthorized', resp: undefined, result: undefined }" 20 | -------------------------------------------------------------------------------- /examples/bad-token.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = { 9 | url: 'http://demo.gitlab.com', 10 | token: 'bad-token' 11 | }; 12 | 13 | gitlab = new Gitlab({ 14 | url: credentials.url, 15 | token: credentials.token 16 | }); 17 | 18 | gitlab.projects.all(function(err, resp, result) { 19 | console.log("having: ", { 20 | err: err, 21 | resp: resp, 22 | result: result 23 | }); 24 | return console.log("should get: { err: '401 Unauthorized', resp: undefined, result: undefined }"); 25 | }); 26 | 27 | }).call(this); 28 | -------------------------------------------------------------------------------- /examples/create-service.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | projectId = parseInt process.argv[2] 16 | serviceName = process.argv[3] 17 | serviceParams = 18 | webhook: process.argv[4] 19 | username: process.argv[5] 20 | channel: process.argv[6] 21 | 22 | 23 | 24 | gitlab.projects.services.update projectId, serviceName, serviceParams, (service) -> 25 | console.log 26 | console.log "=== Service ===" 27 | console.log service 28 | -------------------------------------------------------------------------------- /examples/create-service.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab, projectId, serviceName, serviceParams; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | projectId = parseInt(process.argv[2]); 16 | 17 | serviceName = process.argv[3]; 18 | 19 | serviceParams = { 20 | webhook: process.argv[4], 21 | username: process.argv[5], 22 | channel: process.argv[6] 23 | }; 24 | 25 | gitlab.projects.services.update(projectId, serviceName, serviceParams, function(service) { 26 | console.log; 27 | console.log("=== Service ==="); 28 | return console.log(service); 29 | }); 30 | 31 | }).call(this); 32 | -------------------------------------------------------------------------------- /examples/delete-service.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | projectId = parseInt process.argv[2] 16 | serviceName = process.argv[3] 17 | 18 | 19 | 20 | gitlab.projects.services.remove projectId, serviceName, (service) -> 21 | console.log 22 | console.log "=== Service ===" 23 | console.log service 24 | -------------------------------------------------------------------------------- /examples/delete-service.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab, projectId, serviceName; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | projectId = parseInt(process.argv[2]); 16 | 17 | serviceName = process.argv[3]; 18 | 19 | gitlab.projects.services.remove(projectId, serviceName, function(service) { 20 | console.log; 21 | console.log("=== Service ==="); 22 | return console.log(service); 23 | }); 24 | 25 | }).call(this); 26 | -------------------------------------------------------------------------------- /examples/example.credentials.coffee: -------------------------------------------------------------------------------- 1 | module.exports = 2 | url: 'http://demo.gitlab.com' 3 | token: 'Wvjy2Krpb7y8xi93owUz' 4 | -------------------------------------------------------------------------------- /examples/example.credentials.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | module.exports = { 3 | url: 'http://demo.gitlab.com', 4 | token: 'Wvjy2Krpb7y8xi93owUz' 5 | }; 6 | 7 | }).call(this); 8 | -------------------------------------------------------------------------------- /examples/list-projects.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | gitlab.projects.all (projects) -> 16 | #console.log projects 17 | for project in projects 18 | 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}" 19 | #console.log project 20 | -------------------------------------------------------------------------------- /examples/list-projects.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | gitlab.projects.all(function(projects) { 16 | var i, len, project, results; 17 | results = []; 18 | for (i = 0, len = projects.length; i < len; i++) { 19 | project = projects[i]; 20 | 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)); 21 | } 22 | return results; 23 | }); 24 | 25 | }).call(this); 26 | -------------------------------------------------------------------------------- /examples/list-users.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | token: credentials.token 13 | url: credentials.url 14 | 15 | gitlab.users.all (users) -> 16 | #console.log users 17 | for user in users 18 | console.log "##{user.id}: #{user.email}, #{user.name}, #{user.created_at}" 19 | #console.log user 20 | -------------------------------------------------------------------------------- /examples/list-users.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | token: credentials.token, 12 | url: credentials.url 13 | }); 14 | 15 | gitlab.users.all(function(users) { 16 | var i, len, results, user; 17 | results = []; 18 | for (i = 0, len = users.length; i < len; i++) { 19 | user = users[i]; 20 | results.push(console.log("#" + user.id + ": " + user.email + ", " + user.name + ", " + user.created_at)); 21 | } 22 | return results; 23 | }); 24 | 25 | }).call(this); 26 | -------------------------------------------------------------------------------- /examples/reset-hooks.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | gitlab.projects.all (projects) -> 16 | for _project in projects 17 | do -> 18 | project = _project 19 | gitlab.projects.hooks.list project.id, (hooks) -> 20 | url = "#{credentials.service_hook_base}#{project.path_with_namespace}" 21 | if hooks.length > 1 22 | console.log "#{url} too much hooks" 23 | else if hooks.length is 1 24 | for hook in hooks 25 | if hook.url != url 26 | gitlab.projects.hooks.remove project.id, hook.id, (ret) -> 27 | console.log ret 28 | console.log "#{url} is already OK" 29 | else 30 | gitlab.projects.hooks.add project.id, url, -> 31 | console.log "#{url} has been added" 32 | -------------------------------------------------------------------------------- /examples/reset-hooks.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | gitlab.projects.all(function(projects) { 16 | var _project, i, len, results; 17 | results = []; 18 | for (i = 0, len = projects.length; i < len; i++) { 19 | _project = projects[i]; 20 | results.push((function() { 21 | var project; 22 | project = _project; 23 | return gitlab.projects.hooks.list(project.id, function(hooks) { 24 | var hook, j, len1, url; 25 | url = "" + credentials.service_hook_base + project.path_with_namespace; 26 | if (hooks.length > 1) { 27 | return console.log(url + " too much hooks"); 28 | } else if (hooks.length === 1) { 29 | for (j = 0, len1 = hooks.length; j < len1; j++) { 30 | hook = hooks[j]; 31 | if (hook.url !== url) { 32 | gitlab.projects.hooks.remove(project.id, hook.id, function(ret) { 33 | return console.log(ret); 34 | }); 35 | } 36 | } 37 | return console.log(url + " is already OK"); 38 | } else { 39 | return gitlab.projects.hooks.add(project.id, url, function() { 40 | return console.log(url + " has been added"); 41 | }); 42 | } 43 | }); 44 | })()); 45 | } 46 | return results; 47 | }); 48 | 49 | }).call(this); 50 | -------------------------------------------------------------------------------- /examples/show-file.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | projectId = parseInt process.argv[2] 16 | 17 | gitlab.projects.repository.showFile {projectId: projectId, ref: 'master', file_path: 'README.md'}, (file) -> 18 | console.log 19 | console.log "=== File ===" 20 | console.log file 21 | if file 22 | console.log 23 | console.log "=== Content ===" 24 | console.log (new Buffer(file.content, 'base64')).toString() 25 | -------------------------------------------------------------------------------- /examples/show-file.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab, projectId; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | projectId = parseInt(process.argv[2]); 16 | 17 | gitlab.projects.repository.showFile({ 18 | projectId: projectId, 19 | ref: 'master', 20 | file_path: 'README.md' 21 | }, function(file) { 22 | console.log; 23 | console.log("=== File ==="); 24 | console.log(file); 25 | if (file) { 26 | console.log; 27 | console.log("=== Content ==="); 28 | return console.log((new Buffer(file.content, 'base64')).toString()); 29 | } 30 | }); 31 | 32 | }).call(this); 33 | -------------------------------------------------------------------------------- /examples/show-project.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | projectId = parseInt process.argv[2] 16 | 17 | gitlab.projects.show projectId, (project) -> 18 | console.log 19 | console.log "=== Project ===" 20 | console.log project 21 | 22 | gitlab.projects.members.list projectId, (members) -> 23 | console.log "" 24 | console.log "=== Members ===" 25 | console.log members 26 | 27 | gitlab.projects.milestones.list projectId, {per_page: 100}, (milestones) -> 28 | console.log "" 29 | console.log "=== Milestones ===" 30 | console.log milestones 31 | -------------------------------------------------------------------------------- /examples/show-project.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab, projectId; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | projectId = parseInt(process.argv[2]); 16 | 17 | gitlab.projects.show(projectId, function(project) { 18 | console.log; 19 | console.log("=== Project ==="); 20 | return console.log(project); 21 | }); 22 | 23 | gitlab.projects.members.list(projectId, function(members) { 24 | console.log(""); 25 | console.log("=== Members ==="); 26 | return console.log(members); 27 | }); 28 | 29 | gitlab.projects.milestones.list(projectId, { 30 | per_page: 100 31 | }, function(milestones) { 32 | console.log(""); 33 | console.log("=== Milestones ==="); 34 | return console.log(milestones); 35 | }); 36 | 37 | }).call(this); 38 | -------------------------------------------------------------------------------- /examples/show-service.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | projectId = parseInt process.argv[2] 16 | serviceName = process.argv[3] 17 | 18 | gitlab.projects.services.show projectId, serviceName, (service) -> 19 | console.log 20 | console.log "=== Service ===" 21 | console.log service 22 | -------------------------------------------------------------------------------- /examples/show-service.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab, projectId, serviceName; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | projectId = parseInt(process.argv[2]); 16 | 17 | serviceName = process.argv[3]; 18 | 19 | gitlab.projects.services.show(projectId, serviceName, function(service) { 20 | console.log; 21 | console.log("=== Service ==="); 22 | return console.log(service); 23 | }); 24 | 25 | }).call(this); 26 | -------------------------------------------------------------------------------- /examples/show-user.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | # clear terminal 4 | process.stdout.write '\u001B[2J\u001B[0;0f' 5 | 6 | 7 | Gitlab = require('..') 8 | 9 | credentials = require './credentials' 10 | 11 | gitlab = new Gitlab 12 | url: credentials.url 13 | token: credentials.token 14 | 15 | userId = parseInt process.argv[2] 16 | 17 | gitlab.users.show userId, (user) -> 18 | console.log user 19 | -------------------------------------------------------------------------------- /examples/show-user.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, credentials, gitlab, userId; 3 | 4 | process.stdout.write('\u001B[2J\u001B[0;0f'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = require('./credentials'); 9 | 10 | gitlab = new Gitlab({ 11 | url: credentials.url, 12 | token: credentials.token 13 | }); 14 | 15 | userId = parseInt(process.argv[2]); 16 | 17 | gitlab.users.show(userId, function(user) { 18 | return console.log(user); 19 | }); 20 | 21 | }).call(this); 22 | -------------------------------------------------------------------------------- /lib/ApiBase.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var debug, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 4 | 5 | debug = require('debug')('gitlab:ApiBase'); 6 | 7 | module.exports.ApiBase = (function() { 8 | function ApiBase(options) { 9 | this.options = options; 10 | this.init = bind(this.init, this); 11 | this.handleOptions = bind(this.handleOptions, this); 12 | this.handleOptions(); 13 | this.init(); 14 | debug("constructor()"); 15 | } 16 | 17 | ApiBase.prototype.handleOptions = function() { 18 | var base; 19 | if ((base = this.options).verbose == null) { 20 | base.verbose = false; 21 | } 22 | return debug("handleOptions()"); 23 | }; 24 | 25 | ApiBase.prototype.init = function() { 26 | this.client = this; 27 | debug("init()"); 28 | this.groups = require('./Models/Groups')(this.client); 29 | this.projects = require('./Models/Projects')(this.client); 30 | this.issues = require('./Models/Issues')(this.client); 31 | this.notes = require('./Models/Notes')(this.client); 32 | this.users = require('./Models/Users')(this.client); 33 | return this.labels = require('./Models/Labels')(this.client); 34 | }; 35 | 36 | return ApiBase; 37 | 38 | })(); 39 | 40 | }).call(this); 41 | -------------------------------------------------------------------------------- /lib/ApiBaseHTTP.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var ApiBase, debug, querystring, slumber, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | debug = require('debug')('gitlab:ApiBaseHTTP'); 8 | 9 | ApiBase = require('./ApiBase').ApiBase; 10 | 11 | querystring = require('querystring'); 12 | 13 | slumber = require('slumber'); 14 | 15 | module.exports.ApiBaseHTTP = (function(superClass) { 16 | extend(ApiBaseHTTP, superClass); 17 | 18 | function ApiBaseHTTP() { 19 | this.patch = bind(this.patch, this); 20 | this.put = bind(this.put, this); 21 | this.post = bind(this.post, this); 22 | this["delete"] = bind(this["delete"], this); 23 | this.get = bind(this.get, this); 24 | this.fn_wrapper = bind(this.fn_wrapper, this); 25 | this.prepare_opts = bind(this.prepare_opts, this); 26 | this.init = bind(this.init, this); 27 | this.handleOptions = bind(this.handleOptions, this); 28 | return ApiBaseHTTP.__super__.constructor.apply(this, arguments); 29 | } 30 | 31 | ApiBaseHTTP.prototype.handleOptions = function() { 32 | var base, base1, base2; 33 | ApiBaseHTTP.__super__.handleOptions.apply(this, arguments); 34 | if ((base = this.options).base_url == null) { 35 | base.base_url = ''; 36 | } 37 | if (!this.options.url) { 38 | throw "`url` is mandatory"; 39 | } 40 | if (!(this.options.token || this.options.oauth_token)) { 41 | throw "`private_token` or `oauth_token` is mandatory"; 42 | } 43 | if ((base1 = this.options).slumber == null) { 44 | base1.slumber = {}; 45 | } 46 | if ((base2 = this.options.slumber).append_slash == null) { 47 | base2.append_slash = false; 48 | } 49 | this.options.url = this.options.url.replace(/\/api\/v3/, ''); 50 | if (this.options.auth != null) { 51 | this.options.slumber.auth = this.options.auth; 52 | } 53 | return debug("handleOptions()"); 54 | }; 55 | 56 | ApiBaseHTTP.prototype.init = function() { 57 | var api; 58 | ApiBaseHTTP.__super__.init.apply(this, arguments); 59 | api = slumber.API(this.options.url, this.options.slumber); 60 | return this.slumber = api(this.options.base_url); 61 | }; 62 | 63 | ApiBaseHTTP.prototype.prepare_opts = function(opts) { 64 | if (opts.__query == null) { 65 | opts.__query = {}; 66 | } 67 | if (this.options.token) { 68 | opts.headers = { 69 | 'PRIVATE-TOKEN': this.options.token 70 | }; 71 | } else { 72 | opts.headers = { 73 | 'Authorization': 'Bearer ' + this.options.oauth_token 74 | }; 75 | } 76 | return opts; 77 | }; 78 | 79 | ApiBaseHTTP.prototype.fn_wrapper = function(fn) { 80 | return (function(_this) { 81 | return function(err, response, ret) { 82 | var arity; 83 | arity = fn.length; 84 | switch (arity) { 85 | case 1: 86 | return fn(ret); 87 | case 2: 88 | return fn(err, ret || JSON.parse(response.body).message); 89 | case 3: 90 | return fn(err, response, ret); 91 | } 92 | }; 93 | })(this); 94 | }; 95 | 96 | ApiBaseHTTP.prototype.get = function(path, query, fn) { 97 | var opts; 98 | if (query == null) { 99 | query = {}; 100 | } 101 | if (fn == null) { 102 | fn = null; 103 | } 104 | if ('function' === typeof query) { 105 | fn = query; 106 | query = {}; 107 | } 108 | opts = this.prepare_opts(query); 109 | return this.slumber(path).get(opts, this.fn_wrapper(fn)); 110 | }; 111 | 112 | ApiBaseHTTP.prototype["delete"] = function(path, fn) { 113 | var opts; 114 | if (fn == null) { 115 | fn = null; 116 | } 117 | opts = this.prepare_opts({}); 118 | return this.slumber(path)["delete"](opts, this.fn_wrapper(fn)); 119 | }; 120 | 121 | ApiBaseHTTP.prototype.post = function(path, data, fn) { 122 | var opts; 123 | if (data == null) { 124 | data = {}; 125 | } 126 | if (fn == null) { 127 | fn = null; 128 | } 129 | opts = this.prepare_opts(data); 130 | return this.slumber(path).post(opts, this.fn_wrapper(fn)); 131 | }; 132 | 133 | ApiBaseHTTP.prototype.put = function(path, data, fn) { 134 | var opts; 135 | if (data == null) { 136 | data = {}; 137 | } 138 | if (fn == null) { 139 | fn = null; 140 | } 141 | opts = this.prepare_opts(data); 142 | return this.slumber(path).put(opts, this.fn_wrapper(fn)); 143 | }; 144 | 145 | ApiBaseHTTP.prototype.patch = function(path, data, fn) { 146 | var opts; 147 | if (data == null) { 148 | data = {}; 149 | } 150 | if (fn == null) { 151 | fn = null; 152 | } 153 | opts = this.prepare_opts(data); 154 | return this.slumber(path).patch(opts, this.fn_wrapper(fn)); 155 | }; 156 | 157 | return ApiBaseHTTP; 158 | 159 | })(ApiBase); 160 | 161 | }).call(this); 162 | -------------------------------------------------------------------------------- /lib/ApiV3.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var ApiBaseHTTP, debug, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | debug = require('debug')('gitlab:ApiV3'); 8 | 9 | ApiBaseHTTP = require('./ApiBaseHTTP').ApiBaseHTTP; 10 | 11 | module.exports.ApiV3 = (function(superClass) { 12 | extend(ApiV3, superClass); 13 | 14 | function ApiV3() { 15 | this.handleOptions = bind(this.handleOptions, this); 16 | return ApiV3.__super__.constructor.apply(this, arguments); 17 | } 18 | 19 | ApiV3.prototype.handleOptions = function() { 20 | ApiV3.__super__.handleOptions.apply(this, arguments); 21 | this.options.base_url = 'api/v3'; 22 | return debug("handleOptions()"); 23 | }; 24 | 25 | return ApiV3; 26 | 27 | })(ApiBaseHTTP); 28 | 29 | }).call(this); 30 | -------------------------------------------------------------------------------- /lib/BaseModel.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var debug, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 4 | 5 | debug = require('debug')('gitlab:BaseModel'); 6 | 7 | module.exports = (function() { 8 | function exports(client) { 9 | this.client = client; 10 | this._init = bind(this._init, this); 11 | this.load = bind(this.load, this); 12 | this._init(); 13 | } 14 | 15 | exports.prototype.load = function(model) { 16 | return require("./Models/" + model)(this.client); 17 | }; 18 | 19 | exports.prototype._init = function() { 20 | this.debug = require('debug')("gitlab:Models:" + this.constructor.name); 21 | this.get = this.client.get; 22 | this.post = this.client.post; 23 | this.put = this.client.put; 24 | this["delete"] = this.client["delete"]; 25 | if (this.init != null) { 26 | return this.init(); 27 | } 28 | }; 29 | 30 | return exports; 31 | 32 | })(); 33 | 34 | }).call(this); 35 | -------------------------------------------------------------------------------- /lib/Models/Groups.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Groups, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Groups = (function(superClass) { 10 | extend(Groups, superClass); 11 | 12 | function Groups() { 13 | this.search = bind(this.search, this); 14 | this.deleteGroup = bind(this.deleteGroup, this); 15 | this.addProject = bind(this.addProject, this); 16 | this.create = bind(this.create, this); 17 | this.removeMember = bind(this.removeMember, this); 18 | this.editMember = bind(this.editMember, this); 19 | this.addMember = bind(this.addMember, this); 20 | this.listMembers = bind(this.listMembers, this); 21 | this.listProjects = bind(this.listProjects, this); 22 | this.show = bind(this.show, this); 23 | this.all = bind(this.all, this); 24 | this.init = bind(this.init, this); 25 | return Groups.__super__.constructor.apply(this, arguments); 26 | } 27 | 28 | Groups.prototype.init = function() { 29 | return this.access_levels = { 30 | GUEST: 10, 31 | REPORTER: 20, 32 | DEVELOPER: 30, 33 | MASTER: 40, 34 | OWNER: 50 35 | }; 36 | }; 37 | 38 | Groups.prototype.all = function(params, fn) { 39 | var cb, data; 40 | if (params == null) { 41 | params = {}; 42 | } 43 | if (fn == null) { 44 | fn = null; 45 | } 46 | if ('function' === typeof params) { 47 | fn = params; 48 | params = {}; 49 | } 50 | this.debug("Groups::all()"); 51 | if (params.page == null) { 52 | params.page = 1; 53 | } 54 | if (params.per_page == null) { 55 | params.per_page = 100; 56 | } 57 | data = []; 58 | cb = (function(_this) { 59 | return function(err, retData) { 60 | if (err) { 61 | if (fn) { 62 | return fn(retData || data); 63 | } 64 | } else if (retData.length === params.per_page) { 65 | _this.debug("Recurse Groups::all()"); 66 | data = data.concat(retData); 67 | params.page++; 68 | return _this.get("groups", params, cb); 69 | } else { 70 | data = data.concat(retData); 71 | if (fn) { 72 | return fn(data); 73 | } 74 | } 75 | }; 76 | })(this); 77 | return this.get("groups", params, cb); 78 | }; 79 | 80 | Groups.prototype.show = function(groupId, fn) { 81 | if (fn == null) { 82 | fn = null; 83 | } 84 | this.debug("Groups::show()"); 85 | return this.get("groups/" + (parseInt(groupId)), (function(_this) { 86 | return function(data) { 87 | if (fn) { 88 | return fn(data); 89 | } 90 | }; 91 | })(this)); 92 | }; 93 | 94 | Groups.prototype.listProjects = function(groupId, fn) { 95 | if (fn == null) { 96 | fn = null; 97 | } 98 | this.debug("Groups::listProjects()"); 99 | return this.get("groups/" + (parseInt(groupId)), (function(_this) { 100 | return function(data) { 101 | if (fn) { 102 | return fn(data.projects); 103 | } 104 | }; 105 | })(this)); 106 | }; 107 | 108 | Groups.prototype.listMembers = function(groupId, fn) { 109 | if (fn == null) { 110 | fn = null; 111 | } 112 | this.debug("Groups::listMembers()"); 113 | return this.get("groups/" + (parseInt(groupId)) + "/members", (function(_this) { 114 | return function(data) { 115 | if (fn) { 116 | return fn(data); 117 | } 118 | }; 119 | })(this)); 120 | }; 121 | 122 | Groups.prototype.addMember = function(groupId, userId, accessLevel, fn) { 123 | var checkAccessLevel, params; 124 | if (fn == null) { 125 | fn = null; 126 | } 127 | this.debug("addMember(" + groupId + ", " + userId + ", " + accessLevel + ")"); 128 | checkAccessLevel = (function(_this) { 129 | return function() { 130 | var access_level, k, ref; 131 | ref = _this.access_levels; 132 | for (k in ref) { 133 | access_level = ref[k]; 134 | if (accessLevel === access_level) { 135 | return true; 136 | } 137 | } 138 | return false; 139 | }; 140 | })(this); 141 | if (!checkAccessLevel()) { 142 | throw "`accessLevel` must be one of " + (JSON.stringify(this.access_levels)); 143 | } 144 | params = { 145 | user_id: userId, 146 | access_level: accessLevel 147 | }; 148 | return this.post("groups/" + (parseInt(groupId)) + "/members", params, function(data) { 149 | if (fn) { 150 | return fn(data); 151 | } 152 | }); 153 | }; 154 | 155 | Groups.prototype.editMember = function(groupId, userId, accessLevel, fn) { 156 | var checkAccessLevel, params; 157 | if (fn == null) { 158 | fn = null; 159 | } 160 | this.debug("Groups::editMember(" + groupId + ", " + userId + ", " + accessLevel + ")"); 161 | checkAccessLevel = (function(_this) { 162 | return function() { 163 | var access_level, k, ref; 164 | ref = _this.access_levels; 165 | for (k in ref) { 166 | access_level = ref[k]; 167 | if (accessLevel === access_level) { 168 | return true; 169 | } 170 | } 171 | return false; 172 | }; 173 | })(this); 174 | if (!checkAccessLevel()) { 175 | throw "`accessLevel` must be one of " + (JSON.stringify(this.access_levels)); 176 | } 177 | params = { 178 | access_level: accessLevel 179 | }; 180 | return this.put("groups/" + (parseInt(groupId)) + "/members/" + (parseInt(userId)), params, function(data) { 181 | if (fn) { 182 | return fn(data); 183 | } 184 | }); 185 | }; 186 | 187 | Groups.prototype.removeMember = function(groupId, userId, fn) { 188 | if (fn == null) { 189 | fn = null; 190 | } 191 | this.debug("Groups::removeMember(" + groupId + ", " + userId + ")"); 192 | return this["delete"]("groups/" + (parseInt(groupId)) + "/members/" + (parseInt(userId)), function(data) { 193 | if (fn) { 194 | return fn(data); 195 | } 196 | }); 197 | }; 198 | 199 | Groups.prototype.create = function(params, fn) { 200 | if (params == null) { 201 | params = {}; 202 | } 203 | if (fn == null) { 204 | fn = null; 205 | } 206 | this.debug("Groups::create()"); 207 | return this.post("groups", params, function(data) { 208 | if (fn) { 209 | return fn(data); 210 | } 211 | }); 212 | }; 213 | 214 | Groups.prototype.addProject = function(groupId, projectId, fn) { 215 | if (fn == null) { 216 | fn = null; 217 | } 218 | this.debug("Groups::addProject(" + groupId + ", " + projectId + ")"); 219 | return this.post("groups/" + (parseInt(groupId)) + "/projects/" + (parseInt(projectId)), null, function(data) { 220 | if (fn) { 221 | return fn(data); 222 | } 223 | }); 224 | }; 225 | 226 | Groups.prototype.deleteGroup = function(groupId, fn) { 227 | if (fn == null) { 228 | fn = null; 229 | } 230 | this.debug("Groups::delete(" + groupId + ")"); 231 | return this["delete"]("groups/" + (parseInt(groupId)), function(data) { 232 | if (fn) { 233 | return fn(data); 234 | } 235 | }); 236 | }; 237 | 238 | Groups.prototype.search = function(nameOrPath, fn) { 239 | var params; 240 | if (fn == null) { 241 | fn = null; 242 | } 243 | this.debug("Groups::search(" + nameOrPath + ")"); 244 | params = { 245 | search: nameOrPath 246 | }; 247 | return this.get("groups", params, function(data) { 248 | if (fn) { 249 | return fn(data); 250 | } 251 | }); 252 | }; 253 | 254 | return Groups; 255 | 256 | })(BaseModel); 257 | 258 | module.exports = function(client) { 259 | return new Groups(client); 260 | }; 261 | 262 | }).call(this); 263 | -------------------------------------------------------------------------------- /lib/Models/IssueNotes.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, IssueNotes, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | IssueNotes = (function(superClass) { 12 | extend(IssueNotes, superClass); 13 | 14 | function IssueNotes() { 15 | this.all = bind(this.all, this); 16 | return IssueNotes.__super__.constructor.apply(this, arguments); 17 | } 18 | 19 | IssueNotes.prototype.all = function(projectId, issueId, params, fn) { 20 | var cb, data; 21 | if (params == null) { 22 | params = {}; 23 | } 24 | if (fn == null) { 25 | fn = null; 26 | } 27 | this.debug("IssueNotes::notes()"); 28 | if ('function' === typeof params) { 29 | fn = params; 30 | params = {}; 31 | } 32 | if (params.page == null) { 33 | params.page = 1; 34 | } 35 | if (params.per_page == null) { 36 | params.per_page = 100; 37 | } 38 | data = []; 39 | cb = (function(_this) { 40 | return function(err, retData) { 41 | if (err) { 42 | if (fn) { 43 | return fn(data); 44 | } 45 | } else if (retData.length === params.per_page) { 46 | _this.debug("Recurse IssueNotes::all()"); 47 | data = data.concat(retData); 48 | params.page++; 49 | return _this.get("projects/" + (Utils.parseProjectId(projectId)) + "/issues/" + (parseInt(issueId)) + "/notes", params, cb); 50 | } else { 51 | data = data.concat(retData); 52 | if (fn) { 53 | return fn(data); 54 | } 55 | } 56 | }; 57 | })(this); 58 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/issues/" + (parseInt(issueId)) + "/notes", params, cb); 59 | }; 60 | 61 | return IssueNotes; 62 | 63 | })(BaseModel); 64 | 65 | module.exports = function(client) { 66 | return new IssueNotes(client); 67 | }; 68 | 69 | }).call(this); 70 | -------------------------------------------------------------------------------- /lib/Models/Issues.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Issues, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Issues = (function(superClass) { 10 | extend(Issues, superClass); 11 | 12 | function Issues() { 13 | this.unsubscribe = bind(this.unsubscribe, this); 14 | this.subscribe = bind(this.subscribe, this); 15 | this.remove = bind(this.remove, this); 16 | this.edit = bind(this.edit, this); 17 | this.create = bind(this.create, this); 18 | this.show = bind(this.show, this); 19 | this.all = bind(this.all, this); 20 | return Issues.__super__.constructor.apply(this, arguments); 21 | } 22 | 23 | Issues.prototype.all = function(params, fn) { 24 | if (params == null) { 25 | params = {}; 26 | } 27 | if (fn == null) { 28 | fn = null; 29 | } 30 | if ('function' === typeof params) { 31 | fn = params; 32 | params = {}; 33 | } 34 | this.debug("Issues::all()"); 35 | if (params.page == null) { 36 | params.page = 1; 37 | } 38 | if (params.per_page == null) { 39 | params.per_page = 100; 40 | } 41 | return (function() { 42 | var cb, data; 43 | data = []; 44 | cb = (function(_this) { 45 | return function(retData) { 46 | if (retData.length === params.per_page) { 47 | _this.debug("Recurse Issues::all()"); 48 | data = data.concat(retData); 49 | params.page++; 50 | return _this.get("issues", params, cb); 51 | } else { 52 | data = data.concat(retData); 53 | if (fn) { 54 | return fn(data); 55 | } 56 | } 57 | }; 58 | })(this); 59 | return this.get("issues", params, cb); 60 | }).bind(this)(); 61 | }; 62 | 63 | Issues.prototype.show = function(projectId, issueId, fn) { 64 | if (fn == null) { 65 | fn = null; 66 | } 67 | this.debug("Issues::show()"); 68 | if (projectId.toString().indexOf("/") !== -1) { 69 | projectId = encodeURIComponent(projectId); 70 | } else { 71 | projectId = parseInt(projectId); 72 | } 73 | if (issueId.toString().indexOf("/") !== -1) { 74 | issueId = encodeURIComponent(issueId); 75 | } else { 76 | issueId = parseInt(issueId); 77 | } 78 | return this.get("projects/" + projectId + "/issues/" + issueId, (function(_this) { 79 | return function(data) { 80 | if (fn) { 81 | return fn(data); 82 | } 83 | }; 84 | })(this)); 85 | }; 86 | 87 | Issues.prototype.create = function(projectId, params, fn) { 88 | if (params == null) { 89 | params = {}; 90 | } 91 | if (fn == null) { 92 | fn = null; 93 | } 94 | this.debug("Issues::create()"); 95 | if (projectId.toString().indexOf("/") !== -1) { 96 | projectId = encodeURIComponent(projectId); 97 | } else { 98 | projectId = parseInt(projectId); 99 | } 100 | return this.post("projects/" + projectId + "/issues", params, function(data) { 101 | if (fn) { 102 | return fn(data); 103 | } 104 | }); 105 | }; 106 | 107 | Issues.prototype.edit = function(projectId, issueId, params, fn) { 108 | if (params == null) { 109 | params = {}; 110 | } 111 | if (fn == null) { 112 | fn = null; 113 | } 114 | this.debug("Issues::edit()"); 115 | if (projectId.toString().indexOf("/") !== -1) { 116 | projectId = encodeURIComponent(projectId); 117 | } else { 118 | projectId = parseInt(projectId); 119 | } 120 | if (issueId.toString().indexOf("/") !== -1) { 121 | issueId = encodeURIComponent(issueId); 122 | } else { 123 | issueId = parseInt(issueId); 124 | } 125 | return this.put("projects/" + projectId + "/issues/" + issueId, params, function(data) { 126 | if (fn) { 127 | return fn(data); 128 | } 129 | }); 130 | }; 131 | 132 | Issues.prototype.remove = function(projectId, issueId, fn) { 133 | if (fn == null) { 134 | fn = null; 135 | } 136 | this.debug("Issues::remove()"); 137 | if (projectId.toString().indexOf("/") !== -1) { 138 | projectId = encodeURIComponent(projectId); 139 | } else { 140 | projectId = parseInt(projectId); 141 | } 142 | if (issueId.toString().indexOf("/") !== -1) { 143 | issueId = encodeURIComponent(issueId); 144 | } else { 145 | issueId = parseInt(issueId); 146 | } 147 | return this["delete"]("projects/" + projectId + "/issues/" + issueId, function(data) { 148 | if (fn) { 149 | return fn(data); 150 | } 151 | }); 152 | }; 153 | 154 | Issues.prototype.subscribe = function(projectId, issueId, params, fn) { 155 | if (params == null) { 156 | params = {}; 157 | } 158 | if (fn == null) { 159 | fn = null; 160 | } 161 | this.debug("Issues::subscribe()"); 162 | if (projectId.toString().indexOf("/") !== -1) { 163 | projectId = encodeURIComponent(projectId); 164 | } else { 165 | projectId = parseInt(projectId); 166 | } 167 | if (issueId.toString().indexOf("/") !== -1) { 168 | issueId = encodeURIComponent(issueId); 169 | } else { 170 | issueId = parseInt(issueId); 171 | } 172 | return this.post("projects/" + projectId + "/issues/" + issueId + "/subscription", function(data) { 173 | if (fn) { 174 | return fn(data); 175 | } 176 | }); 177 | }; 178 | 179 | Issues.prototype.unsubscribe = function(projectId, issueId, fn) { 180 | if (fn == null) { 181 | fn = null; 182 | } 183 | this.debug("Issues::unsubscribe()"); 184 | if (projectId.toString().indexOf("/") !== -1) { 185 | projectId = encodeURIComponent(projectId); 186 | } else { 187 | projectId = parseInt(projectId); 188 | } 189 | if (issueId.toString().indexOf("/") !== -1) { 190 | issueId = encodeURIComponent(issueId); 191 | } else { 192 | issueId = parseInt(issueId); 193 | } 194 | return this["delete"]("projects/" + projectId + "/issues/" + issueId + "/subscription", function(data) { 195 | if (fn) { 196 | return fn(data); 197 | } 198 | }); 199 | }; 200 | 201 | return Issues; 202 | 203 | })(BaseModel); 204 | 205 | module.exports = function(client) { 206 | return new Issues(client); 207 | }; 208 | 209 | }).call(this); 210 | -------------------------------------------------------------------------------- /lib/Models/Labels.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Labels, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | Labels = (function(superClass) { 12 | extend(Labels, superClass); 13 | 14 | function Labels() { 15 | this.create = bind(this.create, this); 16 | return Labels.__super__.constructor.apply(this, arguments); 17 | } 18 | 19 | Labels.prototype.create = function(projectId, params, fn) { 20 | if (params == null) { 21 | params = {}; 22 | } 23 | if (fn == null) { 24 | fn = null; 25 | } 26 | this.debug("Labels::create()"); 27 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/labels", params, function(data) { 28 | if (fn) { 29 | return fn(data); 30 | } 31 | }); 32 | }; 33 | 34 | return Labels; 35 | 36 | })(BaseModel); 37 | 38 | module.exports = function(client) { 39 | return new Labels(client); 40 | }; 41 | 42 | }).call(this); 43 | -------------------------------------------------------------------------------- /lib/Models/Notes.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Notes, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | Notes = (function(superClass) { 12 | extend(Notes, superClass); 13 | 14 | function Notes() { 15 | this.create = bind(this.create, this); 16 | return Notes.__super__.constructor.apply(this, arguments); 17 | } 18 | 19 | Notes.prototype.create = function(projectId, issueId, params, fn) { 20 | if (params == null) { 21 | params = {}; 22 | } 23 | if (fn == null) { 24 | fn = null; 25 | } 26 | this.debug("Notes::create()"); 27 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/issues/" + (parseInt(issueId)) + "/notes", params, function(data) { 28 | if (fn) { 29 | return fn(data); 30 | } 31 | }); 32 | }; 33 | 34 | return Notes; 35 | 36 | })(BaseModel); 37 | 38 | module.exports = function(client) { 39 | return new Notes(client); 40 | }; 41 | 42 | }).call(this); 43 | -------------------------------------------------------------------------------- /lib/Models/Pipelines.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Pipelines, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | Pipelines = (function(superClass) { 12 | extend(Pipelines, superClass); 13 | 14 | function Pipelines() { 15 | this.all = bind(this.all, this); 16 | return Pipelines.__super__.constructor.apply(this, arguments); 17 | } 18 | 19 | Pipelines.prototype.all = function(projectId, fn) { 20 | if (fn == null) { 21 | fn = null; 22 | } 23 | this.debug("Pipelines::all()"); 24 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/pipelines", (function(_this) { 25 | return function(data) { 26 | if (fn) { 27 | return fn(data); 28 | } 29 | }; 30 | })(this)); 31 | }; 32 | 33 | return Pipelines; 34 | 35 | })(BaseModel); 36 | 37 | module.exports = function(client) { 38 | return new Pipelines(client); 39 | }; 40 | 41 | }).call(this); 42 | -------------------------------------------------------------------------------- /lib/Models/ProjectBuilds.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectBuilds, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectBuilds = (function(superClass) { 12 | extend(ProjectBuilds, superClass); 13 | 14 | function ProjectBuilds() { 15 | this.triggerBuild = bind(this.triggerBuild, this); 16 | this.showBuild = bind(this.showBuild, this); 17 | this.listBuilds = bind(this.listBuilds, this); 18 | return ProjectBuilds.__super__.constructor.apply(this, arguments); 19 | } 20 | 21 | ProjectBuilds.prototype.listBuilds = function(projectId, params, fn) { 22 | if (params == null) { 23 | params = {}; 24 | } 25 | if (fn == null) { 26 | fn = null; 27 | } 28 | if ('function' === typeof params) { 29 | fn = params; 30 | params = {}; 31 | } 32 | if (params.page == null) { 33 | params.page = 1; 34 | } 35 | if (params.per_page == null) { 36 | params.per_page = 100; 37 | } 38 | this.debug("Projects::listBuilds()"); 39 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds", params, (function(_this) { 40 | return function(data) { 41 | if (fn) { 42 | return fn(data); 43 | } 44 | }; 45 | })(this)); 46 | }; 47 | 48 | ProjectBuilds.prototype.showBuild = function(projectId, buildId, fn) { 49 | if (fn == null) { 50 | fn = null; 51 | } 52 | this.debug("Projects::build()"); 53 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds/" + buildId, null, (function(_this) { 54 | return function(data) { 55 | if (fn) { 56 | return fn(data); 57 | } 58 | }; 59 | })(this)); 60 | }; 61 | 62 | ProjectBuilds.prototype.triggerBuild = function(params, fn) { 63 | if (params == null) { 64 | params = {}; 65 | } 66 | if (fn == null) { 67 | fn = null; 68 | } 69 | this.debug("Projects::triggerBuild()"); 70 | return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/trigger/builds", params, function(data) { 71 | if (fn) { 72 | return fn(data); 73 | } 74 | }); 75 | }; 76 | 77 | return ProjectBuilds; 78 | 79 | })(BaseModel); 80 | 81 | module.exports = function(client) { 82 | return new ProjectBuilds(client); 83 | }; 84 | 85 | }).call(this); 86 | -------------------------------------------------------------------------------- /lib/Models/ProjectDeployKeys.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectKeys, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectKeys = (function(superClass) { 12 | extend(ProjectKeys, superClass); 13 | 14 | function ProjectKeys() { 15 | this.addKey = bind(this.addKey, this); 16 | this.getKey = bind(this.getKey, this); 17 | this.listKeys = bind(this.listKeys, this); 18 | return ProjectKeys.__super__.constructor.apply(this, arguments); 19 | } 20 | 21 | ProjectKeys.prototype.listKeys = function(projectId, fn) { 22 | if (fn == null) { 23 | fn = null; 24 | } 25 | this.debug("ProjectKeys::listKeys()"); 26 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/keys", (function(_this) { 27 | return function(data) { 28 | if (fn) { 29 | return fn(data); 30 | } 31 | }; 32 | })(this)); 33 | }; 34 | 35 | ProjectKeys.prototype.getKey = function(projectId, keyId, fn) { 36 | if (fn == null) { 37 | fn = null; 38 | } 39 | this.debug("ProjectKeys::getKey()"); 40 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/keys/" + (parseInt(keyId)), (function(_this) { 41 | return function(data) { 42 | if (fn) { 43 | return fn(data); 44 | } 45 | }; 46 | })(this)); 47 | }; 48 | 49 | ProjectKeys.prototype.addKey = function(projectId, params, fn) { 50 | if (params == null) { 51 | params = {}; 52 | } 53 | if (fn == null) { 54 | fn = null; 55 | } 56 | this.debug("ProjectKeys::addKey()"); 57 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/keys", params, (function(_this) { 58 | return function(data) { 59 | if (fn) { 60 | return fn(data); 61 | } 62 | }; 63 | })(this)); 64 | }; 65 | 66 | return ProjectKeys; 67 | 68 | })(BaseModel); 69 | 70 | module.exports = function(client) { 71 | return new ProjectKeys(client); 72 | }; 73 | 74 | }).call(this); 75 | -------------------------------------------------------------------------------- /lib/Models/ProjectHooks.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectHooks, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectHooks = (function(superClass) { 12 | extend(ProjectHooks, superClass); 13 | 14 | function ProjectHooks() { 15 | this.remove = bind(this.remove, this); 16 | this.update = bind(this.update, this); 17 | this.add = bind(this.add, this); 18 | this.show = bind(this.show, this); 19 | this.list = bind(this.list, this); 20 | return ProjectHooks.__super__.constructor.apply(this, arguments); 21 | } 22 | 23 | ProjectHooks.prototype.list = function(projectId, fn) { 24 | if (fn == null) { 25 | fn = null; 26 | } 27 | this.debug("Projects::hooks()"); 28 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/hooks", (function(_this) { 29 | return function(data) { 30 | if (fn) { 31 | return fn(data); 32 | } 33 | }; 34 | })(this)); 35 | }; 36 | 37 | ProjectHooks.prototype.show = function(projectId, hookId, fn) { 38 | if (fn == null) { 39 | fn = null; 40 | } 41 | this.debug("Projects::hook()"); 42 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/hooks/" + (parseInt(hookId)), (function(_this) { 43 | return function(data) { 44 | if (fn) { 45 | return fn(data); 46 | } 47 | }; 48 | })(this)); 49 | }; 50 | 51 | ProjectHooks.prototype.add = function(projectId, params, fn) { 52 | if (fn == null) { 53 | fn = null; 54 | } 55 | if ('string' === typeof params) { 56 | params = { 57 | url: params 58 | }; 59 | } 60 | this.debug("Projects::addHook()"); 61 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/hooks", params, (function(_this) { 62 | return function(data) { 63 | if (fn) { 64 | return fn(data); 65 | } 66 | }; 67 | })(this)); 68 | }; 69 | 70 | ProjectHooks.prototype.update = function(projectId, hookId, url, fn) { 71 | var params; 72 | if (fn == null) { 73 | fn = null; 74 | } 75 | this.debug("Projects::saveHook()"); 76 | params = { 77 | access_level: parseInt(accessLevel) 78 | }; 79 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/hooks/" + (parseInt(hookId)), params, (function(_this) { 80 | return function(data) { 81 | if (fn) { 82 | return fn(data); 83 | } 84 | }; 85 | })(this)); 86 | }; 87 | 88 | ProjectHooks.prototype.remove = function(projectId, hookId, fn) { 89 | if (fn == null) { 90 | fn = null; 91 | } 92 | this.debug("Projects::removeHook()"); 93 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/hooks/" + (parseInt(hookId)), (function(_this) { 94 | return function(data) { 95 | if (fn) { 96 | return fn(data); 97 | } 98 | }; 99 | })(this)); 100 | }; 101 | 102 | return ProjectHooks; 103 | 104 | })(BaseModel); 105 | 106 | module.exports = function(client) { 107 | return new ProjectHooks(client); 108 | }; 109 | 110 | }).call(this); 111 | -------------------------------------------------------------------------------- /lib/Models/ProjectIssues.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectIssues, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectIssues = (function(superClass) { 12 | extend(ProjectIssues, superClass); 13 | 14 | function ProjectIssues() { 15 | this.list = bind(this.list, this); 16 | this.init = bind(this.init, this); 17 | return ProjectIssues.__super__.constructor.apply(this, arguments); 18 | } 19 | 20 | ProjectIssues.prototype.init = function() { 21 | return this.notes = this.load('IssueNotes'); 22 | }; 23 | 24 | ProjectIssues.prototype.list = function(projectId, params, fn) { 25 | if (params == null) { 26 | params = {}; 27 | } 28 | if (fn == null) { 29 | fn = null; 30 | } 31 | this.debug("ProjectIssues::issues()"); 32 | if ('function' === typeof params) { 33 | fn = params; 34 | params = {}; 35 | } 36 | if (params.page == null) { 37 | params.page = 1; 38 | } 39 | if (params.per_page == null) { 40 | params.per_page = 100; 41 | } 42 | return (function() { 43 | var cb, data; 44 | data = []; 45 | cb = (function(_this) { 46 | return function(err, retData) { 47 | if (err) { 48 | if (fn) { 49 | return fn(data); 50 | } 51 | } 52 | if (retData.length === params.per_page) { 53 | _this.debug("Recurse ProjectIssues::list()"); 54 | data = data.concat(retData); 55 | params.page++; 56 | return _this.get("projects/" + (Utils.parseProjectId(projectId)) + "/issues", params, cb); 57 | } else { 58 | data = data.concat(retData); 59 | if (fn) { 60 | return fn(data); 61 | } 62 | } 63 | }; 64 | })(this); 65 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/issues", params, cb); 66 | }).bind(this)(); 67 | }; 68 | 69 | return ProjectIssues; 70 | 71 | })(BaseModel); 72 | 73 | module.exports = function(client) { 74 | return new ProjectIssues(client); 75 | }; 76 | 77 | }).call(this); 78 | -------------------------------------------------------------------------------- /lib/Models/ProjectLabels.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectLabels, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectLabels = (function(superClass) { 12 | extend(ProjectLabels, superClass); 13 | 14 | function ProjectLabels() { 15 | this.all = bind(this.all, this); 16 | return ProjectLabels.__super__.constructor.apply(this, arguments); 17 | } 18 | 19 | ProjectLabels.prototype.all = function(projectId, params, fn) { 20 | var cb, data; 21 | if (params == null) { 22 | params = {}; 23 | } 24 | if (fn == null) { 25 | fn = null; 26 | } 27 | this.debug("ProjectLabels::labels()"); 28 | if ('function' === typeof params) { 29 | fn = params; 30 | params = {}; 31 | } 32 | if (params.page == null) { 33 | params.page = 1; 34 | } 35 | if (params.per_page == null) { 36 | params.per_page = 100; 37 | } 38 | data = []; 39 | cb = (function(_this) { 40 | return function(err, retData) { 41 | if (err) { 42 | if (fn) { 43 | return fn(data); 44 | } 45 | } else if (retData.length === params.per_page) { 46 | _this.debug("Recurse ProjectLabels::all()"); 47 | data = data.concat(retData); 48 | params.page++; 49 | return _this.get("projects/" + (Utils.parseProjectId(projectId)) + "/labels", params, cb); 50 | } else { 51 | data = data.concat(retData); 52 | if (fn) { 53 | return fn(data); 54 | } 55 | } 56 | }; 57 | })(this); 58 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/labels", params, cb); 59 | }; 60 | 61 | return ProjectLabels; 62 | 63 | })(BaseModel); 64 | 65 | module.exports = function(client) { 66 | return new ProjectLabels(client); 67 | }; 68 | 69 | }).call(this); 70 | -------------------------------------------------------------------------------- /lib/Models/ProjectMembers.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectMembers, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectMembers = (function(superClass) { 12 | extend(ProjectMembers, superClass); 13 | 14 | function ProjectMembers() { 15 | this.remove = bind(this.remove, this); 16 | this.update = bind(this.update, this); 17 | this.add = bind(this.add, this); 18 | this.show = bind(this.show, this); 19 | this.list = bind(this.list, this); 20 | return ProjectMembers.__super__.constructor.apply(this, arguments); 21 | } 22 | 23 | ProjectMembers.prototype.list = function(projectId, fn) { 24 | if (fn == null) { 25 | fn = null; 26 | } 27 | this.debug("Projects::members()"); 28 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/members", (function(_this) { 29 | return function(data) { 30 | if (fn) { 31 | return fn(data); 32 | } 33 | }; 34 | })(this)); 35 | }; 36 | 37 | ProjectMembers.prototype.show = function(projectId, userId, fn) { 38 | if (fn == null) { 39 | fn = null; 40 | } 41 | this.debug("Projects::member()"); 42 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/members/" + (parseInt(userId)), (function(_this) { 43 | return function(data) { 44 | if (fn) { 45 | return fn(data); 46 | } 47 | }; 48 | })(this)); 49 | }; 50 | 51 | ProjectMembers.prototype.add = function(projectId, userId, accessLevel, fn) { 52 | var params; 53 | if (accessLevel == null) { 54 | accessLevel = 30; 55 | } 56 | if (fn == null) { 57 | fn = null; 58 | } 59 | this.debug("Projects::addMember()"); 60 | params = { 61 | user_id: parseInt(userId), 62 | access_level: parseInt(accessLevel) 63 | }; 64 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/members", params, (function(_this) { 65 | return function(data) { 66 | if (fn) { 67 | return fn(data); 68 | } 69 | }; 70 | })(this)); 71 | }; 72 | 73 | ProjectMembers.prototype.update = function(projectId, userId, accessLevel, fn) { 74 | var params; 75 | if (accessLevel == null) { 76 | accessLevel = 30; 77 | } 78 | if (fn == null) { 79 | fn = null; 80 | } 81 | this.debug("Projects::saveMember()"); 82 | params = { 83 | access_level: parseInt(accessLevel) 84 | }; 85 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/members/" + (parseInt(userId)), params, (function(_this) { 86 | return function(data) { 87 | if (fn) { 88 | return fn(data); 89 | } 90 | }; 91 | })(this)); 92 | }; 93 | 94 | ProjectMembers.prototype.remove = function(projectId, userId, fn) { 95 | if (fn == null) { 96 | fn = null; 97 | } 98 | this.debug("Projects::removeMember()"); 99 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/members/" + (parseInt(userId)), (function(_this) { 100 | return function(data) { 101 | if (fn) { 102 | return fn(data); 103 | } 104 | }; 105 | })(this)); 106 | }; 107 | 108 | return ProjectMembers; 109 | 110 | })(BaseModel); 111 | 112 | module.exports = function(client) { 113 | return new ProjectMembers(client); 114 | }; 115 | 116 | }).call(this); 117 | -------------------------------------------------------------------------------- /lib/Models/ProjectMergeRequests.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectMergeRequests, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectMergeRequests = (function(superClass) { 12 | extend(ProjectMergeRequests, superClass); 13 | 14 | function ProjectMergeRequests() { 15 | this.merge = bind(this.merge, this); 16 | this.comment = bind(this.comment, this); 17 | this.update = bind(this.update, this); 18 | this.add = bind(this.add, this); 19 | this.show = bind(this.show, this); 20 | this.list = bind(this.list, this); 21 | return ProjectMergeRequests.__super__.constructor.apply(this, arguments); 22 | } 23 | 24 | ProjectMergeRequests.prototype.list = function(projectId, params, fn) { 25 | if (params == null) { 26 | params = {}; 27 | } 28 | if (fn == null) { 29 | fn = null; 30 | } 31 | if ('function' === typeof params) { 32 | fn = params; 33 | params = {}; 34 | } 35 | if (params.page == null) { 36 | params.page = 1; 37 | } 38 | if (params.per_page == null) { 39 | params.per_page = 100; 40 | } 41 | this.debug("Projects::mergerequests()"); 42 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/merge_requests", params, (function(_this) { 43 | return function(data) { 44 | if (fn) { 45 | return fn(data); 46 | } 47 | }; 48 | })(this)); 49 | }; 50 | 51 | ProjectMergeRequests.prototype.show = function(projectId, mergerequestId, fn) { 52 | if (fn == null) { 53 | fn = null; 54 | } 55 | this.debug("Projects::mergerequest()"); 56 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/merge_request/" + (parseInt(mergerequestId)), (function(_this) { 57 | return function(data) { 58 | if (fn) { 59 | return fn(data); 60 | } 61 | }; 62 | })(this)); 63 | }; 64 | 65 | ProjectMergeRequests.prototype.add = function(projectId, sourceBranch, targetBranch, assigneeId, title, fn) { 66 | var params; 67 | if (fn == null) { 68 | fn = null; 69 | } 70 | this.debug("Projects::addMergeRequest()"); 71 | params = { 72 | id: Utils.parseProjectId(projectId), 73 | source_branch: sourceBranch, 74 | target_branch: targetBranch, 75 | title: title 76 | }; 77 | if (assigneeId !== void 0) { 78 | params.assigneeId = parseInt(assigneeId); 79 | } 80 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/merge_requests", params, (function(_this) { 81 | return function(data) { 82 | if (fn) { 83 | return fn(data); 84 | } 85 | }; 86 | })(this)); 87 | }; 88 | 89 | ProjectMergeRequests.prototype.update = function(projectId, mergerequestId, params, fn) { 90 | if (fn == null) { 91 | fn = null; 92 | } 93 | this.debug("Projects::saveMergeRequest()"); 94 | params.id = Utils.parseProjectId(projectId); 95 | params.merge_request_id = parseInt(mergerequestId); 96 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/merge_request/" + (parseInt(mergerequestId)), params, (function(_this) { 97 | return function(data) { 98 | if (fn) { 99 | return fn(data); 100 | } 101 | }; 102 | })(this)); 103 | }; 104 | 105 | ProjectMergeRequests.prototype.comment = function(projectId, mergerequestId, note, fn) { 106 | var params; 107 | if (fn == null) { 108 | fn = null; 109 | } 110 | this.debug("Projects::commentMergeRequest()"); 111 | params = { 112 | id: Utils.parseProjectId(projectId), 113 | merge_request_id: parseInt(mergerequestId), 114 | note: note 115 | }; 116 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/merge_request/" + (parseInt(mergerequestId)) + "/comments", params, (function(_this) { 117 | return function(data) { 118 | if (fn) { 119 | return fn(data); 120 | } 121 | }; 122 | })(this)); 123 | }; 124 | 125 | ProjectMergeRequests.prototype.merge = function(projectId, mergerequestId, params, fn) { 126 | if (fn == null) { 127 | fn = null; 128 | } 129 | this.debug("Projects::acceptMergeRequest()"); 130 | params.id = Utils.parseProjectId(projectId); 131 | params.merge_request_id = parseInt(mergerequestId); 132 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/merge_request/" + (parseInt(mergerequestId)) + "/merge", params, (function(_this) { 133 | return function(data) { 134 | if (fn) { 135 | return fn(data); 136 | } 137 | }; 138 | })(this)); 139 | }; 140 | 141 | return ProjectMergeRequests; 142 | 143 | })(BaseModel); 144 | 145 | module.exports = function(client) { 146 | return new ProjectMergeRequests(client); 147 | }; 148 | 149 | }).call(this); 150 | -------------------------------------------------------------------------------- /lib/Models/ProjectMilestones.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectMilestones, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectMilestones = (function(superClass) { 12 | var list; 13 | 14 | extend(ProjectMilestones, superClass); 15 | 16 | function ProjectMilestones() { 17 | this.update = bind(this.update, this); 18 | this.add = bind(this.add, this); 19 | this.show = bind(this.show, this); 20 | this.all = bind(this.all, this); 21 | return ProjectMilestones.__super__.constructor.apply(this, arguments); 22 | } 23 | 24 | list = function(projectId, fn) { 25 | if (fn == null) { 26 | fn = null; 27 | } 28 | console.log('DEPRECATED: milestone.list. Use milestone.all instead'); 29 | return this.all.apply(this, arguments); 30 | }; 31 | 32 | ProjectMilestones.prototype.all = function(projectId, fn) { 33 | var cb, data, params; 34 | if (fn == null) { 35 | fn = null; 36 | } 37 | this.debug("Projects::Milestones::all()"); 38 | params = {}; 39 | if (params.page == null) { 40 | params.page = 1; 41 | } 42 | if (params.per_page == null) { 43 | params.per_page = 100; 44 | } 45 | data = []; 46 | cb = (function(_this) { 47 | return function(err, retData) { 48 | if (err) { 49 | if (fn) { 50 | return fn(retData || data); 51 | } 52 | } else if (retData.length === params.per_page) { 53 | _this.debug("Recurse Projects::Milestones::all()"); 54 | data = data.concat(retData); 55 | params.page++; 56 | return _this.get("projects/" + (Utils.parseProjectId(projectId)) + "/milestones", params, cb); 57 | } else { 58 | data = data.concat(retData); 59 | if (fn) { 60 | return fn(data); 61 | } 62 | } 63 | }; 64 | })(this); 65 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/milestones", params, cb); 66 | }; 67 | 68 | ProjectMilestones.prototype.show = function(projectId, milestoneId, fn) { 69 | if (fn == null) { 70 | fn = null; 71 | } 72 | this.debug("Projects::milestone()"); 73 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/milestones/" + (parseInt(milestoneId)), (function(_this) { 74 | return function(data) { 75 | if (fn) { 76 | return fn(data); 77 | } 78 | }; 79 | })(this)); 80 | }; 81 | 82 | ProjectMilestones.prototype.add = function(projectId, title, description, due_date, fn) { 83 | var params; 84 | if (fn == null) { 85 | fn = null; 86 | } 87 | this.debug("Projects::addMilestone()"); 88 | params = { 89 | id: Utils.parseProjectId(projectId), 90 | title: title, 91 | description: description, 92 | due_date: due_date 93 | }; 94 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/milestones", params, (function(_this) { 95 | return function(data) { 96 | if (fn) { 97 | return fn(data); 98 | } 99 | }; 100 | })(this)); 101 | }; 102 | 103 | ProjectMilestones.prototype.update = function(projectId, milestoneId, title, description, due_date, state_event, fn) { 104 | var params; 105 | if (fn == null) { 106 | fn = null; 107 | } 108 | this.debug("Projects::editMilestone()"); 109 | params = { 110 | id: Utils.parseProjectId(projectId), 111 | title: title, 112 | description: description, 113 | due_date: due_date, 114 | state_event: state_event 115 | }; 116 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/milestones/" + (parseInt(milestoneId)), params, (function(_this) { 117 | return function(data) { 118 | if (fn) { 119 | return fn(data); 120 | } 121 | }; 122 | })(this)); 123 | }; 124 | 125 | return ProjectMilestones; 126 | 127 | })(BaseModel); 128 | 129 | module.exports = function(client) { 130 | return new ProjectMilestones(client); 131 | }; 132 | 133 | }).call(this); 134 | -------------------------------------------------------------------------------- /lib/Models/ProjectRepository.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectRepository, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectRepository = (function(superClass) { 12 | extend(ProjectRepository, superClass); 13 | 14 | function ProjectRepository() { 15 | this.compare = bind(this.compare, this); 16 | this.updateFile = bind(this.updateFile, this); 17 | this.createFile = bind(this.createFile, this); 18 | this.showFile = bind(this.showFile, this); 19 | this.listTree = bind(this.listTree, this); 20 | this.diffCommit = bind(this.diffCommit, this); 21 | this.showCommit = bind(this.showCommit, this); 22 | this.listCommits = bind(this.listCommits, this); 23 | this.listTags = bind(this.listTags, this); 24 | this.showTag = bind(this.showTag, this); 25 | this.deleteTag = bind(this.deleteTag, this); 26 | this.addTag = bind(this.addTag, this); 27 | this.deleteBranch = bind(this.deleteBranch, this); 28 | this.createBranch = bind(this.createBranch, this); 29 | this.unprotectBranch = bind(this.unprotectBranch, this); 30 | this.protectBranch = bind(this.protectBranch, this); 31 | this.showBranch = bind(this.showBranch, this); 32 | this.listBranches = bind(this.listBranches, this); 33 | return ProjectRepository.__super__.constructor.apply(this, arguments); 34 | } 35 | 36 | ProjectRepository.prototype.listBranches = function(projectId, fn) { 37 | if (fn == null) { 38 | fn = null; 39 | } 40 | this.debug("Projects::listBranches()"); 41 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches", (function(_this) { 42 | return function(data) { 43 | if (fn) { 44 | return fn(data); 45 | } 46 | }; 47 | })(this)); 48 | }; 49 | 50 | ProjectRepository.prototype.showBranch = function(projectId, branchId, fn) { 51 | if (fn == null) { 52 | fn = null; 53 | } 54 | this.debug("Projects::branch()"); 55 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + (encodeURI(branchId)), (function(_this) { 56 | return function(data) { 57 | if (fn) { 58 | return fn(data); 59 | } 60 | }; 61 | })(this)); 62 | }; 63 | 64 | ProjectRepository.prototype.protectBranch = function(projectId, branchId, params, fn) { 65 | if (params == null) { 66 | params = {}; 67 | } 68 | if (fn == null) { 69 | fn = null; 70 | } 71 | this.debug("Projects::protectBranch()"); 72 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + (encodeURI(branchId)) + "/protect", params, (function(_this) { 73 | return function(data) { 74 | if (fn) { 75 | return fn(data); 76 | } 77 | }; 78 | })(this)); 79 | }; 80 | 81 | ProjectRepository.prototype.unprotectBranch = function(projectId, branchId, fn) { 82 | if (fn == null) { 83 | fn = null; 84 | } 85 | this.debug("Projects::unprotectBranch()"); 86 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + (encodeURI(branchId)) + "/unprotect", null, (function(_this) { 87 | return function(data) { 88 | if (fn) { 89 | return fn(data); 90 | } 91 | }; 92 | })(this)); 93 | }; 94 | 95 | ProjectRepository.prototype.createBranch = function(params, fn) { 96 | if (params == null) { 97 | params = {}; 98 | } 99 | if (fn == null) { 100 | fn = null; 101 | } 102 | this.debug("Projects::createBranch()", params); 103 | return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/branches", params, (function(_this) { 104 | return function(data) { 105 | if (fn) { 106 | return fn(data); 107 | } 108 | }; 109 | })(this)); 110 | }; 111 | 112 | ProjectRepository.prototype.deleteBranch = function(projectId, branchId, fn) { 113 | if (fn == null) { 114 | fn = null; 115 | } 116 | this.debug("Projects::deleteBranch()"); 117 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/repository/branches/" + (encodeURI(branchId)), (function(_this) { 118 | return function(data) { 119 | if (fn) { 120 | return fn(data); 121 | } 122 | }; 123 | })(this)); 124 | }; 125 | 126 | ProjectRepository.prototype.addTag = function(params, fn) { 127 | if (params == null) { 128 | params = {}; 129 | } 130 | if (fn == null) { 131 | fn = null; 132 | } 133 | this.debug("Projects::addTag()"); 134 | return this.post("projects/" + (Utils.parseProjectId(params.id)) + "/repository/tags", params, (function(_this) { 135 | return function(data) { 136 | if (fn) { 137 | return fn(data); 138 | } 139 | }; 140 | })(this)); 141 | }; 142 | 143 | ProjectRepository.prototype.deleteTag = function(projectId, tagName, fn) { 144 | if (fn == null) { 145 | fn = null; 146 | } 147 | this.debug("Projects::deleteTag()"); 148 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/repository/tags/" + (encodeURI(tagName)), (function(_this) { 149 | return function(data) { 150 | if (fn) { 151 | return fn(data); 152 | } 153 | }; 154 | })(this)); 155 | }; 156 | 157 | ProjectRepository.prototype.showTag = function(projectId, tagName, fn) { 158 | if (fn == null) { 159 | fn = null; 160 | } 161 | this.debug("Projects::showTag()"); 162 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/tags/" + (encodeURI(tagName)), (function(_this) { 163 | return function(data) { 164 | if (fn) { 165 | return fn(data); 166 | } 167 | }; 168 | })(this)); 169 | }; 170 | 171 | ProjectRepository.prototype.listTags = function(projectId, fn) { 172 | if (fn == null) { 173 | fn = null; 174 | } 175 | this.debug("Projects::listTags()"); 176 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/tags", (function(_this) { 177 | return function(data) { 178 | if (fn) { 179 | return fn(data); 180 | } 181 | }; 182 | })(this)); 183 | }; 184 | 185 | ProjectRepository.prototype.listCommits = function(projectId, fn) { 186 | if (fn == null) { 187 | fn = null; 188 | } 189 | this.debug("Projects::listCommits()"); 190 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/commits", (function(_this) { 191 | return function(data) { 192 | if (fn) { 193 | return fn(data); 194 | } 195 | }; 196 | })(this)); 197 | }; 198 | 199 | ProjectRepository.prototype.showCommit = function(projectId, sha, fn) { 200 | if (fn == null) { 201 | fn = null; 202 | } 203 | this.debug("Projects::commit()"); 204 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/commits/" + sha, (function(_this) { 205 | return function(data) { 206 | if (fn) { 207 | return fn(data); 208 | } 209 | }; 210 | })(this)); 211 | }; 212 | 213 | ProjectRepository.prototype.diffCommit = function(projectId, sha, fn) { 214 | if (fn == null) { 215 | fn = null; 216 | } 217 | this.debug("Projects::diffCommit()"); 218 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/commits/" + sha + "/diff", (function(_this) { 219 | return function(data) { 220 | if (fn) { 221 | return fn(data); 222 | } 223 | }; 224 | })(this)); 225 | }; 226 | 227 | ProjectRepository.prototype.listTree = function(projectId, params, fn) { 228 | if (params == null) { 229 | params = {}; 230 | } 231 | if (fn == null) { 232 | fn = null; 233 | } 234 | this.debug("Projects::listTree()"); 235 | if ('function' === typeof params) { 236 | fn = params; 237 | params = {}; 238 | } 239 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/repository/tree", params, (function(_this) { 240 | return function(data) { 241 | if (fn) { 242 | return fn(data); 243 | } 244 | }; 245 | })(this)); 246 | }; 247 | 248 | ProjectRepository.prototype.showFile = function(projectId, params, fn) { 249 | if (params == null) { 250 | params = {}; 251 | } 252 | if (fn == null) { 253 | fn = null; 254 | } 255 | if ('function' === typeof params) { 256 | fn = params; 257 | params = projectId; 258 | } else { 259 | params.projectId = projectId; 260 | } 261 | this.debug("Projects::showFile()", params); 262 | if (params.file_path && params.ref) { 263 | return this.get("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/files", params, (function(_this) { 264 | return function(data) { 265 | if (fn) { 266 | return fn(data); 267 | } 268 | }; 269 | })(this)); 270 | } else if (params.file_path && params.file_id) { 271 | return this.get(("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/raw_blobs/") + params.file_id, params, (function(_this) { 272 | return function(data) { 273 | if (fn) { 274 | return fn(data); 275 | } 276 | }; 277 | })(this)); 278 | } 279 | }; 280 | 281 | ProjectRepository.prototype.createFile = function(params, fn) { 282 | if (params == null) { 283 | params = {}; 284 | } 285 | if (fn == null) { 286 | fn = null; 287 | } 288 | this.debug("Projects::createFile()", params); 289 | return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/files", params, (function(_this) { 290 | return function(data) { 291 | if (fn) { 292 | return fn(data); 293 | } 294 | }; 295 | })(this)); 296 | }; 297 | 298 | ProjectRepository.prototype.updateFile = function(params, fn) { 299 | if (params == null) { 300 | params = {}; 301 | } 302 | if (fn == null) { 303 | fn = null; 304 | } 305 | this.debug("Projects::updateFile()", params); 306 | return this.put("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/files", params, (function(_this) { 307 | return function(data) { 308 | if (fn) { 309 | return fn(data); 310 | } 311 | }; 312 | })(this)); 313 | }; 314 | 315 | ProjectRepository.prototype.compare = function(params, fn) { 316 | if (params == null) { 317 | params = {}; 318 | } 319 | if (fn == null) { 320 | fn = null; 321 | } 322 | this.debug("Projects::compare()", params); 323 | return this.get("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/compare", params, (function(_this) { 324 | return function(data) { 325 | if (fn) { 326 | return fn(data); 327 | } 328 | }; 329 | })(this)); 330 | }; 331 | 332 | return ProjectRepository; 333 | 334 | })(BaseModel); 335 | 336 | module.exports = function(client) { 337 | return new ProjectRepository(client); 338 | }; 339 | 340 | }).call(this); 341 | -------------------------------------------------------------------------------- /lib/Models/ProjectServices.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, ProjectServices, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | ProjectServices = (function(superClass) { 12 | extend(ProjectServices, superClass); 13 | 14 | function ProjectServices() { 15 | this.remove = bind(this.remove, this); 16 | this.update = bind(this.update, this); 17 | this.show = bind(this.show, this); 18 | return ProjectServices.__super__.constructor.apply(this, arguments); 19 | } 20 | 21 | ProjectServices.prototype.show = function(projectId, serviceName, fn) { 22 | if (fn == null) { 23 | fn = null; 24 | } 25 | this.debug("Projects::showService()"); 26 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/services/" + serviceName, (function(_this) { 27 | return function(data) { 28 | if (fn) { 29 | return fn(data); 30 | } 31 | }; 32 | })(this)); 33 | }; 34 | 35 | ProjectServices.prototype.update = function(projectId, serviceName, params, fn) { 36 | if (fn == null) { 37 | fn = null; 38 | } 39 | this.debug("Projects::updateService()"); 40 | return this.put("projects/" + (Utils.parseProjectId(projectId)) + "/services/" + serviceName, params, (function(_this) { 41 | return function(data) { 42 | if (fn) { 43 | return fn(data); 44 | } 45 | }; 46 | })(this)); 47 | }; 48 | 49 | ProjectServices.prototype.remove = function(projectId, serviceName, fn) { 50 | if (fn == null) { 51 | fn = null; 52 | } 53 | this.debug("Projects:removeService()"); 54 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/services/" + serviceName, (function(_this) { 55 | return function(data) { 56 | if (fn) { 57 | return fn(data); 58 | } 59 | }; 60 | })(this)); 61 | }; 62 | 63 | return ProjectServices; 64 | 65 | })(BaseModel); 66 | 67 | module.exports = function(client) { 68 | return new ProjectServices(client); 69 | }; 70 | 71 | }).call(this); 72 | -------------------------------------------------------------------------------- /lib/Models/Projects.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Projects, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | Projects = (function(superClass) { 12 | extend(Projects, superClass); 13 | 14 | function Projects() { 15 | this.removeTrigger = bind(this.removeTrigger, this); 16 | this.createTrigger = bind(this.createTrigger, this); 17 | this.showTrigger = bind(this.showTrigger, this); 18 | this.listTriggers = bind(this.listTriggers, this); 19 | this.search = bind(this.search, this); 20 | this.share = bind(this.share, this); 21 | this.fork = bind(this.fork, this); 22 | this.remove = bind(this.remove, this); 23 | this.listTags = bind(this.listTags, this); 24 | this.listCommits = bind(this.listCommits, this); 25 | this.listMembers = bind(this.listMembers, this); 26 | this.editMember = bind(this.editMember, this); 27 | this.addMember = bind(this.addMember, this); 28 | this.edit = bind(this.edit, this); 29 | this.create_for_user = bind(this.create_for_user, this); 30 | this.create = bind(this.create, this); 31 | this.show = bind(this.show, this); 32 | this.allAdmin = bind(this.allAdmin, this); 33 | this.all = bind(this.all, this); 34 | this.init = bind(this.init, this); 35 | return Projects.__super__.constructor.apply(this, arguments); 36 | } 37 | 38 | Projects.prototype.init = function() { 39 | this.members = this.load('ProjectMembers'); 40 | this.hooks = this.load('ProjectHooks'); 41 | this.issues = this.load('ProjectIssues'); 42 | this.labels = this.load('ProjectLabels'); 43 | this.repository = this.load('ProjectRepository'); 44 | this.milestones = this.load('ProjectMilestones'); 45 | this.deploy_keys = this.load('ProjectDeployKeys'); 46 | this.merge_requests = this.load('ProjectMergeRequests'); 47 | this.services = this.load('ProjectServices'); 48 | this.builds = this.load('ProjectBuilds'); 49 | this.pipelines = this.load('Pipelines'); 50 | return this.runners = this.load('Runners'); 51 | }; 52 | 53 | Projects.prototype.all = function(params, fn) { 54 | var cb, data; 55 | if (params == null) { 56 | params = {}; 57 | } 58 | if (fn == null) { 59 | fn = null; 60 | } 61 | if ('function' === typeof params) { 62 | fn = params; 63 | params = {}; 64 | } 65 | this.debug("Projects::all()"); 66 | if (params.page == null) { 67 | params.page = 1; 68 | } 69 | if (params.per_page == null) { 70 | params.per_page = 100; 71 | } 72 | data = []; 73 | cb = (function(_this) { 74 | return function(err, retData) { 75 | if (err) { 76 | if (fn) { 77 | return fn(retData || data); 78 | } 79 | } else if (retData.length === params.per_page) { 80 | _this.debug("Recurse Projects::all()"); 81 | data = data.concat(retData); 82 | params.page++; 83 | return _this.get("projects", params, cb); 84 | } else { 85 | data = data.concat(retData); 86 | if (fn) { 87 | return fn(data); 88 | } 89 | } 90 | }; 91 | })(this); 92 | return this.get("projects", params, cb); 93 | }; 94 | 95 | Projects.prototype.allAdmin = function(params, fn) { 96 | var cb, data; 97 | if (params == null) { 98 | params = {}; 99 | } 100 | if (fn == null) { 101 | fn = null; 102 | } 103 | if ('function' === typeof params) { 104 | fn = params; 105 | params = {}; 106 | } 107 | this.debug("Projects::allAdmin()"); 108 | if (params.page == null) { 109 | params.page = 1; 110 | } 111 | if (params.per_page == null) { 112 | params.per_page = 100; 113 | } 114 | data = []; 115 | cb = (function(_this) { 116 | return function(err, retData) { 117 | if (err) { 118 | if (fn) { 119 | return fn(retData || data); 120 | } 121 | } else if (retData.length === params.per_page) { 122 | _this.debug("Recurse Projects::allAdmin()"); 123 | data = data.concat(retData); 124 | params.page++; 125 | return _this.get("projects/all", params, cb); 126 | } else { 127 | data = data.concat(retData); 128 | if (fn) { 129 | return fn(data); 130 | } 131 | } 132 | }; 133 | })(this); 134 | return this.get("projects/all", params, cb); 135 | }; 136 | 137 | Projects.prototype.show = function(projectId, fn) { 138 | if (fn == null) { 139 | fn = null; 140 | } 141 | this.debug("Projects::show()"); 142 | return this.get("projects/" + (Utils.parseProjectId(projectId)), (function(_this) { 143 | return function(data) { 144 | if (fn) { 145 | return fn(data); 146 | } 147 | }; 148 | })(this)); 149 | }; 150 | 151 | Projects.prototype.create = function(params, fn) { 152 | if (params == null) { 153 | params = {}; 154 | } 155 | if (fn == null) { 156 | fn = null; 157 | } 158 | this.debug("Projects::create()"); 159 | return this.post("projects", params, function(data) { 160 | if (fn) { 161 | return fn(data); 162 | } 163 | }); 164 | }; 165 | 166 | Projects.prototype.create_for_user = function(params, fn) { 167 | if (params == null) { 168 | params = {}; 169 | } 170 | if (fn == null) { 171 | fn = null; 172 | } 173 | this.debug("Projects::create_for_user()"); 174 | return this.post("projects/user/" + params.user_id, params, function(data) { 175 | if (fn) { 176 | return fn(data); 177 | } 178 | }); 179 | }; 180 | 181 | Projects.prototype.edit = function(projectId, params, fn) { 182 | if (params == null) { 183 | params = {}; 184 | } 185 | if (fn == null) { 186 | fn = null; 187 | } 188 | this.debug("Projects::edit()"); 189 | return this.put("projects/" + (Utils.parseProjectId(projectId)), params, function(data) { 190 | if (fn) { 191 | return fn(data); 192 | } 193 | }); 194 | }; 195 | 196 | Projects.prototype.addMember = function(params, fn) { 197 | if (params == null) { 198 | params = {}; 199 | } 200 | if (fn == null) { 201 | fn = null; 202 | } 203 | this.debug("Projects::addMember()"); 204 | return this.post("projects/" + params.id + "/members", params, function(data) { 205 | if (fn) { 206 | return fn(data); 207 | } 208 | }); 209 | }; 210 | 211 | Projects.prototype.editMember = function(params, fn) { 212 | if (params == null) { 213 | params = {}; 214 | } 215 | if (fn == null) { 216 | fn = null; 217 | } 218 | this.debug("Projects::editMember()"); 219 | return this.put("projects/" + params.id + "/members/" + params.user_id, params, function(data) { 220 | if (fn) { 221 | return fn(data); 222 | } 223 | }); 224 | }; 225 | 226 | Projects.prototype.listMembers = function(params, fn) { 227 | if (params == null) { 228 | params = {}; 229 | } 230 | if (fn == null) { 231 | fn = null; 232 | } 233 | this.debug("Projects::listMembers()"); 234 | return this.get("projects/" + params.id + "/members", function(data) { 235 | if (fn) { 236 | return fn(data); 237 | } 238 | }); 239 | }; 240 | 241 | Projects.prototype.listCommits = function(params, fn) { 242 | if (params == null) { 243 | params = {}; 244 | } 245 | if (fn == null) { 246 | fn = null; 247 | } 248 | this.debug("Projects::listCommits()"); 249 | return this.get("projects/" + params.id + "/repository/commits", params, (function(_this) { 250 | return function(data) { 251 | if (fn) { 252 | return fn(data); 253 | } 254 | }; 255 | })(this)); 256 | }; 257 | 258 | Projects.prototype.listTags = function(params, fn) { 259 | if (params == null) { 260 | params = {}; 261 | } 262 | if (fn == null) { 263 | fn = null; 264 | } 265 | this.debug("Projects::listTags()"); 266 | return this.get("projects/" + params.id + "/repository/tags", (function(_this) { 267 | return function(data) { 268 | if (fn) { 269 | return fn(data); 270 | } 271 | }; 272 | })(this)); 273 | }; 274 | 275 | Projects.prototype.remove = function(projectId, fn) { 276 | if (fn == null) { 277 | fn = null; 278 | } 279 | this.debug("Projects::remove()"); 280 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)), (function(_this) { 281 | return function(data) { 282 | if (fn) { 283 | return fn(data); 284 | } 285 | }; 286 | })(this)); 287 | }; 288 | 289 | Projects.prototype.fork = function(params, fn) { 290 | if (params == null) { 291 | params = {}; 292 | } 293 | if (fn == null) { 294 | fn = null; 295 | } 296 | this.debug("Projects::fork()"); 297 | return this.post("projects/fork/" + params.id, params, function(data) { 298 | if (fn) { 299 | return fn(data); 300 | } 301 | }); 302 | }; 303 | 304 | Projects.prototype.share = function(params, fn) { 305 | if (params == null) { 306 | params = {}; 307 | } 308 | if (fn == null) { 309 | fn = null; 310 | } 311 | this.debug("Projects::share()"); 312 | return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/share", params, function(data) { 313 | if (fn) { 314 | return fn(data); 315 | } 316 | }); 317 | }; 318 | 319 | Projects.prototype.search = function(projectName, params, fn) { 320 | if (params == null) { 321 | params = {}; 322 | } 323 | if (fn == null) { 324 | fn = null; 325 | } 326 | if ('function' === typeof params) { 327 | fn = params; 328 | params = {}; 329 | } 330 | this.debug("Projects::search()"); 331 | return this.get("projects/search/" + projectName, params, (function(_this) { 332 | return function(data) { 333 | if (fn) { 334 | return fn(data); 335 | } 336 | }; 337 | })(this)); 338 | }; 339 | 340 | Projects.prototype.listTriggers = function(projectId, fn) { 341 | if (fn == null) { 342 | fn = null; 343 | } 344 | this.debug("Projects::listTriggers()"); 345 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/triggers", (function(_this) { 346 | return function(data) { 347 | if (fn) { 348 | return fn(data); 349 | } 350 | }; 351 | })(this)); 352 | }; 353 | 354 | Projects.prototype.showTrigger = function(projectId, token, fn) { 355 | if (fn == null) { 356 | fn = null; 357 | } 358 | this.debug("Projects::showTrigger()"); 359 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/triggers/" + token, (function(_this) { 360 | return function(data) { 361 | if (fn) { 362 | return fn(data); 363 | } 364 | }; 365 | })(this)); 366 | }; 367 | 368 | Projects.prototype.createTrigger = function(params, fn) { 369 | if (params == null) { 370 | params = {}; 371 | } 372 | if (fn == null) { 373 | fn = null; 374 | } 375 | this.debug("Projects::createTrigger()"); 376 | return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/triggers", params, function(data) { 377 | if (fn) { 378 | return fn(data); 379 | } 380 | }); 381 | }; 382 | 383 | Projects.prototype.removeTrigger = function(projectId, token, fn) { 384 | if (fn == null) { 385 | fn = null; 386 | } 387 | this.debug("Projects::removeTrigger()"); 388 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/triggers/" + token, (function(_this) { 389 | return function(data) { 390 | if (fn) { 391 | return fn(data); 392 | } 393 | }; 394 | })(this)); 395 | }; 396 | 397 | return Projects; 398 | 399 | })(BaseModel); 400 | 401 | module.exports = function(client) { 402 | return new Projects(client); 403 | }; 404 | 405 | }).call(this); 406 | -------------------------------------------------------------------------------- /lib/Models/Runners.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Runners, Utils, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Utils = require('../Utils'); 10 | 11 | Runners = (function(superClass) { 12 | extend(Runners, superClass); 13 | 14 | function Runners() { 15 | this.disable = bind(this.disable, this); 16 | this.enable = bind(this.enable, this); 17 | this.remove = bind(this.remove, this); 18 | this.update = bind(this.update, this); 19 | this.show = bind(this.show, this); 20 | this.all = bind(this.all, this); 21 | return Runners.__super__.constructor.apply(this, arguments); 22 | } 23 | 24 | Runners.prototype.all = function(projectId, params, fn) { 25 | if (params == null) { 26 | params = {}; 27 | } 28 | if (fn == null) { 29 | fn = null; 30 | } 31 | if ('function' === typeof params) { 32 | fn = params; 33 | params = {}; 34 | } 35 | this.debug("Projects::Runners::all()"); 36 | if (projectId != null) { 37 | return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/runners", params, (function(_this) { 38 | return function(data) { 39 | if (fn) { 40 | return fn(data); 41 | } 42 | }; 43 | })(this)); 44 | } else { 45 | return this.get("runners", params, (function(_this) { 46 | return function(data) { 47 | if (fn) { 48 | return fn(data); 49 | } 50 | }; 51 | })(this)); 52 | } 53 | }; 54 | 55 | Runners.prototype.show = function(runnerId, fn) { 56 | if (fn == null) { 57 | fn = null; 58 | } 59 | this.debug("Projects::Runners::show()"); 60 | return this.get("runners/" + (parseInt(runnerId)), (function(_this) { 61 | return function(data) { 62 | if (fn) { 63 | return fn(data); 64 | } 65 | }; 66 | })(this)); 67 | }; 68 | 69 | Runners.prototype.update = function(runnerId, attributes, fn) { 70 | if (fn == null) { 71 | fn = null; 72 | } 73 | this.debug("Projects::Runners::update"); 74 | return this.put("runners/" + (parseInt(runnerId)), attributes, (function(_this) { 75 | return function(data) { 76 | if (fn) { 77 | return fn(data); 78 | } 79 | }; 80 | })(this)); 81 | }; 82 | 83 | Runners.prototype.remove = function(runnerId, projectId, enable, fn) { 84 | if (fn == null) { 85 | fn = null; 86 | } 87 | this.debug("Projects::Runners::runners()"); 88 | return this["delete"]("runners/" + (parseInt(runnerId)), (function(_this) { 89 | return function(data) { 90 | if (fn) { 91 | return fn(data); 92 | } 93 | }; 94 | })(this)); 95 | }; 96 | 97 | Runners.prototype.enable = function(projectId, runnerId, fn) { 98 | if (fn == null) { 99 | fn = null; 100 | } 101 | this.debug("Projects::Runners::enable()"); 102 | ({ 103 | attributes: { 104 | runner_id: parseInt(runnerId) 105 | } 106 | }); 107 | return this.post("projects/" + (Utils.parseProjectId(projectId)) + "/runners", attributes, function(data) { 108 | if (fn) { 109 | return fn(data); 110 | } 111 | }); 112 | }; 113 | 114 | Runners.prototype.disable = function(projectId, runnerId, fn) { 115 | if (fn == null) { 116 | fn = null; 117 | } 118 | this.debug("Projects::Runners::disable()"); 119 | return this["delete"]("projects/" + (Utils.parseProjectId(projectId)) + "/runners/" + (parseInt(runnerId)), function(data) { 120 | if (fn) { 121 | return fn(data); 122 | } 123 | }); 124 | }; 125 | 126 | return Runners; 127 | 128 | })(BaseModel); 129 | 130 | module.exports = function(client) { 131 | return new Runners(client); 132 | }; 133 | 134 | }).call(this); 135 | -------------------------------------------------------------------------------- /lib/Models/UserKeys.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, UserKeys, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | UserKeys = (function(superClass) { 10 | extend(UserKeys, superClass); 11 | 12 | function UserKeys() { 13 | this.addKey = bind(this.addKey, this); 14 | this.all = bind(this.all, this); 15 | return UserKeys.__super__.constructor.apply(this, arguments); 16 | } 17 | 18 | UserKeys.prototype.all = function(userId, fn) { 19 | if (fn == null) { 20 | fn = null; 21 | } 22 | return this.get("users/" + (parseInt(userId)) + "/keys", (function(_this) { 23 | return function(data) { 24 | if (fn) { 25 | return fn(data); 26 | } 27 | }; 28 | })(this)); 29 | }; 30 | 31 | UserKeys.prototype.addKey = function(userId, title, key, fn) { 32 | var params; 33 | if (fn == null) { 34 | fn = null; 35 | } 36 | params = { 37 | title: title, 38 | key: key 39 | }; 40 | return this.post("users/" + userId + "/keys", params, function(data) { 41 | if (fn) { 42 | return fn(data); 43 | } 44 | }); 45 | }; 46 | 47 | return UserKeys; 48 | 49 | })(BaseModel); 50 | 51 | module.exports = function(client) { 52 | return new UserKeys(client); 53 | }; 54 | 55 | }).call(this); 56 | -------------------------------------------------------------------------------- /lib/Models/Users.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var BaseModel, Users, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 4 | 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; }, 5 | hasProp = {}.hasOwnProperty; 6 | 7 | BaseModel = require('../BaseModel'); 8 | 9 | Users = (function(superClass) { 10 | extend(Users, superClass); 11 | 12 | function Users() { 13 | this.search = bind(this.search, this); 14 | this.session = bind(this.session, this); 15 | this.create = bind(this.create, this); 16 | this.show = bind(this.show, this); 17 | this.current = bind(this.current, this); 18 | this.all = bind(this.all, this); 19 | this.init = bind(this.init, this); 20 | return Users.__super__.constructor.apply(this, arguments); 21 | } 22 | 23 | Users.prototype.init = function() { 24 | return this.keys = this.load('UserKeys'); 25 | }; 26 | 27 | Users.prototype.all = function(params, fn) { 28 | var cb, data; 29 | if (params == null) { 30 | params = {}; 31 | } 32 | if (fn == null) { 33 | fn = null; 34 | } 35 | if ('function' === typeof params) { 36 | fn = params; 37 | params = {}; 38 | } 39 | this.debug("Users::all()"); 40 | if (params.page == null) { 41 | params.page = 1; 42 | } 43 | if (params.per_page == null) { 44 | params.per_page = 100; 45 | } 46 | data = []; 47 | cb = (function(_this) { 48 | return function(err, retData) { 49 | if (err) { 50 | if (fn) { 51 | return fn(retData || data); 52 | } 53 | } else if (retData.length === params.per_page) { 54 | _this.debug("Recurse Users::all()"); 55 | data = data.concat(retData); 56 | params.page++; 57 | return _this.get("users", params, cb); 58 | } else { 59 | data = data.concat(retData); 60 | if (fn) { 61 | return fn(data); 62 | } 63 | } 64 | }; 65 | })(this); 66 | return this.get("users", params, cb); 67 | }; 68 | 69 | Users.prototype.current = function(fn) { 70 | if (fn == null) { 71 | fn = null; 72 | } 73 | this.debug("Users::current()"); 74 | return this.get("user", function(data) { 75 | if (fn) { 76 | return fn(data); 77 | } 78 | }); 79 | }; 80 | 81 | Users.prototype.show = function(userId, fn) { 82 | if (fn == null) { 83 | fn = null; 84 | } 85 | this.debug("Users::show()"); 86 | return this.get("users/" + (parseInt(userId)), (function(_this) { 87 | return function(data) { 88 | if (fn) { 89 | return fn(data); 90 | } 91 | }; 92 | })(this)); 93 | }; 94 | 95 | Users.prototype.create = function(params, fn) { 96 | if (params == null) { 97 | params = {}; 98 | } 99 | if (fn == null) { 100 | fn = null; 101 | } 102 | this.debug("Users::create()", params); 103 | return this.post("users", params, function(data) { 104 | if (fn) { 105 | return fn(data); 106 | } 107 | }); 108 | }; 109 | 110 | Users.prototype.session = function(email, password, fn) { 111 | var params; 112 | if (fn == null) { 113 | fn = null; 114 | } 115 | this.debug("Users::session()"); 116 | params = { 117 | email: email, 118 | password: password 119 | }; 120 | return this.post("session", params, function(data) { 121 | if (fn) { 122 | return fn(data); 123 | } 124 | }); 125 | }; 126 | 127 | Users.prototype.search = function(emailOrUsername, fn) { 128 | var params; 129 | if (fn == null) { 130 | fn = null; 131 | } 132 | this.debug("Users::search(" + emailOrUsername + ")"); 133 | params = { 134 | search: emailOrUsername 135 | }; 136 | return this.get("users", params, function(data) { 137 | if (fn) { 138 | return fn(data); 139 | } 140 | }); 141 | }; 142 | 143 | return Users; 144 | 145 | })(BaseModel); 146 | 147 | module.exports = function(client) { 148 | return new Users(client); 149 | }; 150 | 151 | }).call(this); 152 | -------------------------------------------------------------------------------- /lib/Utils.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Utils; 3 | 4 | Utils = (function() { 5 | function Utils() {} 6 | 7 | Utils.parseProjectId = function(projectId) { 8 | if (typeof projectId === "number") { 9 | return projectId; 10 | } else if (projectId.indexOf("/") !== -1) { 11 | return projectId = encodeURIComponent(projectId); 12 | } else { 13 | return projectId = parseInt(projectId); 14 | } 15 | }; 16 | 17 | return Utils; 18 | 19 | })(); 20 | 21 | module.exports = Utils; 22 | 23 | }).call(this); 24 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var ApiV3; 3 | 4 | ApiV3 = require('./ApiV3').ApiV3; 5 | 6 | module.exports = function(options) { 7 | return new ApiV3(options); 8 | }; 9 | 10 | module.exports.ApiV3 = ApiV3; 11 | 12 | }).call(this); 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitlab", 3 | "version": "1.8.0", 4 | "description": "GitLab API Nodejs library.", 5 | "main": "lib/index.js", 6 | "directories": { 7 | "example": "examples", 8 | "test": "test" 9 | }, 10 | "scripts": { 11 | "test": "./node_modules/.bin/mocha tests", 12 | "build": "./node_modules/.bin/cake build" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/node-gitlab/node-gitlab" 17 | }, 18 | "dependencies": { 19 | "debug": "*", 20 | "slumber": "0.9.0" 21 | }, 22 | "devDependencies": { 23 | "coffee-script": ">=1.9.1", 24 | "mocha": "", 25 | "proxyquire": "~1.0.1", 26 | "chai": "~1.9.2", 27 | "sinon": "~1.10.3", 28 | "sinon-chai": "~2.6.0" 29 | }, 30 | "keywords": [ 31 | "gitlab", 32 | "git", 33 | "api", 34 | "request" 35 | ], 36 | "author": "Manfred Touron ", 37 | "contributors": [ 38 | { 39 | "name": "Dave Irvine", 40 | "url": "https://github.com/dave-irvine" 41 | }, 42 | { 43 | "name": "Glavin Wiechert", 44 | "url": "https://github.com/Glavin001" 45 | }, 46 | { 47 | "name": "Florian Quiblier", 48 | "url": "https://github.com/fofoy" 49 | }, 50 | { 51 | "name": "Anthony Heber", 52 | "url": "https://github.com/aheber" 53 | }, 54 | { 55 | "name": "Evan Heidtmann", 56 | "url": "https://github.com/ezheidtmann" 57 | }, 58 | { 59 | "name": "luoqpolyvi", 60 | "url": "https://github.com/luoqpolyvi" 61 | }, 62 | { 63 | "name": "Brian Vanderbusch", 64 | "url": "https://github.com/LongLiveCHIEF" 65 | }, 66 | { 67 | "name": "daprahamian", 68 | "url": "https://github.com/daprahamian" 69 | }, 70 | { 71 | "name": "pgorecki", 72 | "url": "https://github.com/pgorecki" 73 | }, 74 | { 75 | "name": "CaoJun", 76 | "url": "https://github.com/mdsb100" 77 | }, 78 | { 79 | "name": "nalabjp", 80 | "url": "https://github.com/nalabjp" 81 | }, 82 | { 83 | "name": "shaoshuai0102", 84 | "url": "https://github.com/shaoshuai0102" 85 | }, 86 | { 87 | "name": "Sakesan Panjamawat", 88 | "url": "https://github.com/sakp" 89 | } 90 | ], 91 | "license": "MIT", 92 | "readmeFilename": "README.md" 93 | } 94 | -------------------------------------------------------------------------------- /src/ApiBase.coffee: -------------------------------------------------------------------------------- 1 | debug = require('debug') 'gitlab:ApiBase' 2 | 3 | class module.exports.ApiBase 4 | constructor: (@options) -> 5 | do @handleOptions 6 | do @init 7 | debug "constructor()" 8 | 9 | handleOptions: => 10 | @options.verbose ?= false 11 | debug "handleOptions()" 12 | 13 | init: => 14 | @client = @ 15 | debug "init()" 16 | @groups = require('./Models/Groups') @client 17 | @projects = require('./Models/Projects') @client 18 | @issues = require('./Models/Issues') @client 19 | @notes = require('./Models/Notes') @client 20 | #@repositories = require('./Models/Repositories') @client 21 | @users = require('./Models/Users') @client 22 | #@mergeRequests = require('./Models/MergeRequests') @client 23 | @labels = require('./Models/Labels') @client 24 | -------------------------------------------------------------------------------- /src/ApiBaseHTTP.coffee: -------------------------------------------------------------------------------- 1 | debug = require('debug') 'gitlab:ApiBaseHTTP' 2 | {ApiBase} = require './ApiBase' 3 | querystring = require 'querystring' 4 | slumber = require 'slumber' 5 | 6 | 7 | class module.exports.ApiBaseHTTP extends ApiBase 8 | handleOptions: => 9 | super 10 | @options.base_url ?= '' 11 | 12 | unless @options.url 13 | throw "`url` is mandatory" 14 | 15 | unless @options.token or @options.oauth_token 16 | throw "`private_token` or `oauth_token` is mandatory" 17 | 18 | @options.slumber ?= {} 19 | @options.slumber.append_slash ?= false 20 | 21 | @options.url = @options.url.replace(/\/api\/v3/, '') 22 | 23 | if @options.auth? 24 | @options.slumber.auth = @options.auth 25 | 26 | debug "handleOptions()" 27 | 28 | init: => 29 | super 30 | api = slumber.API @options.url, @options.slumber 31 | @slumber = api(@options.base_url) 32 | 33 | prepare_opts: (opts) => 34 | opts.__query ?= {} 35 | if @options.token 36 | opts.headers = { 'PRIVATE-TOKEN': @options.token } 37 | else 38 | opts.headers = { 'Authorization': 'Bearer ' + @options.oauth_token } 39 | return opts 40 | 41 | fn_wrapper: (fn) => 42 | return (err, response, ret) => 43 | arity = fn.length 44 | switch arity 45 | when 1 then fn ret 46 | when 2 47 | if typeof response.body == 'object' 48 | fn err, ret || response.body.message 49 | else 50 | fn err, ret || JSON.parse(response.body).message 51 | when 3 then fn err, response, ret 52 | 53 | get: (path, query={}, fn=null) => 54 | if 'function' is typeof query 55 | fn = query 56 | query = {} 57 | opts = @prepare_opts query 58 | @slumber(path).get opts, @fn_wrapper fn 59 | 60 | delete: (path, fn=null) => 61 | opts = @prepare_opts {} 62 | @slumber(path).delete opts, @fn_wrapper fn 63 | 64 | post: (path, data={}, fn=null) => 65 | opts = @prepare_opts data 66 | @slumber(path).post opts, @fn_wrapper fn 67 | 68 | put: (path, data={}, fn=null) => 69 | opts = @prepare_opts data 70 | @slumber(path).put opts, @fn_wrapper fn 71 | 72 | patch: (path, data={}, fn=null) => 73 | opts = @prepare_opts data 74 | @slumber(path).patch opts, @fn_wrapper fn 75 | -------------------------------------------------------------------------------- /src/ApiV3.coffee: -------------------------------------------------------------------------------- 1 | debug = require('debug') 'gitlab:ApiV3' 2 | {ApiBaseHTTP} = require './ApiBaseHTTP' 3 | 4 | class module.exports.ApiV3 extends ApiBaseHTTP 5 | handleOptions: => 6 | super 7 | @options.base_url = 'api/v3' 8 | debug "handleOptions()" 9 | -------------------------------------------------------------------------------- /src/BaseModel.coffee: -------------------------------------------------------------------------------- 1 | debug = require('debug') 'gitlab:BaseModel' 2 | 3 | 4 | class module.exports 5 | constructor: (@client) -> 6 | do @_init 7 | 8 | load: (model) => 9 | require("./Models/#{model}") @client 10 | 11 | _init: => 12 | @debug = require('debug') "gitlab:Models:#{@constructor.name}" 13 | 14 | @get = @client.get 15 | @post = @client.post 16 | @put = @client.put 17 | @delete = @client.delete 18 | 19 | do @init if @init? 20 | -------------------------------------------------------------------------------- /src/Models/Groups.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | 3 | class Groups extends BaseModel 4 | init: => 5 | @access_levels = 6 | GUEST: 10 7 | REPORTER: 20 8 | DEVELOPER: 30 9 | MASTER: 40 10 | OWNER: 50 11 | 12 | all: (params = {}, fn = null) => 13 | if 'function' is typeof params 14 | fn = params 15 | params = {} 16 | @debug "Groups::all()" 17 | 18 | params.page ?= 1 19 | params.per_page ?= 100 20 | 21 | data = [] 22 | cb = (err, retData) => 23 | if err 24 | return fn(retData || data) if fn 25 | else if retData.length == params.per_page 26 | @debug "Recurse Groups::all()" 27 | data = data.concat(retData) 28 | params.page++ 29 | return @get "groups", params, cb 30 | else 31 | data = data.concat(retData) 32 | return fn data if fn 33 | 34 | @get "groups", params, cb 35 | 36 | show: (groupId, fn = null) => 37 | @debug "Groups::show()" 38 | @get "groups/#{parseInt groupId}", (data) => fn data if fn 39 | 40 | listProjects: (groupId, fn = null) => 41 | @debug "Groups::listProjects()" 42 | @get "groups/#{parseInt groupId}", (data) => fn data.projects if fn 43 | 44 | listMembers: (groupId, fn = null) => 45 | @debug "Groups::listMembers()" 46 | @get "groups/#{parseInt groupId}/members", (data) => fn data if fn 47 | 48 | addMember: (groupId, userId, accessLevel, fn=null) => 49 | @debug "addMember(#{groupId}, #{userId}, #{accessLevel})" 50 | 51 | checkAccessLevel = => 52 | for k, access_level of @access_levels 53 | return true if accessLevel == access_level 54 | false 55 | 56 | unless do checkAccessLevel 57 | throw "`accessLevel` must be one of #{JSON.stringify @access_levels}" 58 | 59 | params = 60 | user_id: userId 61 | access_level: accessLevel 62 | 63 | @post "groups/#{parseInt groupId}/members", params, (data) -> fn data if fn 64 | 65 | editMember: (groupId, userId, accessLevel, fn = null) => 66 | @debug "Groups::editMember(#{groupId}, #{userId}, #{accessLevel})" 67 | 68 | checkAccessLevel = => 69 | for k, access_level of @access_levels 70 | return true if accessLevel == access_level 71 | false 72 | 73 | unless do checkAccessLevel 74 | throw "`accessLevel` must be one of #{JSON.stringify @access_levels}" 75 | 76 | params = 77 | access_level: accessLevel 78 | 79 | @put "groups/#{parseInt groupId}/members/#{parseInt userId}", params, (data) -> fn data if fn 80 | 81 | removeMember: (groupId, userId, fn = null) => 82 | @debug "Groups::removeMember(#{groupId}, #{userId})" 83 | @delete "groups/#{parseInt groupId}/members/#{parseInt userId}", (data) -> fn data if fn 84 | 85 | create: (params = {}, fn = null) => 86 | @debug "Groups::create()" 87 | @post "groups", params, (data) -> fn data if fn 88 | 89 | addProject: (groupId, projectId, fn = null) => 90 | @debug "Groups::addProject(#{groupId}, #{projectId})" 91 | @post "groups/#{parseInt groupId}/projects/#{parseInt projectId}", null, (data) -> fn data if fn 92 | 93 | deleteGroup: (groupId, fn = null) => 94 | @debug "Groups::delete(#{groupId})" 95 | @delete "groups/#{parseInt groupId}", (data) -> fn data if fn 96 | 97 | search: (nameOrPath, fn = null) => 98 | @debug "Groups::search(#{nameOrPath})" 99 | params = 100 | search: nameOrPath 101 | @get "groups", params, (data) -> fn data if fn 102 | 103 | module.exports = (client) -> new Groups client 104 | -------------------------------------------------------------------------------- /src/Models/IssueNotes.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class IssueNotes extends BaseModel 5 | all: (projectId, issueId, params = {}, fn = null) => 6 | @debug "IssueNotes::notes()" 7 | 8 | if 'function' is typeof params 9 | fn = params 10 | params = {} 11 | params.page ?= 1 12 | params.per_page ?= 100 13 | 14 | data = [] 15 | cb = (err, retData) => 16 | if err 17 | return fn data if fn 18 | else if retData.length == params.per_page 19 | @debug "Recurse IssueNotes::all()" 20 | data = data.concat(retData) 21 | params.page++ 22 | return @get "projects/#{Utils.parseProjectId projectId}/issues/#{parseInt issueId}/notes", params, cb 23 | else 24 | data = data.concat(retData) 25 | return fn data if fn 26 | 27 | @get "projects/#{Utils.parseProjectId projectId}/issues/#{parseInt issueId}/notes", params, cb 28 | 29 | module.exports = (client) -> new IssueNotes client 30 | -------------------------------------------------------------------------------- /src/Models/Issues.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | 3 | class Issues extends BaseModel 4 | all: (params = {}, fn = null) => 5 | if 'function' is typeof params 6 | fn = params 7 | params = {} 8 | @debug "Issues::all()" 9 | params.page ?= 1 10 | params.per_page ?= 100 11 | 12 | do (-> 13 | data = [] 14 | cb = (retData) => 15 | if retData.length == params.per_page 16 | @debug "Recurse Issues::all()" 17 | data = data.concat(retData) 18 | params.page++ 19 | return @get "issues", params, cb 20 | else 21 | data = data.concat(retData) 22 | fn data if fn 23 | 24 | @get "issues", params, cb 25 | ).bind(@) 26 | 27 | show: (projectId, issueId, fn = null) => 28 | @debug "Issues::show()" 29 | if projectId.toString().indexOf("/") isnt -1 30 | projectId = encodeURIComponent(projectId) 31 | else 32 | projectId = parseInt(projectId) 33 | if issueId.toString().indexOf("/") isnt -1 34 | issueId = encodeURIComponent(issueId) 35 | else 36 | issueId = parseInt(issueId) 37 | @get "projects/#{projectId}/issues/#{issueId}", (data) => fn data if fn 38 | 39 | create: (projectId, params = {}, fn = null) => 40 | @debug "Issues::create()" 41 | if projectId.toString().indexOf("/") isnt -1 42 | projectId = encodeURIComponent(projectId) 43 | else 44 | projectId = parseInt(projectId) 45 | 46 | @post "projects/#{projectId}/issues", params, (data) -> fn data if fn 47 | 48 | edit: (projectId, issueId, params = {}, fn = null) => 49 | @debug "Issues::edit()" 50 | if projectId.toString().indexOf("/") isnt -1 51 | projectId = encodeURIComponent(projectId) 52 | else 53 | projectId = parseInt(projectId) 54 | 55 | if issueId.toString().indexOf("/") isnt -1 56 | issueId = encodeURIComponent(issueId) 57 | else 58 | issueId = parseInt(issueId) 59 | 60 | @put "projects/#{projectId}/issues/#{issueId}", params, (data) -> fn data if fn 61 | 62 | remove: (projectId, issueId, fn = null) => 63 | @debug "Issues::remove()" 64 | if projectId.toString().indexOf("/") isnt -1 65 | projectId = encodeURIComponent(projectId) 66 | else 67 | projectId = parseInt(projectId) 68 | 69 | if issueId.toString().indexOf("/") isnt -1 70 | issueId = encodeURIComponent(issueId) 71 | else 72 | issueId = parseInt(issueId) 73 | 74 | @delete "projects/#{projectId}/issues/#{issueId}", (data) -> fn data if fn 75 | 76 | subscribe: (projectId, issueId, params = {}, fn = null) => 77 | @debug "Issues::subscribe()" 78 | if projectId.toString().indexOf("/") isnt -1 79 | projectId = encodeURIComponent(projectId) 80 | else 81 | projectId = parseInt(projectId) 82 | 83 | if issueId.toString().indexOf("/") isnt -1 84 | issueId = encodeURIComponent(issueId) 85 | else 86 | issueId = parseInt(issueId) 87 | 88 | @post "projects/#{projectId}/issues/#{issueId}/subscription", (data) -> fn data if fn 89 | 90 | unsubscribe: (projectId, issueId, fn = null) => 91 | @debug "Issues::unsubscribe()" 92 | if projectId.toString().indexOf("/") isnt -1 93 | projectId = encodeURIComponent(projectId) 94 | else 95 | projectId = parseInt(projectId) 96 | 97 | if issueId.toString().indexOf("/") isnt -1 98 | issueId = encodeURIComponent(issueId) 99 | else 100 | issueId = parseInt(issueId) 101 | 102 | @delete "projects/#{projectId}/issues/#{issueId}/subscription", (data) -> fn data if fn 103 | 104 | 105 | module.exports = (client) -> new Issues client 106 | -------------------------------------------------------------------------------- /src/Models/Labels.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class Labels extends BaseModel 5 | 6 | create: (projectId, params = {}, fn = null) => 7 | @debug "Labels::create()" 8 | @post "projects/#{Utils.parseProjectId projectId}/labels", params, (data) -> fn data if fn 9 | 10 | module.exports = (client) -> new Labels client 11 | -------------------------------------------------------------------------------- /src/Models/Notes.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class Notes extends BaseModel 5 | 6 | create: (projectId, issueId, params = {}, fn = null) => 7 | @debug "Notes::create()" 8 | @post "projects/#{Utils.parseProjectId projectId}/issues/#{parseInt issueId}/notes", params, (data) -> fn data if fn 9 | 10 | module.exports = (client) -> new Notes client 11 | -------------------------------------------------------------------------------- /src/Models/Pipelines.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class Pipelines extends BaseModel 5 | all: (projectId, fn = null) => 6 | @debug "Pipelines::all()" 7 | @get "projects/#{Utils.parseProjectId projectId}/pipelines", (data) => fn data if fn 8 | 9 | module.exports = (client) -> new Pipelines client 10 | -------------------------------------------------------------------------------- /src/Models/ProjectBuilds.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectBuilds extends BaseModel 5 | 6 | # === Builds 7 | listBuilds: (projectId, params={}, fn = null) => 8 | if 'function' is typeof params 9 | fn = params 10 | params={} 11 | 12 | params.page ?= 1 13 | params.per_page ?= 100 14 | 15 | @debug "Projects::listBuilds()" 16 | @get "projects/#{Utils.parseProjectId projectId}/builds", params, (data) => fn data if fn 17 | 18 | showBuild: (projectId, buildId, fn = null) => 19 | @debug "Projects::build()" 20 | @get "projects/#{Utils.parseProjectId projectId}/builds/#{buildId}", null, (data) => fn data if fn 21 | 22 | triggerBuild: (params={}, fn = null) => 23 | @debug "Projects::triggerBuild()" 24 | @post "projects/#{Utils.parseProjectId params.projectId}/trigger/builds", params, (data) -> fn data if fn 25 | 26 | module.exports = (client) -> new ProjectBuilds client 27 | -------------------------------------------------------------------------------- /src/Models/ProjectDeployKeys.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectKeys extends BaseModel 5 | 6 | listKeys: (projectId, fn = null) => 7 | @debug "ProjectKeys::listKeys()" 8 | @get "projects/#{Utils.parseProjectId projectId}/keys", (data) => fn data if fn 9 | 10 | getKey: (projectId, keyId, fn = null) => 11 | @debug "ProjectKeys::getKey()" 12 | @get "projects/#{Utils.parseProjectId projectId}/keys/#{parseInt keyId}", (data) => fn data if fn 13 | 14 | addKey: (projectId, params = {}, fn = null) => 15 | @debug "ProjectKeys::addKey()" 16 | @post "projects/#{Utils.parseProjectId projectId}/keys", params, (data) => fn data if fn 17 | 18 | module.exports = (client) -> new ProjectKeys client 19 | -------------------------------------------------------------------------------- /src/Models/ProjectHooks.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectHooks extends BaseModel 5 | list: (projectId, fn = null) => 6 | @debug "Projects::hooks()" 7 | @get "projects/#{Utils.parseProjectId projectId}/hooks", (data) => fn data if fn 8 | 9 | show: (projectId, hookId, fn = null) => 10 | @debug "Projects::hook()" 11 | @get "projects/#{Utils.parseProjectId projectId}/hooks/#{parseInt hookId}", (data) => fn data if fn 12 | 13 | add: (projectId, params, fn = null) => 14 | if 'string' is typeof params 15 | params = 16 | url: params 17 | @debug "Projects::addHook()" 18 | @post "projects/#{Utils.parseProjectId projectId}/hooks", params, (data) => fn data if fn 19 | 20 | update: (projectId, hookId, url, fn = null) => 21 | @debug "Projects::saveHook()" 22 | params = 23 | access_level: parseInt accessLevel 24 | @put "projects/#{Utils.parseProjectId projectId}/hooks/#{parseInt hookId}", params, (data) => fn data if fn 25 | 26 | remove: (projectId, hookId, fn = null) => 27 | @debug "Projects::removeHook()" 28 | @delete "projects/#{Utils.parseProjectId projectId}/hooks/#{parseInt hookId}", (data) => fn data if fn 29 | 30 | module.exports = (client) -> new ProjectHooks client 31 | -------------------------------------------------------------------------------- /src/Models/ProjectIssues.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectIssues extends BaseModel 5 | init: => 6 | @notes = @load 'IssueNotes' 7 | 8 | list: (projectId, params = {}, fn = null) => 9 | @debug "ProjectIssues::issues()" 10 | 11 | if 'function' is typeof params 12 | fn = params 13 | params = {} 14 | params.page ?= 1 15 | params.per_page ?= 100 16 | 17 | do (-> 18 | data = [] 19 | cb = (err, retData) => 20 | if err 21 | return fn data if fn 22 | if retData.length == params.per_page 23 | @debug "Recurse ProjectIssues::list()" 24 | data = data.concat(retData) 25 | params.page++ 26 | return @get "projects/#{Utils.parseProjectId projectId}/issues", params, cb 27 | else 28 | data = data.concat(retData) 29 | return fn data if fn 30 | 31 | @get "projects/#{Utils.parseProjectId projectId}/issues", params, cb 32 | ).bind(@) 33 | 34 | module.exports = (client) -> new ProjectIssues client 35 | -------------------------------------------------------------------------------- /src/Models/ProjectLabels.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectLabels extends BaseModel 5 | all: (projectId, params = {}, fn = null) => 6 | @debug "ProjectLabels::labels()" 7 | 8 | if 'function' is typeof params 9 | fn = params 10 | params = {} 11 | params.page ?= 1 12 | params.per_page ?= 100 13 | 14 | data = [] 15 | cb = (err, retData) => 16 | if err 17 | return fn data if fn 18 | else if retData.length == params.per_page 19 | @debug "Recurse ProjectLabels::all()" 20 | data = data.concat(retData) 21 | params.page++ 22 | return @get "projects/#{Utils.parseProjectId projectId}/labels", params, cb 23 | else 24 | data = data.concat(retData) 25 | return fn data if fn 26 | 27 | @get "projects/#{Utils.parseProjectId projectId}/labels", params, cb 28 | 29 | module.exports = (client) -> new ProjectLabels client 30 | -------------------------------------------------------------------------------- /src/Models/ProjectMembers.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectMembers extends BaseModel 5 | list: (projectId, fn = null) => 6 | @debug "Projects::members()" 7 | @get "projects/#{Utils.parseProjectId projectId}/members", (data) => fn data if fn 8 | 9 | show: (projectId, userId, fn = null) => 10 | @debug "Projects::member()" 11 | @get "projects/#{Utils.parseProjectId projectId}/members/#{parseInt userId}", (data) => fn data if fn 12 | 13 | add: (projectId, userId, accessLevel = 30, fn = null) => 14 | @debug "Projects::addMember()" 15 | params = 16 | user_id: parseInt userId 17 | access_level: parseInt accessLevel 18 | @post "projects/#{Utils.parseProjectId projectId}/members", params, (data) => fn data if fn 19 | 20 | update: (projectId, userId, accessLevel = 30, fn = null) => 21 | @debug "Projects::saveMember()" 22 | params = 23 | access_level: parseInt accessLevel 24 | @put "projects/#{Utils.parseProjectId projectId}/members/#{parseInt userId}", params, (data) => fn data if fn 25 | 26 | remove: (projectId, userId, fn = null) => 27 | @debug "Projects::removeMember()" 28 | @delete "projects/#{Utils.parseProjectId projectId}/members/#{parseInt userId}", (data) => fn data if fn 29 | 30 | module.exports = (client) -> new ProjectMembers client -------------------------------------------------------------------------------- /src/Models/ProjectMergeRequests.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectMergeRequests extends BaseModel 5 | list: (projectId, params={}, fn = null) => 6 | if 'function' is typeof params 7 | fn = params 8 | params={} 9 | 10 | params.page ?= 1 11 | params.per_page ?= 100 12 | 13 | @debug "Projects::mergerequests()" 14 | @get "projects/#{Utils.parseProjectId projectId}/merge_requests", params, (data) => fn data if fn 15 | 16 | show: (projectId, mergerequestId, fn = null) => 17 | @debug "Projects::mergerequest()" 18 | @get "projects/#{Utils.parseProjectId projectId}/merge_request/#{parseInt mergerequestId}", (data) => fn data if fn 19 | 20 | add: (projectId, sourceBranch, targetBranch, assigneeId, title, fn = null) => 21 | @debug "Projects::addMergeRequest()" 22 | params = 23 | id: Utils.parseProjectId projectId 24 | source_branch: sourceBranch 25 | target_branch: targetBranch 26 | title: title 27 | params.assigneeId = parseInt assigneeId unless assigneeId is undefined 28 | @post "projects/#{Utils.parseProjectId projectId}/merge_requests", params, (data) => fn data if fn 29 | 30 | update: (projectId, mergerequestId, params, fn = null) => 31 | @debug "Projects::saveMergeRequest()" 32 | 33 | params.id = Utils.parseProjectId projectId; 34 | params.merge_request_id = parseInt mergerequestId; 35 | 36 | @put "projects/#{Utils.parseProjectId projectId}/merge_request/#{parseInt mergerequestId}", params, (data) => fn data if fn 37 | 38 | comment: (projectId, mergerequestId, note, fn = null) => 39 | @debug "Projects::commentMergeRequest()" 40 | params = 41 | id: Utils.parseProjectId projectId 42 | merge_request_id: parseInt mergerequestId 43 | note: note 44 | @post "projects/#{Utils.parseProjectId projectId}/merge_request/#{parseInt mergerequestId}/comments", params, (data) => fn data if fn 45 | 46 | merge: (projectId, mergerequestId, params, fn = null) => 47 | @debug "Projects::acceptMergeRequest()" 48 | 49 | params.id = Utils.parseProjectId projectId 50 | params.merge_request_id = parseInt mergerequestId 51 | 52 | @put "projects/#{Utils.parseProjectId projectId}/merge_request/#{parseInt mergerequestId}/merge", params, (data) => fn data if fn 53 | 54 | 55 | module.exports = (client) -> new ProjectMergeRequests client 56 | -------------------------------------------------------------------------------- /src/Models/ProjectMilestones.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectMilestones extends BaseModel 5 | list = (projectId, fn = null) -> 6 | console.log 'DEPRECATED: milestone.list. Use milestone.all instead' 7 | @all arguments... 8 | all: (projectId, fn = null) => 9 | @debug "Projects::Milestones::all()" 10 | params = {} 11 | params.page ?= 1 12 | params.per_page ?= 100 13 | 14 | data = [] 15 | cb = (err, retData) => 16 | if err 17 | return fn(retData || data) if fn 18 | else if retData.length == params.per_page 19 | @debug "Recurse Projects::Milestones::all()" 20 | data = data.concat(retData) 21 | params.page++ 22 | return @get "projects/#{Utils.parseProjectId projectId}/milestones", params, cb 23 | else 24 | data = data.concat(retData) 25 | return fn data if fn 26 | 27 | @get "projects/#{Utils.parseProjectId projectId}/milestones", params, cb 28 | 29 | show: (projectId, milestoneId, fn = null) => 30 | @debug "Projects::milestone()" 31 | @get "projects/#{Utils.parseProjectId projectId}/milestones/#{parseInt milestoneId}", (data) => fn data if fn 32 | 33 | add: (projectId, title, description, due_date, fn = null) => 34 | @debug "Projects::addMilestone()" 35 | params = 36 | id: Utils.parseProjectId projectId 37 | title: title 38 | description: description 39 | due_date: due_date 40 | @post "projects/#{Utils.parseProjectId projectId}/milestones", params, (data) => fn data if fn 41 | 42 | update: (projectId, milestoneId, title, description, due_date, state_event, fn = null) => 43 | @debug "Projects::editMilestone()" 44 | params = 45 | id: Utils.parseProjectId projectId 46 | title: title 47 | description: description 48 | due_date: due_date 49 | state_event: state_event 50 | @put "projects/#{Utils.parseProjectId projectId}/milestones/#{parseInt milestoneId}", params, (data) => fn data if fn 51 | 52 | module.exports = (client) -> new ProjectMilestones client 53 | -------------------------------------------------------------------------------- /src/Models/ProjectRepository.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectRepository extends BaseModel 5 | 6 | # === Branches 7 | listBranches: (projectId, fn = null) => 8 | @debug "Projects::listBranches()" 9 | @get "projects/#{Utils.parseProjectId projectId}/repository/branches", (data) => fn data if fn 10 | 11 | showBranch: (projectId, branchId, fn = null) => 12 | @debug "Projects::branch()" 13 | @get "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}", (data) => fn data if fn 14 | 15 | protectBranch: (projectId, branchId, params = {}, fn = null) => 16 | @debug "Projects::protectBranch()" 17 | @put "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}/protect", params, (data) => fn data if fn 18 | 19 | unprotectBranch: (projectId, branchId, fn = null) => 20 | @debug "Projects::unprotectBranch()" 21 | @put "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}/unprotect", null, (data) => fn data if fn 22 | 23 | createBranch: (params = {}, fn = null) => 24 | @debug "Projects::createBranch()", params 25 | @post "projects/#{Utils.parseProjectId params.projectId}/repository/branches", params, (data) => fn data if fn 26 | 27 | deleteBranch: (projectId, branchId, fn = null) => 28 | @debug "Projects::deleteBranch()" 29 | @delete "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}", (data) => fn data if fn 30 | 31 | # === Tags 32 | addTag: (params = {}, fn = null) => 33 | @debug "Projects::addTag()" 34 | @post "projects/#{Utils.parseProjectId params.id}/repository/tags", params, (data) => fn data if fn 35 | 36 | deleteTag: (projectId, tagName, fn = null) => 37 | @debug "Projects::deleteTag()" 38 | @delete "projects/#{Utils.parseProjectId projectId}/repository/tags/#{encodeURI tagName}", (data) => fn data if fn 39 | 40 | showTag: (projectId, tagName, fn = null) => 41 | @debug "Projects::showTag()" 42 | @get "projects/#{Utils.parseProjectId projectId}/repository/tags/#{encodeURI tagName}", (data) => fn data if fn 43 | 44 | listTags: (projectId, fn = null) => 45 | @debug "Projects::listTags()" 46 | @get "projects/#{Utils.parseProjectId projectId}/repository/tags", (data) => fn data if fn 47 | 48 | # === Commits 49 | listCommits: (projectId, fn = null) => 50 | @debug "Projects::listCommits()" 51 | @get "projects/#{Utils.parseProjectId projectId}/repository/commits", (data) => fn data if fn 52 | 53 | showCommit: (projectId, sha, fn = null) => 54 | @debug "Projects::commit()" 55 | @get "projects/#{Utils.parseProjectId projectId}/repository/commits/#{sha}", (data) => fn data if fn 56 | 57 | diffCommit: (projectId, sha, fn = null) => 58 | @debug "Projects::diffCommit()" 59 | @get "projects/#{Utils.parseProjectId projectId}/repository/commits/#{sha}/diff", (data) => fn data if fn 60 | 61 | # === Tree 62 | listTree: (projectId, params = {}, fn = null) => 63 | @debug "Projects::listTree()" 64 | if 'function' is typeof(params) 65 | fn = params 66 | params = {} 67 | @get "projects/#{Utils.parseProjectId projectId}/repository/tree", params, (data) => fn data if fn 68 | 69 | # == Files 70 | showFile: (projectId, params = {}, fn = null) => 71 | if 'function' is typeof params 72 | fn = params 73 | params = projectId 74 | else 75 | params.projectId = projectId 76 | 77 | @debug "Projects::showFile()", params 78 | if params.file_path and params.ref 79 | @get "projects/#{Utils.parseProjectId params.projectId}/repository/files", params, (data) => fn data if fn 80 | else if params.file_path and params.file_id 81 | @get "projects/#{Utils.parseProjectId params.projectId}/repository/raw_blobs/" + params.file_id, params, (data) => fn data if fn 82 | 83 | createFile: (params = {}, fn = null) => 84 | @debug "Projects::createFile()", params 85 | @post "projects/#{Utils.parseProjectId params.projectId}/repository/files", params, (data) => fn data if fn 86 | 87 | updateFile: (params = {}, fn = null) => 88 | @debug "Projects::updateFile()", params 89 | @put "projects/#{Utils.parseProjectId params.projectId}/repository/files", params, (data) => fn data if fn 90 | 91 | compare: (params = {}, fn = null) => 92 | @debug "Projects::compare()", params 93 | @get "projects/#{Utils.parseProjectId params.projectId}/repository/compare", params, (data) => fn data if fn 94 | 95 | ## TODO: 96 | # - Raw file content 97 | # - Raw blob content 98 | # - Get file archive 99 | # - Delete existing file in repository 100 | 101 | module.exports = (client) -> new ProjectRepository client 102 | -------------------------------------------------------------------------------- /src/Models/ProjectServices.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class ProjectServices extends BaseModel 5 | 6 | show: (projectId, serviceName, fn = null) => 7 | @debug "Projects::showService()" 8 | @get "projects/#{Utils.parseProjectId projectId}/services/#{serviceName}", (data) => fn data if fn 9 | 10 | update: (projectId, serviceName, params, fn = null) => 11 | @debug "Projects::updateService()" 12 | @put "projects/#{Utils.parseProjectId projectId}/services/#{serviceName}", params, (data) => fn data if fn 13 | 14 | remove: (projectId, serviceName, fn = null) => 15 | @debug "Projects:removeService()" 16 | @delete "projects/#{Utils.parseProjectId projectId}/services/#{serviceName}", (data) => fn data if fn 17 | 18 | module.exports = (client) -> new ProjectServices client 19 | -------------------------------------------------------------------------------- /src/Models/Projects.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class Projects extends BaseModel 5 | init: => 6 | @members = @load 'ProjectMembers' 7 | @hooks = @load 'ProjectHooks' 8 | @issues = @load 'ProjectIssues' 9 | @labels = @load 'ProjectLabels' 10 | @repository = @load 'ProjectRepository' 11 | @milestones = @load 'ProjectMilestones' 12 | @deploy_keys = @load 'ProjectDeployKeys' 13 | @merge_requests = @load 'ProjectMergeRequests' 14 | @services = @load 'ProjectServices' 15 | @builds = @load 'ProjectBuilds' 16 | @pipelines = @load 'Pipelines' 17 | @runners = @load 'Runners' 18 | 19 | all: (params={}, fn=null) => 20 | if 'function' is typeof params 21 | fn = params 22 | params={} 23 | @debug "Projects::all()" 24 | 25 | params.page ?= 1 26 | params.per_page ?= 100 27 | 28 | data = [] 29 | cb = (err, retData) => 30 | if err 31 | return fn(retData || data) if fn 32 | else if retData.length == params.per_page 33 | @debug "Recurse Projects::all()" 34 | data = data.concat(retData) 35 | params.page++ 36 | return @get "projects", params, cb 37 | else 38 | data = data.concat(retData) 39 | return fn data if fn 40 | 41 | @get "projects", params, cb 42 | 43 | allAdmin: (params={}, fn=null) => 44 | if 'function' is typeof params 45 | fn = params 46 | params={} 47 | @debug "Projects::allAdmin()" 48 | 49 | params.page ?= 1 50 | params.per_page ?= 100 51 | 52 | data = [] 53 | cb = (err, retData) => 54 | if err 55 | return fn(retData || data) if fn 56 | else if retData.length == params.per_page 57 | @debug "Recurse Projects::allAdmin()" 58 | data = data.concat(retData) 59 | params.page++ 60 | return @get "projects/all", params, cb 61 | else 62 | data = data.concat(retData) 63 | return fn data if fn 64 | 65 | @get "projects/all", params, cb 66 | 67 | show: (projectId, fn=null) => 68 | @debug "Projects::show()" 69 | @get "projects/#{Utils.parseProjectId projectId}", (data) => fn data if fn 70 | 71 | create: (params={}, fn=null) => 72 | @debug "Projects::create()" 73 | @post "projects", params, (data) -> fn data if fn 74 | 75 | create_for_user: (params={}, fn=null) => 76 | @debug "Projects::create_for_user()" 77 | @post "projects/user/#{params.user_id}", params, (data) -> fn data if fn 78 | 79 | edit: (projectId, params={}, fn=null) => 80 | @debug "Projects::edit()" 81 | @put "projects/#{Utils.parseProjectId projectId}", params, (data) -> fn data if fn 82 | 83 | addMember: (params={}, fn=null) => 84 | @debug "Projects::addMember()" 85 | @post "projects/#{params.id}/members", params, (data) -> fn data if fn 86 | 87 | editMember: (params={}, fn=null) => 88 | @debug "Projects::editMember()" 89 | @put "projects/#{params.id}/members/#{params.user_id}", params, (data) -> fn data if fn 90 | 91 | listMembers: (params={}, fn=null) => 92 | @debug "Projects::listMembers()" 93 | @get "projects/#{params.id}/members", (data) -> fn data if fn 94 | 95 | listCommits: (params={}, fn=null) => 96 | @debug "Projects::listCommits()" 97 | @get "projects/#{params.id}/repository/commits", params, (data) => fn data if fn 98 | 99 | listTags: (params={}, fn=null) => 100 | @debug "Projects::listTags()" 101 | @get "projects/#{params.id}/repository/tags", (data) => fn data if fn 102 | 103 | remove: (projectId, fn = null) => 104 | @debug "Projects::remove()" 105 | @delete "projects/#{Utils.parseProjectId projectId}", (data) => fn data if fn 106 | 107 | fork: (params={}, fn=null) => 108 | @debug "Projects::fork()" 109 | @post "projects/fork/#{params.id}", params, (data) -> fn data if fn 110 | 111 | share: (params={}, fn=null) => 112 | @debug "Projects::share()" 113 | @post "projects/#{Utils.parseProjectId params.projectId}/share", params, (data) -> fn data if fn 114 | 115 | search: (projectName, params={}, fn=null) => 116 | if 'function' is typeof params 117 | fn = params 118 | params={} 119 | 120 | @debug "Projects::search()" 121 | @get "projects/search/#{projectName}", params, (data) => fn data if fn 122 | 123 | listTriggers: (projectId, fn = null) => 124 | @debug "Projects::listTriggers()" 125 | @get "projects/#{Utils.parseProjectId projectId}/triggers", (data) => fn data if fn 126 | 127 | showTrigger: (projectId, token, fn = null) => 128 | @debug "Projects::showTrigger()" 129 | @get "projects/#{Utils.parseProjectId projectId}/triggers/#{token}", (data) => fn data if fn 130 | 131 | createTrigger: (params={}, fn=null) => 132 | @debug "Projects::createTrigger()" 133 | @post "projects/#{Utils.parseProjectId params.projectId}/triggers", params, (data) -> fn data if fn 134 | 135 | removeTrigger: (projectId, token, fn = null) => 136 | @debug "Projects::removeTrigger()" 137 | @delete "projects/#{Utils.parseProjectId projectId}/triggers/#{token}", (data) => fn data if fn 138 | 139 | module.exports = (client) -> new Projects client 140 | -------------------------------------------------------------------------------- /src/Models/Runners.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | Utils = require '../Utils' 3 | 4 | class Runners extends BaseModel 5 | all: (projectId, params={}, fn = null) => 6 | if 'function' is typeof params 7 | fn = params 8 | params={} 9 | 10 | @debug "Projects::Runners::all()" 11 | 12 | if projectId? 13 | @get "projects/#{Utils.parseProjectId projectId}/runners", params, (data) => fn data if fn 14 | else 15 | @get "runners", params, (data) => fn data if fn 16 | 17 | show: (runnerId, fn = null) => 18 | @debug "Projects::Runners::show()" 19 | @get "runners/#{parseInt runnerId}", (data) => fn data if fn 20 | 21 | update: (runnerId, attributes, fn = null) => 22 | @debug "Projects::Runners::update" 23 | @put "runners/#{parseInt runnerId}", attributes, (data) => fn data if fn 24 | 25 | remove: (runnerId, projectId, enable, fn = null) => 26 | @debug "Projects::Runners::runners()" 27 | @delete "runners/#{parseInt runnerId}", (data) => fn data if fn 28 | 29 | enable: (projectId, runnerId, fn = null) => 30 | @debug "Projects::Runners::enable()" 31 | attributes: 32 | runner_id: parseInt runnerId 33 | @post "projects/#{Utils.parseProjectId projectId}/runners", attributes, (data) -> fn data if fn 34 | 35 | disable: (projectId, runnerId, fn = null) => 36 | @debug "Projects::Runners::disable()" 37 | @delete "projects/#{Utils.parseProjectId projectId}/runners/#{parseInt runnerId}", (data) -> fn data if fn 38 | 39 | module.exports = (client) -> new Runners client 40 | -------------------------------------------------------------------------------- /src/Models/UserKeys.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | 3 | class UserKeys extends BaseModel 4 | all: (userId, fn = null) => 5 | @get "users/#{parseInt userId}/keys", (data) => fn data if fn 6 | 7 | addKey: (userId, title, key, fn = null) => 8 | params = 9 | title: title 10 | key: key 11 | 12 | @post "users/#{userId}/keys", params, (data) -> fn data if fn 13 | 14 | module.exports = (client) -> new UserKeys client 15 | -------------------------------------------------------------------------------- /src/Models/Users.coffee: -------------------------------------------------------------------------------- 1 | BaseModel = require '../BaseModel' 2 | 3 | class Users extends BaseModel 4 | init: => 5 | @keys = @load 'UserKeys' 6 | 7 | all: (params = {}, fn = null) => 8 | if 'function' is typeof params 9 | fn = params 10 | params = {} 11 | @debug "Users::all()" 12 | 13 | params.page ?= 1 14 | params.per_page ?= 100 15 | 16 | data = [] 17 | cb = (err, retData) => 18 | if err 19 | return fn(retData || data) if fn 20 | else if retData.length == params.per_page 21 | @debug "Recurse Users::all()" 22 | data = data.concat(retData) 23 | params.page++ 24 | return @get "users", params, cb 25 | else 26 | data = data.concat(retData) 27 | return fn data if fn 28 | 29 | @get "users", params, cb 30 | 31 | current: (fn = null) => 32 | @debug "Users::current()" 33 | @get "user", (data) -> fn data if fn 34 | 35 | show: (userId, fn = null) => 36 | @debug "Users::show()" 37 | @get "users/#{parseInt userId}", (data) => fn data if fn 38 | 39 | create: (params = {}, fn = null) => 40 | @debug "Users::create()", params 41 | @post "users", params, (data) -> fn data if fn 42 | 43 | session: (email, password, fn = null) => 44 | @debug "Users::session()" 45 | params = 46 | email: email 47 | password: password 48 | @post "session", params, (data) -> fn data if fn 49 | 50 | search: (emailOrUsername, fn = null) => 51 | @debug "Users::search(#{emailOrUsername})" 52 | params = 53 | search: emailOrUsername 54 | @get "users", params, (data) -> fn data if fn 55 | 56 | module.exports = (client) -> new Users client 57 | -------------------------------------------------------------------------------- /src/Utils.coffee: -------------------------------------------------------------------------------- 1 | class Utils 2 | @parseProjectId: (projectId) => 3 | if typeof projectId is "number" 4 | return projectId # Do nothing 5 | else if projectId.indexOf("/") isnt -1 6 | projectId = encodeURIComponent(projectId) 7 | else 8 | projectId = parseInt(projectId) 9 | 10 | module.exports = Utils 11 | -------------------------------------------------------------------------------- /src/index.coffee: -------------------------------------------------------------------------------- 1 | {ApiV3} = require './ApiV3' 2 | module.exports = (options) -> 3 | return new ApiV3(options) 4 | 5 | module.exports.ApiV3 = ApiV3 6 | -------------------------------------------------------------------------------- /tests/ApiBaseHTTP.test.coffee: -------------------------------------------------------------------------------- 1 | chai = require 'chai' 2 | expect = chai.expect 3 | sinon = require 'sinon' 4 | proxyquire = require 'proxyquire' 5 | sinonChai = require 'sinon-chai' 6 | 7 | chai.use sinonChai 8 | 9 | describe "ApiBaseHTTP", -> 10 | ApiBaseHTTP = null 11 | apibasehttp = null 12 | 13 | before -> 14 | ApiBaseHTTP = require('../lib/ApiBaseHTTP').ApiBaseHTTP 15 | 16 | beforeEach -> 17 | 18 | describe "handleOptions()", -> 19 | it "should strip /api/v3 from `url` parameter if provided", -> 20 | apibasehttp = new ApiBaseHTTP 21 | base_url: "api/v3" 22 | url: "http://gitlab.mydomain.com/api/v3" 23 | token: "test" 24 | 25 | expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com") 26 | 27 | it "should not strip /api/v3 from `url` parameter if not provided", -> 28 | apibasehttp = new ApiBaseHTTP 29 | base_url: "api/v3" 30 | url: "http://gitlab.mydomain.com" 31 | token: "test" 32 | 33 | expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com") 34 | -------------------------------------------------------------------------------- /tests/ApiBaseHTTP.test.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var chai, expect, proxyquire, sinon, sinonChai; 3 | 4 | chai = require('chai'); 5 | 6 | expect = chai.expect; 7 | 8 | sinon = require('sinon'); 9 | 10 | proxyquire = require('proxyquire'); 11 | 12 | sinonChai = require('sinon-chai'); 13 | 14 | chai.use(sinonChai); 15 | 16 | describe("ApiBaseHTTP", function() { 17 | var ApiBaseHTTP, apibasehttp; 18 | ApiBaseHTTP = null; 19 | apibasehttp = null; 20 | before(function() { 21 | return ApiBaseHTTP = require('../lib/ApiBaseHTTP').ApiBaseHTTP; 22 | }); 23 | beforeEach(function() {}); 24 | return describe("handleOptions()", function() { 25 | it("should strip /api/v3 from `url` parameter if provided", function() { 26 | apibasehttp = new ApiBaseHTTP({ 27 | base_url: "api/v3", 28 | url: "http://gitlab.mydomain.com/api/v3", 29 | token: "test" 30 | }); 31 | return expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com"); 32 | }); 33 | return it("should not strip /api/v3 from `url` parameter if not provided", function() { 34 | apibasehttp = new ApiBaseHTTP({ 35 | base_url: "api/v3", 36 | url: "http://gitlab.mydomain.com", 37 | token: "test" 38 | }); 39 | return expect(apibasehttp.options.url).to.equal("http://gitlab.mydomain.com"); 40 | }); 41 | }); 42 | }); 43 | 44 | }).call(this); 45 | -------------------------------------------------------------------------------- /tests/ProjectMembers.test.coffee: -------------------------------------------------------------------------------- 1 | chai = require 'chai' 2 | expect = chai.expect 3 | sinon = require 'sinon' 4 | sinonChai = require 'sinon-chai' 5 | 6 | chai.use sinonChai 7 | 8 | describe "ProjectMembers", -> 9 | gitlab = null 10 | projects = null 11 | members = null 12 | 13 | before -> 14 | gitlab = (require '../') 15 | url: 'test' 16 | token: 'test' 17 | 18 | projects = gitlab.projects 19 | members = projects.members 20 | 21 | beforeEach -> 22 | 23 | describe "list()", -> 24 | it "should use GET verb", -> 25 | getStub = sinon.stub members, "get" 26 | 27 | members.list 1 28 | 29 | getStub.restore() 30 | expect(getStub).to.have.been.called 31 | 32 | it "should pass Numeric projectIDs to Utils.parseProjectId", -> 33 | getStub = sinon.stub members, "get" 34 | 35 | members.list 1 36 | 37 | getStub.restore() 38 | expect(getStub).to.have.been.calledWith "projects/1/members" 39 | 40 | it "should pass Namespaced projectIDs to Utils.parseProjectId", -> 41 | getStub = sinon.stub members, "get" 42 | 43 | members.list "abc/def" 44 | 45 | getStub.restore() 46 | expect(getStub).to.have.been.calledWith "projects/abc%2Fdef/members" 47 | 48 | describe "show()", -> 49 | it "should use GET verb", -> 50 | getStub = sinon.stub members, "get" 51 | 52 | members.show 1, 2 53 | 54 | getStub.restore() 55 | expect(getStub).to.have.been.called 56 | 57 | it "should pass Numeric projectIDs to Utils.parseProjectId", -> 58 | getStub = sinon.stub members, "get" 59 | 60 | members.show 1, 2 61 | 62 | getStub.restore() 63 | expect(getStub).to.have.been.calledWith "projects/1/members/2" 64 | 65 | it "should pass Namespaced projectIDs to Utils.parseProjectId", -> 66 | getStub = sinon.stub members, "get" 67 | 68 | members.show "abc/def", 2 69 | 70 | getStub.restore() 71 | expect(getStub).to.have.been.calledWith "projects/abc%2Fdef/members/2" 72 | 73 | describe "add()", -> 74 | it "should use POST verb", -> 75 | postStub = sinon.stub members, "post" 76 | 77 | members.add 1, 1, 30 78 | 79 | postStub.restore() 80 | expect(postStub).to.have.been.called 81 | -------------------------------------------------------------------------------- /tests/ProjectMembers.test.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var chai, expect, sinon, sinonChai; 3 | 4 | chai = require('chai'); 5 | 6 | expect = chai.expect; 7 | 8 | sinon = require('sinon'); 9 | 10 | sinonChai = require('sinon-chai'); 11 | 12 | chai.use(sinonChai); 13 | 14 | describe("ProjectMembers", function() { 15 | var gitlab, members, projects; 16 | gitlab = null; 17 | projects = null; 18 | members = null; 19 | before(function() { 20 | gitlab = (require('../'))({ 21 | url: 'test', 22 | token: 'test' 23 | }); 24 | projects = gitlab.projects; 25 | return members = projects.members; 26 | }); 27 | beforeEach(function() {}); 28 | describe("list()", function() { 29 | it("should use GET verb", function() { 30 | var getStub; 31 | getStub = sinon.stub(members, "get"); 32 | members.list(1); 33 | getStub.restore(); 34 | return expect(getStub).to.have.been.called; 35 | }); 36 | it("should pass Numeric projectIDs to Utils.parseProjectId", function() { 37 | var getStub; 38 | getStub = sinon.stub(members, "get"); 39 | members.list(1); 40 | getStub.restore(); 41 | return expect(getStub).to.have.been.calledWith("projects/1/members"); 42 | }); 43 | return it("should pass Namespaced projectIDs to Utils.parseProjectId", function() { 44 | var getStub; 45 | getStub = sinon.stub(members, "get"); 46 | members.list("abc/def"); 47 | getStub.restore(); 48 | return expect(getStub).to.have.been.calledWith("projects/abc%2Fdef/members"); 49 | }); 50 | }); 51 | describe("show()", function() { 52 | it("should use GET verb", function() { 53 | var getStub; 54 | getStub = sinon.stub(members, "get"); 55 | members.show(1, 2); 56 | getStub.restore(); 57 | return expect(getStub).to.have.been.called; 58 | }); 59 | it("should pass Numeric projectIDs to Utils.parseProjectId", function() { 60 | var getStub; 61 | getStub = sinon.stub(members, "get"); 62 | members.show(1, 2); 63 | getStub.restore(); 64 | return expect(getStub).to.have.been.calledWith("projects/1/members/2"); 65 | }); 66 | return it("should pass Namespaced projectIDs to Utils.parseProjectId", function() { 67 | var getStub; 68 | getStub = sinon.stub(members, "get"); 69 | members.show("abc/def", 2); 70 | getStub.restore(); 71 | return expect(getStub).to.have.been.calledWith("projects/abc%2Fdef/members/2"); 72 | }); 73 | }); 74 | return describe("add()", function() { 75 | return it("should use POST verb", function() { 76 | var postStub; 77 | postStub = sinon.stub(members, "post"); 78 | members.add(1, 1, 30); 79 | postStub.restore(); 80 | return expect(postStub).to.have.been.called; 81 | }); 82 | }); 83 | }); 84 | 85 | }).call(this); 86 | -------------------------------------------------------------------------------- /tests/ProjectRepository.test.coffee: -------------------------------------------------------------------------------- 1 | chai = require 'chai' 2 | expect = chai.expect 3 | sinon = require 'sinon' 4 | sinonChai = require 'sinon-chai' 5 | 6 | chai.use sinonChai 7 | 8 | describe "ProjectRepository", -> 9 | gitlab = null 10 | projects = null 11 | repository = null 12 | 13 | before -> 14 | gitlab = (require '../') 15 | url: 'test' 16 | token: 'test' 17 | 18 | projects = gitlab.projects 19 | repository = projects.repository 20 | 21 | beforeEach -> 22 | 23 | describe "listBranches()", -> 24 | it "should use GET verb", -> 25 | getStub = sinon.stub repository, "get" 26 | 27 | repository.listBranches 1 28 | 29 | getStub.restore() 30 | expect(getStub).to.have.been.called 31 | 32 | describe "listCommits()", -> 33 | it "should use GET verb", -> 34 | getStub = sinon.stub repository, "get" 35 | 36 | repository.listCommits 1 37 | 38 | getStub.restore() 39 | expect(getStub).to.have.been.called 40 | 41 | describe "addTag()", -> 42 | it "should use POST verb", -> 43 | postStub = sinon.stub repository, "post" 44 | 45 | opts = 46 | id: 1, 47 | tag_name: "v1.0.0", 48 | ref: "2695effb5807a22ff3d138d593fd856244e155e7", 49 | message: "Annotated message", 50 | release_description: "Release description" 51 | repository.addTag opts 52 | 53 | postStub.restore() 54 | expect(postStub).to.have.been.called 55 | 56 | describe "listTags()", -> 57 | it "should use GET verb", -> 58 | getStub = sinon.stub repository, "get" 59 | 60 | repository.listTags 1 61 | 62 | getStub.restore() 63 | expect(getStub).to.have.been.called 64 | 65 | describe "listTree()", -> 66 | it "should use GET verb", -> 67 | getStub = sinon.stub repository, "get" 68 | 69 | repository.listTree 1 70 | 71 | getStub.restore() 72 | expect(getStub).to.have.been.called 73 | 74 | describe "showFile()", -> 75 | it "should use GET verb", -> 76 | getStub = sinon.stub repository, "get" 77 | 78 | repository.showFile 1, { 79 | file_path: "test", 80 | ref: "test" 81 | } 82 | 83 | getStub.restore() 84 | expect(getStub).to.have.been.called 85 | -------------------------------------------------------------------------------- /tests/ProjectRepository.test.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var chai, expect, sinon, sinonChai; 3 | 4 | chai = require('chai'); 5 | 6 | expect = chai.expect; 7 | 8 | sinon = require('sinon'); 9 | 10 | sinonChai = require('sinon-chai'); 11 | 12 | chai.use(sinonChai); 13 | 14 | describe("ProjectRepository", function() { 15 | var gitlab, projects, repository; 16 | gitlab = null; 17 | projects = null; 18 | repository = null; 19 | before(function() { 20 | gitlab = (require('../'))({ 21 | url: 'test', 22 | token: 'test' 23 | }); 24 | projects = gitlab.projects; 25 | return repository = projects.repository; 26 | }); 27 | beforeEach(function() {}); 28 | describe("listBranches()", function() { 29 | return it("should use GET verb", function() { 30 | var getStub; 31 | getStub = sinon.stub(repository, "get"); 32 | repository.listBranches(1); 33 | getStub.restore(); 34 | return expect(getStub).to.have.been.called; 35 | }); 36 | }); 37 | describe("listCommits()", function() { 38 | return it("should use GET verb", function() { 39 | var getStub; 40 | getStub = sinon.stub(repository, "get"); 41 | repository.listCommits(1); 42 | getStub.restore(); 43 | return expect(getStub).to.have.been.called; 44 | }); 45 | }); 46 | describe("addTag()", function() { 47 | return it("should use POST verb", function() { 48 | var opts, postStub; 49 | postStub = sinon.stub(repository, "post"); 50 | opts = { 51 | id: 1, 52 | tag_name: "v1.0.0", 53 | ref: "2695effb5807a22ff3d138d593fd856244e155e7", 54 | message: "Annotated message", 55 | release_description: "Release description" 56 | }; 57 | repository.addTag(opts); 58 | postStub.restore(); 59 | return expect(postStub).to.have.been.called; 60 | }); 61 | }); 62 | describe("listTags()", function() { 63 | return it("should use GET verb", function() { 64 | var getStub; 65 | getStub = sinon.stub(repository, "get"); 66 | repository.listTags(1); 67 | getStub.restore(); 68 | return expect(getStub).to.have.been.called; 69 | }); 70 | }); 71 | describe("listTree()", function() { 72 | return it("should use GET verb", function() { 73 | var getStub; 74 | getStub = sinon.stub(repository, "get"); 75 | repository.listTree(1); 76 | getStub.restore(); 77 | return expect(getStub).to.have.been.called; 78 | }); 79 | }); 80 | return describe("showFile()", function() { 81 | return it("should use GET verb", function() { 82 | var getStub; 83 | getStub = sinon.stub(repository, "get"); 84 | repository.showFile(1, { 85 | file_path: "test", 86 | ref: "test" 87 | }); 88 | getStub.restore(); 89 | return expect(getStub).to.have.been.called; 90 | }); 91 | }); 92 | }); 93 | 94 | }).call(this); 95 | -------------------------------------------------------------------------------- /tests/Projects.test.coffee: -------------------------------------------------------------------------------- 1 | chai = require 'chai' 2 | expect = chai.expect 3 | sinon = require 'sinon' 4 | sinonChai = require 'sinon-chai' 5 | 6 | chai.use sinonChai 7 | 8 | describe "Projects", -> 9 | gitlab = null 10 | projects = null 11 | 12 | before -> 13 | gitlab = (require '../') 14 | url: 'test' 15 | token: 'test' 16 | 17 | projects = gitlab.projects 18 | 19 | beforeEach -> 20 | 21 | describe "show()", -> 22 | it "should use GET verb", -> 23 | getStub = sinon.stub projects, "get" 24 | 25 | projects.show 1 26 | 27 | getStub.restore() 28 | expect(getStub).to.have.been.called 29 | 30 | it "should pass Numeric projectIDs to Utils.parseProjectId", -> 31 | getStub = sinon.stub projects, "get" 32 | 33 | projects.show 1 34 | 35 | getStub.restore() 36 | expect(getStub).to.have.been.calledWith "projects/1" 37 | 38 | it "should pass Namespaced projectIDs to Utils.parseProjectId", -> 39 | getStub = sinon.stub projects, "get" 40 | 41 | projects.show "abc/def" 42 | 43 | getStub.restore() 44 | expect(getStub).to.have.been.calledWith "projects/abc%2Fdef" 45 | 46 | describe "all()", -> 47 | arrayOf101 = [] 48 | arrayOf100 = [] 49 | arrayOf99 = [] 50 | arrayOf1 = [] 51 | 52 | before -> 53 | for i in [0..102] 54 | if i < 1 55 | arrayOf1.push {} 56 | if i < 99 57 | arrayOf99.push {} 58 | if i < 100 59 | arrayOf100.push {} 60 | if i < 101 61 | arrayOf101.push {} 62 | 63 | it "should use GET verb", -> 64 | getStub = sinon.stub projects, "get" 65 | 66 | projects.all() 67 | 68 | getStub.restore() 69 | expect(getStub).to.have.been.called 70 | 71 | it "should recurse if more than 100 records are returned", -> 72 | getStub = sinon.stub projects, "get", (a,b,c)-> 73 | if getStub.callCount < 3 74 | c null, arrayOf100 75 | else 76 | c null, arrayOf99 77 | 78 | projects.all() 79 | 80 | expect(getStub).to.have.been.calledThrice 81 | 82 | describe "create()", -> 83 | it "should use POST verb", -> 84 | postStub = sinon.stub projects, "post" 85 | 86 | projects.create {} 87 | 88 | postStub.restore() 89 | expect(postStub).to.have.been.called 90 | -------------------------------------------------------------------------------- /tests/Projects.test.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var chai, expect, sinon, sinonChai; 3 | 4 | chai = require('chai'); 5 | 6 | expect = chai.expect; 7 | 8 | sinon = require('sinon'); 9 | 10 | sinonChai = require('sinon-chai'); 11 | 12 | chai.use(sinonChai); 13 | 14 | describe("Projects", function() { 15 | var gitlab, projects; 16 | gitlab = null; 17 | projects = null; 18 | before(function() { 19 | gitlab = (require('../'))({ 20 | url: 'test', 21 | token: 'test' 22 | }); 23 | return projects = gitlab.projects; 24 | }); 25 | beforeEach(function() {}); 26 | describe("show()", function() { 27 | it("should use GET verb", function() { 28 | var getStub; 29 | getStub = sinon.stub(projects, "get"); 30 | projects.show(1); 31 | getStub.restore(); 32 | return expect(getStub).to.have.been.called; 33 | }); 34 | it("should pass Numeric projectIDs to Utils.parseProjectId", function() { 35 | var getStub; 36 | getStub = sinon.stub(projects, "get"); 37 | projects.show(1); 38 | getStub.restore(); 39 | return expect(getStub).to.have.been.calledWith("projects/1"); 40 | }); 41 | return it("should pass Namespaced projectIDs to Utils.parseProjectId", function() { 42 | var getStub; 43 | getStub = sinon.stub(projects, "get"); 44 | projects.show("abc/def"); 45 | getStub.restore(); 46 | return expect(getStub).to.have.been.calledWith("projects/abc%2Fdef"); 47 | }); 48 | }); 49 | describe("all()", function() { 50 | var arrayOf1, arrayOf100, arrayOf101, arrayOf99; 51 | arrayOf101 = []; 52 | arrayOf100 = []; 53 | arrayOf99 = []; 54 | arrayOf1 = []; 55 | before(function() { 56 | var i, j, results; 57 | results = []; 58 | for (i = j = 0; j <= 102; i = ++j) { 59 | if (i < 1) { 60 | arrayOf1.push({}); 61 | } 62 | if (i < 99) { 63 | arrayOf99.push({}); 64 | } 65 | if (i < 100) { 66 | arrayOf100.push({}); 67 | } 68 | if (i < 101) { 69 | results.push(arrayOf101.push({})); 70 | } else { 71 | results.push(void 0); 72 | } 73 | } 74 | return results; 75 | }); 76 | it("should use GET verb", function() { 77 | var getStub; 78 | getStub = sinon.stub(projects, "get"); 79 | projects.all(); 80 | getStub.restore(); 81 | return expect(getStub).to.have.been.called; 82 | }); 83 | return it("should recurse if more than 100 records are returned", function() { 84 | var getStub; 85 | getStub = sinon.stub(projects, "get", function(a, b, c) { 86 | if (getStub.callCount < 3) { 87 | return c(null, arrayOf100); 88 | } else { 89 | return c(null, arrayOf99); 90 | } 91 | }); 92 | projects.all(); 93 | return expect(getStub).to.have.been.calledThrice; 94 | }); 95 | }); 96 | return describe("create()", function() { 97 | return it("should use POST verb", function() { 98 | var postStub; 99 | postStub = sinon.stub(projects, "post"); 100 | projects.create({}); 101 | postStub.restore(); 102 | return expect(postStub).to.have.been.called; 103 | }); 104 | }); 105 | }); 106 | 107 | }).call(this); 108 | -------------------------------------------------------------------------------- /tests/Utils.test.coffee: -------------------------------------------------------------------------------- 1 | chai = require 'chai' 2 | expect = chai.expect 3 | proxyquire = require 'proxyquire' 4 | Utils = require '../lib/Utils.js' 5 | 6 | describe "Utils", -> 7 | describe "parseProjectId", -> 8 | it "should return a Number if passed a Number", -> 9 | expect(Utils.parseProjectId 0).to.be.a 'number' 10 | 11 | it "should URI encode strings containing '/'", -> 12 | expect(Utils.parseProjectId "/abc").to.equal '%2Fabc' 13 | expect(Utils.parseProjectId "a/bc").to.equal 'a%2Fbc' 14 | expect(Utils.parseProjectId "ab/c").to.equal 'ab%2Fc' 15 | expect(Utils.parseProjectId "abc/").to.equal 'abc%2F' 16 | 17 | it "should return NaN for unparseable strings without '/'", -> 18 | expect(isNaN Utils.parseProjectId "abc").to.be.true 19 | 20 | it "should return a Number for parseable strings without '/'", -> 21 | expect(Utils.parseProjectId "1").to.equal 1 22 | -------------------------------------------------------------------------------- /tests/Utils.test.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Utils, chai, expect, proxyquire; 3 | 4 | chai = require('chai'); 5 | 6 | expect = chai.expect; 7 | 8 | proxyquire = require('proxyquire'); 9 | 10 | Utils = require('../lib/Utils.js'); 11 | 12 | describe("Utils", function() { 13 | return describe("parseProjectId", function() { 14 | it("should return a Number if passed a Number", function() { 15 | return expect(Utils.parseProjectId(0)).to.be.a('number'); 16 | }); 17 | it("should URI encode strings containing '/'", function() { 18 | expect(Utils.parseProjectId("/abc")).to.equal('%2Fabc'); 19 | expect(Utils.parseProjectId("a/bc")).to.equal('a%2Fbc'); 20 | expect(Utils.parseProjectId("ab/c")).to.equal('ab%2Fc'); 21 | return expect(Utils.parseProjectId("abc/")).to.equal('abc%2F'); 22 | }); 23 | it("should return NaN for unparseable strings without '/'", function() { 24 | return expect(isNaN(Utils.parseProjectId("abc"))).to.be["true"]; 25 | }); 26 | return it("should return a Number for parseable strings without '/'", function() { 27 | return expect(Utils.parseProjectId("1")).to.equal(1); 28 | }); 29 | }); 30 | }); 31 | 32 | }).call(this); 33 | -------------------------------------------------------------------------------- /tests/mock.coffee: -------------------------------------------------------------------------------- 1 | class Mock 2 | constructor: -> 3 | @path = '' 4 | @projects = [] 5 | project = 6 | id: 13 7 | description: '' 8 | default_branch: 'master' 9 | public: false 10 | visibility_level: 0 11 | ssh_url_to_repo: 'git@demo.gitlab.com:sandbox/afro.git' 12 | http_url_to_repo: 'http://demo.gitlab.com/sandbox/afro.git' 13 | web_url: 'http://demo.gitlab.com/sandbox/afro' 14 | owner: 15 | id: 8 16 | name: 'Sandbox' 17 | created_at: '2013-08-01T16:44:17.000Z' 18 | name: 'Afro' 19 | name_with_namespace: 'Sandbox / Afro' 20 | path: 'afro' 21 | path_with_namespace: 'sandbox/afro' 22 | issues_enabled: true 23 | merge_requests_enabled: true 24 | wall_enabled: false 25 | wiki_enabled: true 26 | snippets_enabled: false 27 | created_at: '2013-11-14T17:45:19.000Z' 28 | last_activity_at: '2014-01-16T15:32:07.000Z' 29 | namespace: 30 | id: 8 31 | name: 'Sandbox' 32 | path: 'sandbox' 33 | owner_id: 1 34 | created_at: '2013-08-01T16:44:17.000Z' 35 | updated_at: '2013-08-01T16:44:17.000Z' 36 | description: '' 37 | @projects.push project 38 | 39 | setup: (gitlab) => 40 | before => 41 | gitlab.slumber = (path) => @update_path(path) 42 | beforeEach => 43 | do @beforeEach 44 | 45 | update_path: (@path) => 46 | return @ 47 | 48 | defaults: 49 | get: (opts, cb) -> 50 | cb(null, {}, [{}]) if cb 51 | delete: (opts, cb) -> 52 | cb(null, {}, [{}]) if cb 53 | post: (opts, cb) -> 54 | cb(null, {}, [{}]) if cb 55 | put: (opts, cb) -> 56 | cb(null, {}, [{}]) if cb 57 | patch: (opts, cb) -> 58 | cb(null, {}, [{}]) if cb 59 | 60 | beforeEach: => 61 | for method in ['get', 'delete', 'post', 'put', 'patch'] 62 | @[method] = @defaults[method] 63 | 64 | 65 | module.exports = new Mock() 66 | -------------------------------------------------------------------------------- /tests/mock.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Mock, 3 | bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 4 | 5 | Mock = (function() { 6 | function Mock() { 7 | this.beforeEach = bind(this.beforeEach, this); 8 | this.update_path = bind(this.update_path, this); 9 | this.setup = bind(this.setup, this); 10 | var project; 11 | this.path = ''; 12 | this.projects = []; 13 | project = { 14 | id: 13, 15 | description: '', 16 | default_branch: 'master', 17 | "public": false, 18 | visibility_level: 0, 19 | ssh_url_to_repo: 'git@demo.gitlab.com:sandbox/afro.git', 20 | http_url_to_repo: 'http://demo.gitlab.com/sandbox/afro.git', 21 | web_url: 'http://demo.gitlab.com/sandbox/afro', 22 | owner: { 23 | id: 8, 24 | name: 'Sandbox', 25 | created_at: '2013-08-01T16:44:17.000Z' 26 | }, 27 | name: 'Afro', 28 | name_with_namespace: 'Sandbox / Afro', 29 | path: 'afro', 30 | path_with_namespace: 'sandbox/afro', 31 | issues_enabled: true, 32 | merge_requests_enabled: true, 33 | wall_enabled: false, 34 | wiki_enabled: true, 35 | snippets_enabled: false, 36 | created_at: '2013-11-14T17:45:19.000Z', 37 | last_activity_at: '2014-01-16T15:32:07.000Z', 38 | namespace: { 39 | id: 8, 40 | name: 'Sandbox', 41 | path: 'sandbox', 42 | owner_id: 1, 43 | created_at: '2013-08-01T16:44:17.000Z', 44 | updated_at: '2013-08-01T16:44:17.000Z', 45 | description: '' 46 | } 47 | }; 48 | this.projects.push(project); 49 | } 50 | 51 | Mock.prototype.setup = function(gitlab) { 52 | before((function(_this) { 53 | return function() { 54 | return gitlab.slumber = function(path) { 55 | return _this.update_path(path); 56 | }; 57 | }; 58 | })(this)); 59 | return beforeEach((function(_this) { 60 | return function() { 61 | return _this.beforeEach(); 62 | }; 63 | })(this)); 64 | }; 65 | 66 | Mock.prototype.update_path = function(path1) { 67 | this.path = path1; 68 | return this; 69 | }; 70 | 71 | Mock.prototype.defaults = { 72 | get: function(opts, cb) { 73 | if (cb) { 74 | return cb(null, {}, [{}]); 75 | } 76 | }, 77 | "delete": function(opts, cb) { 78 | if (cb) { 79 | return cb(null, {}, [{}]); 80 | } 81 | }, 82 | post: function(opts, cb) { 83 | if (cb) { 84 | return cb(null, {}, [{}]); 85 | } 86 | }, 87 | put: function(opts, cb) { 88 | if (cb) { 89 | return cb(null, {}, [{}]); 90 | } 91 | }, 92 | patch: function(opts, cb) { 93 | if (cb) { 94 | return cb(null, {}, [{}]); 95 | } 96 | } 97 | }; 98 | 99 | Mock.prototype.beforeEach = function() { 100 | var i, len, method, ref, results; 101 | ref = ['get', 'delete', 'post', 'put', 'patch']; 102 | results = []; 103 | for (i = 0, len = ref.length; i < len; i++) { 104 | method = ref[i]; 105 | results.push(this[method] = this.defaults[method]); 106 | } 107 | return results; 108 | }; 109 | 110 | return Mock; 111 | 112 | })(); 113 | 114 | module.exports = new Mock(); 115 | 116 | }).call(this); 117 | -------------------------------------------------------------------------------- /tests/test.coffee: -------------------------------------------------------------------------------- 1 | assert = require 'assert' 2 | 3 | # Setup 4 | Gitlab = require('..') 5 | credentials = # From http://demo.gitlab.com/ 6 | host: "http://demo.gitlab.com" 7 | token: "Wvjy2Krpb7y8xi93owUz" 8 | password: "123456" 9 | login: "test@test.com" 10 | 11 | gitlab = new Gitlab 12 | token: credentials.token 13 | url: credentials.host 14 | 15 | # Working variables 16 | projectId = 3 17 | userId = 1 18 | 19 | 20 | {validate_project} = require './validators' 21 | 22 | mock = require './mock' 23 | 24 | unless process.env.TEST_NO_MOCK? 25 | mock.setup gitlab 26 | 27 | 28 | describe 'User', -> 29 | describe '#all()', -> 30 | it 'should retrieve array of users without error', (done) -> 31 | gitlab.users.all (result) -> 32 | done() 33 | 34 | describe '#current()', -> 35 | it 'should retrieve current user without error', (done) -> 36 | gitlab.users.current (result) -> 37 | done() 38 | 39 | describe '#show()', -> 40 | it 'should retrieve a single user', (done) -> 41 | gitlab.users.show userId, (result) -> 42 | done() 43 | 44 | describe '#session()', -> 45 | it 'should retrieve a users session without error', (done) -> 46 | gitlab.users.session credentials.login, credentials.password, (result) -> 47 | done() 48 | 49 | 50 | describe 'Project', -> 51 | describe '#all()', -> 52 | beforeEach -> 53 | mock.get = (opts, cb) -> 54 | cb(null, {}, mock.projects) 55 | it 'should retrieve array of projects without error', (done) -> 56 | gitlab.projects.all (projects) -> 57 | assert projects.length > 0 58 | validate_project project for project in projects 59 | done() 60 | 61 | 62 | describe '#show()', -> 63 | beforeEach -> 64 | mock.get = (opts, cb) -> 65 | project = mock.projects[0] 66 | project.id = parseInt mock.path.split('/')[-1...][0] 67 | cb(null, {}, project) 68 | it 'should retrieve single project', (done) -> 69 | gitlab.projects.show projectId, (project) -> 70 | assert.equal project.id, projectId 71 | validate_project project 72 | done() 73 | 74 | describe 'Members', -> 75 | describe '#listMembers()', -> 76 | describe '#list', -> 77 | it 'should retrieve list of members of a project', (done) -> 78 | gitlab.projects.members.list projectId, (result) -> 79 | done() 80 | 81 | describe '#repository', -> 82 | describe '#listBranches', -> 83 | it 'should retrive branches of a given project', (done) -> 84 | gitlab.projects.repository.listBranches projectId, (result) -> 85 | done() 86 | 87 | describe '#listCommits()', -> 88 | it 'should retrieve commits of a given project', (done) -> 89 | gitlab.projects.repository.listCommits projectId, (result) -> 90 | done() 91 | 92 | describe '#addTag()', -> 93 | it 'should add a tag to a given project', (done) -> 94 | opts = 95 | id: projectId, 96 | tag_name: "v1.0.0", 97 | ref: "2695effb5807a22ff3d138d593fd856244e155e7", 98 | message: "Annotated message", 99 | release_description: "Release description" 100 | gitlab.projects.repository.addTag opts, (result) -> 101 | done() 102 | 103 | describe '#listTags()', -> 104 | it 'should retrieve tags of a given project', (done) -> 105 | gitlab.projects.repository.listTags projectId, (result) -> 106 | done() 107 | 108 | describe '#listTree()', -> 109 | it 'should retrieve tree of a given project', (done) -> 110 | gitlab.projects.repository.listTree projectId, (result) -> 111 | done() 112 | 113 | describe '#showFile()', -> 114 | it 'should retrieve specified file with arity=3', (done) -> 115 | opts = file_path: 'README.md', ref: 'master' 116 | gitlab.projects.repository.showFile projectId, opts, (result) -> 117 | done() 118 | 119 | it 'should retrieve specified file with arity=2', (done) -> 120 | opts = projectId: projectId, file_path: 'README.md', ref: 'master' 121 | gitlab.projects.repository.showFile opts, (result) -> 122 | done() 123 | 124 | 125 | describe 'Issue', -> 126 | describe '#all()', -> 127 | it 'should retrieve array of issues created by user', (done) -> 128 | gitlab.issues.all (result) -> 129 | done() 130 | -------------------------------------------------------------------------------- /tests/test.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var Gitlab, assert, credentials, gitlab, mock, projectId, userId, validate_project; 3 | 4 | assert = require('assert'); 5 | 6 | Gitlab = require('..'); 7 | 8 | credentials = { 9 | host: "http://demo.gitlab.com", 10 | token: "Wvjy2Krpb7y8xi93owUz", 11 | password: "123456", 12 | login: "test@test.com" 13 | }; 14 | 15 | gitlab = new Gitlab({ 16 | token: credentials.token, 17 | url: credentials.host 18 | }); 19 | 20 | projectId = 3; 21 | 22 | userId = 1; 23 | 24 | validate_project = require('./validators').validate_project; 25 | 26 | mock = require('./mock'); 27 | 28 | if (process.env.TEST_NO_MOCK == null) { 29 | mock.setup(gitlab); 30 | } 31 | 32 | describe('User', function() { 33 | describe('#all()', function() { 34 | return it('should retrieve array of users without error', function(done) { 35 | return gitlab.users.all(function(result) { 36 | return done(); 37 | }); 38 | }); 39 | }); 40 | describe('#current()', function() { 41 | return it('should retrieve current user without error', function(done) { 42 | return gitlab.users.current(function(result) { 43 | return done(); 44 | }); 45 | }); 46 | }); 47 | describe('#show()', function() { 48 | return it('should retrieve a single user', function(done) { 49 | return gitlab.users.show(userId, function(result) { 50 | return done(); 51 | }); 52 | }); 53 | }); 54 | return describe('#session()', function() { 55 | return it('should retrieve a users session without error', function(done) { 56 | return gitlab.users.session(credentials.login, credentials.password, function(result) { 57 | return done(); 58 | }); 59 | }); 60 | }); 61 | }); 62 | 63 | describe('Project', function() { 64 | describe('#all()', function() { 65 | beforeEach(function() { 66 | return mock.get = function(opts, cb) { 67 | return cb(null, {}, mock.projects); 68 | }; 69 | }); 70 | return it('should retrieve array of projects without error', function(done) { 71 | return gitlab.projects.all(function(projects) { 72 | var i, len, project; 73 | assert(projects.length > 0); 74 | for (i = 0, len = projects.length; i < len; i++) { 75 | project = projects[i]; 76 | validate_project(project); 77 | } 78 | return done(); 79 | }); 80 | }); 81 | }); 82 | describe('#show()', function() { 83 | beforeEach(function() { 84 | return mock.get = function(opts, cb) { 85 | var project; 86 | project = mock.projects[0]; 87 | project.id = parseInt(mock.path.split('/').slice(-1)[0]); 88 | return cb(null, {}, project); 89 | }; 90 | }); 91 | return it('should retrieve single project', function(done) { 92 | return gitlab.projects.show(projectId, function(project) { 93 | assert.equal(project.id, projectId); 94 | validate_project(project); 95 | return done(); 96 | }); 97 | }); 98 | }); 99 | describe('Members', function() { 100 | return describe('#listMembers()', function() { 101 | return describe('#list', function() { 102 | return it('should retrieve list of members of a project', function(done) { 103 | return gitlab.projects.members.list(projectId, function(result) { 104 | return done(); 105 | }); 106 | }); 107 | }); 108 | }); 109 | }); 110 | return describe('#repository', function() { 111 | describe('#listBranches', function() { 112 | return it('should retrive branches of a given project', function(done) { 113 | return gitlab.projects.repository.listBranches(projectId, function(result) { 114 | return done(); 115 | }); 116 | }); 117 | }); 118 | describe('#listCommits()', function() { 119 | return it('should retrieve commits of a given project', function(done) { 120 | return gitlab.projects.repository.listCommits(projectId, function(result) { 121 | return done(); 122 | }); 123 | }); 124 | }); 125 | describe('#addTag()', function() { 126 | return it('should add a tag to a given project', function(done) { 127 | var opts; 128 | opts = { 129 | id: projectId, 130 | tag_name: "v1.0.0", 131 | ref: "2695effb5807a22ff3d138d593fd856244e155e7", 132 | message: "Annotated message", 133 | release_description: "Release description" 134 | }; 135 | return gitlab.projects.repository.addTag(opts, function(result) { 136 | return done(); 137 | }); 138 | }); 139 | }); 140 | describe('#listTags()', function() { 141 | return it('should retrieve tags of a given project', function(done) { 142 | return gitlab.projects.repository.listTags(projectId, function(result) { 143 | return done(); 144 | }); 145 | }); 146 | }); 147 | describe('#listTree()', function() { 148 | return it('should retrieve tree of a given project', function(done) { 149 | return gitlab.projects.repository.listTree(projectId, function(result) { 150 | return done(); 151 | }); 152 | }); 153 | }); 154 | return describe('#showFile()', function() { 155 | it('should retrieve specified file with arity=3', function(done) { 156 | var opts; 157 | opts = { 158 | file_path: 'README.md', 159 | ref: 'master' 160 | }; 161 | return gitlab.projects.repository.showFile(projectId, opts, function(result) { 162 | return done(); 163 | }); 164 | }); 165 | return it('should retrieve specified file with arity=2', function(done) { 166 | var opts; 167 | opts = { 168 | projectId: projectId, 169 | file_path: 'README.md', 170 | ref: 'master' 171 | }; 172 | return gitlab.projects.repository.showFile(opts, function(result) { 173 | return done(); 174 | }); 175 | }); 176 | }); 177 | }); 178 | }); 179 | 180 | describe('Issue', function() { 181 | return describe('#all()', function() { 182 | return it('should retrieve array of issues created by user', function(done) { 183 | return gitlab.issues.all(function(result) { 184 | return done(); 185 | }); 186 | }); 187 | }); 188 | }); 189 | 190 | }).call(this); 191 | -------------------------------------------------------------------------------- /tests/validators.coffee: -------------------------------------------------------------------------------- 1 | assert = require 'assert' 2 | 3 | module.exports.validate_project = (project) -> 4 | assert project.id > 0 5 | assert.equal 'boolean', typeof project.public 6 | assert.equal 'string', typeof project.name 7 | #assert.equal 'string', typeof project.description 8 | -------------------------------------------------------------------------------- /tests/validators.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var assert; 3 | 4 | assert = require('assert'); 5 | 6 | module.exports.validate_project = function(project) { 7 | assert(project.id > 0); 8 | assert.equal('boolean', typeof project["public"]); 9 | return assert.equal('string', typeof project.name); 10 | }; 11 | 12 | }).call(this); 13 | --------------------------------------------------------------------------------