Skip to content
This repository has been archived by the owner on Oct 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #139 from node-gitlab/develop
Browse files Browse the repository at this point in the history
develop -> master
  • Loading branch information
moul committed Jul 11, 2016
2 parents 98c21f7 + fe1b4b1 commit f8d103e
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 5 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
----------------------

Expand All @@ -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)
----------------------

Expand Down
74 changes: 74 additions & 0 deletions lib/Models/ProjectBuilds.js
Original file line number Diff line number Diff line change
@@ -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);
36 changes: 36 additions & 0 deletions lib/Models/ProjectRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 18 additions & 2 deletions lib/Models/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitlab",
"version": "1.6.0",
"version": "1.7.0",
"description": "GitLab API Nodejs library.",
"main": "lib/index.js",
"directories": {
Expand All @@ -17,7 +17,7 @@
},
"dependencies": {
"debug": "*",
"slumber": ">=0.7.0"
"slumber": "0.9.0"
},
"devDependencies": {
"coffee-script": ">=1.9.1",
Expand Down
19 changes: 19 additions & 0 deletions src/Models/ProjectBuilds.coffee
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions src/Models/ProjectRepository.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Models/Projects.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 16 additions & 1 deletion tests/ProjectRepository.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -66,4 +81,4 @@ describe "ProjectRepository", ->
}

getStub.restore()
expect(getStub).to.have.been.called
expect(getStub).to.have.been.called
16 changes: 16 additions & 0 deletions tests/ProjectRepository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tests/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
15 changes: 15 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f8d103e

Please sign in to comment.