Skip to content

Commit 55ea42a

Browse files
committed
Merge pull request moul#131 from vvvsrx/develop
Add support for portion builds api
2 parents 7f24f4e + 377858e commit 55ea42a

4 files changed

Lines changed: 115 additions & 1 deletion

File tree

lib/Models/ProjectBuilds.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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, fn) {
22+
if (fn == null) {
23+
fn = null;
24+
}
25+
this.debug("Projects::listBuilds()");
26+
return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds", (function(_this) {
27+
return function(data) {
28+
if (fn) {
29+
return fn(data);
30+
}
31+
};
32+
})(this));
33+
};
34+
35+
ProjectBuilds.prototype.showBuild = function(projectId, buildId, fn) {
36+
if (fn == null) {
37+
fn = null;
38+
}
39+
this.debug("Projects::build()");
40+
return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/builds/" + buildId, null, (function(_this) {
41+
return function(data) {
42+
if (fn) {
43+
return fn(data);
44+
}
45+
};
46+
})(this));
47+
};
48+
49+
ProjectBuilds.prototype.triggerBuild = function(params, fn) {
50+
if (params == null) {
51+
params = {};
52+
}
53+
if (fn == null) {
54+
fn = null;
55+
}
56+
this.debug("Projects::triggerBuild()");
57+
return this.post("projects/" + (Utils.parseProjectId(params.projectId)) + "/trigger/builds", params, null, (function(_this) {
58+
return function(data) {
59+
if (fn) {
60+
return fn(data);
61+
}
62+
};
63+
})(this));
64+
};
65+
66+
return ProjectBuilds;
67+
68+
})(BaseModel);
69+
70+
module.exports = function(client) {
71+
return new ProjectBuilds(client);
72+
};
73+
74+
}).call(this);

lib/Models/Projects.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
extend(Projects, superClass);
1313

1414
function Projects() {
15+
this.listTriggers = bind(this.listTriggers, this);
1516
this.search = bind(this.search, this);
1617
this.fork = bind(this.fork, this);
1718
this.remove = bind(this.remove, this);
@@ -39,7 +40,8 @@
3940
this.milestones = this.load('ProjectMilestones');
4041
this.deploy_keys = this.load('ProjectDeployKeys');
4142
this.merge_requests = this.load('ProjectMergeRequests');
42-
return this.services = this.load('ProjectServices');
43+
this.services = this.load('ProjectServices');
44+
return this.builds = this.load('ProjectBuilds');
4345
};
4446

4547
Projects.prototype.all = function(params, fn) {
@@ -314,6 +316,20 @@
314316
})(this));
315317
};
316318

319+
Projects.prototype.listTriggers = function(projectId, fn) {
320+
if (fn == null) {
321+
fn = null;
322+
}
323+
this.debug("Projects::listTriggers()");
324+
return this.get("projects/" + (Utils.parseProjectId(projectId)) + "/triggers", (function(_this) {
325+
return function(data) {
326+
if (fn) {
327+
return fn(data);
328+
}
329+
};
330+
})(this));
331+
};
332+
317333
return Projects;
318334

319335
})(BaseModel);

src/Models/ProjectBuilds.coffee

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
BaseModel = require '../BaseModel'
2+
Utils = require '../Utils'
3+
4+
class ProjectBuilds extends BaseModel
5+
6+
# === Builds
7+
listBuilds: (projectId, fn = null) =>
8+
@debug "Projects::listBuilds()"
9+
@get "projects/#{Utils.parseProjectId projectId}/builds", (data) => fn data if fn
10+
11+
showBuild: (projectId, buildId, fn = null) =>
12+
@debug "Projects::build()"
13+
@get "projects/#{Utils.parseProjectId projectId}/builds/#{buildId}", null, (data) => fn data if fn
14+
15+
triggerBuild: (params={}, fn = null) =>
16+
@debug "Projects::triggerBuild()"
17+
@post "projects/#{Utils.parseProjectId params.projectId}/trigger/builds", params, null, (data) => fn data if fn
18+
19+
module.exports = (client) -> new ProjectBuilds client

src/Models/Projects.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Projects extends BaseModel
1212
@deploy_keys = @load 'ProjectDeployKeys'
1313
@merge_requests = @load 'ProjectMergeRequests'
1414
@services = @load 'ProjectServices'
15+
@builds = @load 'ProjectBuilds'
1516

1617
all: (params={}, fn=null) =>
1718
if 'function' is typeof params
@@ -113,4 +114,8 @@ class Projects extends BaseModel
113114
@debug "Projects::search()"
114115
@get "projects/search/#{projectName}", params, (data) => fn data if fn
115116

117+
listTriggers: (projectId, fn = null) =>
118+
@debug "Projects::listTriggers()"
119+
@get "projects/#{Utils.parseProjectId projectId}/triggers", (data) => fn data if fn
120+
116121
module.exports = (client) -> new Projects client

0 commit comments

Comments
 (0)