diff --git a/README.md b/README.md index d8bb527..2045fa4 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,17 @@ MIT Changelog ========= +[1.7.0](https://github.com/node-gitlab/node-gitlab/tree/v1.7.0) (2016-07-11) +---------------------- + +- Add support for adding a tag to a project +- Add gitlab.projects.repository.compare() +- Add support for portion builds API +- Set slumber version to non-breaking + +[Full commits list](https://github.com/node-gitlab/node-gitlab/compare/v1.6.0...v1.7.0) + + [1.6.0](https://github.com/node-gitlab/node-gitlab/tree/v1.6.0) (2016-05-10) ---------------------- @@ -131,6 +142,8 @@ Changelog - Add support for the GitLab services API - Fix undefined assigneeId in merge request (#111) +[Full commits list](https://github.com/node-gitlab/node-gitlab/compare/v1.5.0...v1.6.0) + [1.5.0](https://github.com/node-gitlab/node-gitlab/tree/v1.5.0) (2015-11-26) ---------------------- diff --git a/lib/Models/ProjectBuilds.js b/lib/Models/ProjectBuilds.js new file mode 100644 index 0000000..21b0cd1 --- /dev/null +++ b/lib/Models/ProjectBuilds.js @@ -0,0 +1,74 @@ +(function() { + var BaseModel, ProjectBuilds, Utils, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + BaseModel = require('../BaseModel'); + + Utils = require('../Utils'); + + ProjectBuilds = (function(superClass) { + extend(ProjectBuilds, superClass); + + function ProjectBuilds() { + this.triggerBuild = bind(this.triggerBuild, this); + this.showBuild = bind(this.showBuild, this); + this.listBuilds = bind(this.listBuilds, this); + return ProjectBuilds.__super__.constructor.apply(this, arguments); + } + + ProjectBuilds.prototype.listBuilds = function(projectId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::listBuilds()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds", (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectBuilds.prototype.showBuild = function(projectId, buildId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::build()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds/" + buildId, null, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + ProjectBuilds.prototype.triggerBuild = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::triggerBuild()"); + return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/trigger/builds", params, null, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + + return ProjectBuilds; + + })(BaseModel); + + module.exports = function(client) { + return new ProjectBuilds(client); + }; + +}).call(this); diff --git a/lib/Models/ProjectRepository.js b/lib/Models/ProjectRepository.js index a516924..0c03ba8 100644 --- a/lib/Models/ProjectRepository.js +++ b/lib/Models/ProjectRepository.js @@ -12,6 +12,7 @@ extend(ProjectRepository, superClass); function ProjectRepository() { + this.compare = bind(this.compare, this); this.updateFile = bind(this.updateFile, this); this.createFile = bind(this.createFile, this); this.showFile = bind(this.showFile, this); @@ -20,6 +21,7 @@ this.showCommit = bind(this.showCommit, this); this.listCommits = bind(this.listCommits, this); this.listTags = bind(this.listTags, this); + this.addTag = bind(this.addTag, this); this.deleteBranch = bind(this.deleteBranch, this); this.createBranch = bind(this.createBranch, this); this.unprotectBranch = bind(this.unprotectBranch, this); @@ -116,6 +118,23 @@ })(this)); }; + ProjectRepository.prototype.addTag = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::addTag()"); + return this.post("projects/" + (Utils.parseProjectId(params.id)) + "/repository/tags", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + ProjectRepository.prototype.listTags = function(projectId, fn) { if (fn == null) { fn = null; @@ -260,6 +279,23 @@ })(this)); }; + ProjectRepository.prototype.compare = function(params, fn) { + if (params == null) { + params = {}; + } + if (fn == null) { + fn = null; + } + this.debug("Projects::compare()", params); + return this.get("projects/" + (Utils.parseProjectId(params.projectId)) + "/repository/compare", params, (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + return ProjectRepository; })(BaseModel); diff --git a/lib/Models/Projects.js b/lib/Models/Projects.js index 5107284..2799dc8 100644 --- a/lib/Models/Projects.js +++ b/lib/Models/Projects.js @@ -12,6 +12,7 @@ extend(Projects, superClass); function Projects() { + this.listTriggers = bind(this.listTriggers, this); this.search = bind(this.search, this); this.fork = bind(this.fork, this); this.remove = bind(this.remove, this); @@ -24,8 +25,8 @@ this.create_for_user = bind(this.create_for_user, this); this.create = bind(this.create, this); this.show = bind(this.show, this); - this.all = bind(this.all, this); this.allAdmin = bind(this.allAdmin, this); + this.all = bind(this.all, this); this.init = bind(this.init, this); return Projects.__super__.constructor.apply(this, arguments); } @@ -39,7 +40,8 @@ this.milestones = this.load('ProjectMilestones'); this.deploy_keys = this.load('ProjectDeployKeys'); this.merge_requests = this.load('ProjectMergeRequests'); - return this.services = this.load('ProjectServices'); + this.services = this.load('ProjectServices'); + return this.builds = this.load('ProjectBuilds'); }; Projects.prototype.all = function(params, fn) { @@ -314,6 +316,20 @@ })(this)); }; + Projects.prototype.listTriggers = function(projectId, fn) { + if (fn == null) { + fn = null; + } + this.debug("Projects::listTriggers()"); + return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/triggers", (function(_this) { + return function(data) { + if (fn) { + return fn(data); + } + }; + })(this)); + }; + return Projects; })(BaseModel); diff --git a/package.json b/package.json index 3b3c43c..1dac0ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitlab", - "version": "1.6.0", + "version": "1.7.0", "description": "GitLab API Nodejs library.", "main": "lib/index.js", "directories": { @@ -17,7 +17,7 @@ }, "dependencies": { "debug": "*", - "slumber": ">=0.7.0" + "slumber": "0.9.0" }, "devDependencies": { "coffee-script": ">=1.9.1", diff --git a/src/Models/ProjectBuilds.coffee b/src/Models/ProjectBuilds.coffee new file mode 100644 index 0000000..e482f54 --- /dev/null +++ b/src/Models/ProjectBuilds.coffee @@ -0,0 +1,19 @@ +BaseModel = require '../BaseModel' +Utils = require '../Utils' + +class ProjectBuilds extends BaseModel + + # === Builds + listBuilds: (projectId, fn = null) => + @debug "Projects::listBuilds()" + @get "projects/#{Utils.parseProjectId projectId}/builds", (data) => fn data if fn + + showBuild: (projectId, buildId, fn = null) => + @debug "Projects::build()" + @get "projects/#{Utils.parseProjectId projectId}/builds/#{buildId}", null, (data) => fn data if fn + + triggerBuild: (params={}, fn = null) => + @debug "Projects::triggerBuild()" + @post "projects/#{Utils.parseProjectId params.projectId}/trigger/builds", params, null, (data) => fn data if fn + +module.exports = (client) -> new ProjectBuilds client diff --git a/src/Models/ProjectRepository.coffee b/src/Models/ProjectRepository.coffee index 423d9cc..b936b7f 100644 --- a/src/Models/ProjectRepository.coffee +++ b/src/Models/ProjectRepository.coffee @@ -29,6 +29,10 @@ class ProjectRepository extends BaseModel @delete "projects/#{Utils.parseProjectId projectId}/repository/branches/#{encodeURI branchId}", (data) => fn data if fn # === Tags + addTag: (params = {}, fn = null) => + @debug "Projects::addTag()" + @post "projects/#{Utils.parseProjectId params.id}/repository/tags", params, (data) => fn data if fn + listTags: (projectId, fn = null) => @debug "Projects::listTags()" @get "projects/#{Utils.parseProjectId projectId}/repository/tags", (data) => fn data if fn @@ -76,6 +80,10 @@ class ProjectRepository extends BaseModel @debug "Projects::updateFile()", params @put "projects/#{Utils.parseProjectId params.projectId}/repository/files", params, (data) => fn data if fn + compare: (params = {}, fn = null) => + @debug "Projects::compare()", params + @get "projects/#{Utils.parseProjectId params.projectId}/repository/compare", params, (data) => fn data if fn + ## TODO: # - Raw file content # - Raw blob content diff --git a/src/Models/Projects.coffee b/src/Models/Projects.coffee index 649c2a5..8bcd26f 100644 --- a/src/Models/Projects.coffee +++ b/src/Models/Projects.coffee @@ -12,6 +12,7 @@ class Projects extends BaseModel @deploy_keys = @load 'ProjectDeployKeys' @merge_requests = @load 'ProjectMergeRequests' @services = @load 'ProjectServices' + @builds = @load 'ProjectBuilds' all: (params={}, fn=null) => if 'function' is typeof params @@ -113,4 +114,8 @@ class Projects extends BaseModel @debug "Projects::search()" @get "projects/search/#{projectName}", params, (data) => fn data if fn + listTriggers: (projectId, fn = null) => + @debug "Projects::listTriggers()" + @get "projects/#{Utils.parseProjectId projectId}/triggers", (data) => fn data if fn + module.exports = (client) -> new Projects client diff --git a/tests/ProjectRepository.test.coffee b/tests/ProjectRepository.test.coffee index 49dfd9f..a1ab87d 100644 --- a/tests/ProjectRepository.test.coffee +++ b/tests/ProjectRepository.test.coffee @@ -38,6 +38,21 @@ describe "ProjectRepository", -> getStub.restore() expect(getStub).to.have.been.called + describe "addTag()", -> + it "should use POST verb", -> + postStub = sinon.stub repository, "post" + + opts = + id: 1, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + repository.addTag opts + + postStub.restore() + expect(postStub).to.have.been.called + describe "listTags()", -> it "should use GET verb", -> getStub = sinon.stub repository, "get" @@ -66,4 +81,4 @@ describe "ProjectRepository", -> } getStub.restore() - expect(getStub).to.have.been.called \ No newline at end of file + expect(getStub).to.have.been.called diff --git a/tests/ProjectRepository.test.js b/tests/ProjectRepository.test.js index 8d1db80..692deb7 100644 --- a/tests/ProjectRepository.test.js +++ b/tests/ProjectRepository.test.js @@ -43,6 +43,22 @@ return expect(getStub).to.have.been.called; }); }); + describe("addTag()", function() { + return it("should use POST verb", function() { + var opts, postStub; + postStub = sinon.stub(repository, "post"); + opts = { + id: 1, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + }; + repository.addTag(opts); + postStub.restore(); + return expect(postStub).to.have.been.called; + }); + }); describe("listTags()", function() { return it("should use GET verb", function() { var getStub; diff --git a/tests/test.coffee b/tests/test.coffee index f2b90ae..473b3e7 100644 --- a/tests/test.coffee +++ b/tests/test.coffee @@ -89,6 +89,17 @@ describe 'Project', -> gitlab.projects.repository.listCommits projectId, (result) -> done() + describe '#addTag()', -> + it 'should add a tag to a given project', (done) -> + opts = + id: projectId, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + gitlab.projects.repository.addTag opts, (result) -> + done() + describe '#listTags()', -> it 'should retrieve tags of a given project', (done) -> gitlab.projects.repository.listTags projectId, (result) -> diff --git a/tests/test.js b/tests/test.js index 71368c4..699c1c4 100644 --- a/tests/test.js +++ b/tests/test.js @@ -122,6 +122,21 @@ }); }); }); + describe('#addTag()', function() { + return it('should add a tag to a given project', function(done) { + var opts; + opts = { + id: projectId, + tag_name: "v1.0.0", + ref: "2695effb5807a22ff3d138d593fd856244e155e7", + message: "Annotated message", + release_description: "Release description" + }; + return gitlab.projects.repository.addTag(opts, function(result) { + return done(); + }); + }); + }); describe('#listTags()', function() { return it('should retrieve tags of a given project', function(done) { return gitlab.projects.repository.listTags(projectId, function(result) {