Skip to content

Commit 534ed08

Browse files
author
Tim Walling
committed
add new repo merging API
1 parent f3d26b9 commit 534ed08

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

api/v3.0.0/repos.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,49 @@ var repos = module.exports = {
323323
});
324324
};
325325

326+
/** section: github
327+
* repos#merge(msg, callback) -> null
328+
* - msg (Object): Object that contains the parameters and their values to be sent to the server.
329+
* - callback (Function): function to call when the request is finished with an error as first argument and result data as second argument.
330+
*
331+
* ##### Params on the `msg` object:
332+
*
333+
* - user (String): Required.
334+
* - repo (String): Required.
335+
* - base (String): Required. The name of the base branch that the head will be merged into.
336+
* - head (String): Required. The head to merge. This can be a branch name or a commit SHA1.
337+
* - commit_message (String): Optional. Commit message to use for the merge commit. If omitted, a default message will be used.
338+
**/
339+
this.merge = function(msg, block, callback) {
340+
var self = this;
341+
this.client.httpSend(msg, block, function(err, res) {
342+
if (err)
343+
return self.sendError(err, null, msg, callback);
344+
345+
var ret;
346+
try {
347+
ret = res.data && JSON.parse(res.data);
348+
}
349+
catch (ex) {
350+
if (callback)
351+
callback(new error.InternalServerError(ex.message), res);
352+
return;
353+
}
354+
355+
if (!ret)
356+
ret = {};
357+
if (!ret.meta)
358+
ret.meta = {};
359+
["x-ratelimit-limit", "x-ratelimit-remaining", "link"].forEach(function(header) {
360+
if (res.headers[header])
361+
ret.meta[header] = res.headers[header];
362+
});
363+
364+
if (callback)
365+
callback(null, ret);
366+
});
367+
}
368+
326369
/** section: github
327370
* repos#getContributors(msg, callback) -> null
328371
* - msg (Object): Object that contains the parameters and their values to be sent to the server.

api/v3.0.0/reposTest.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,28 @@ var test = module.exports = {
179179
);
180180
},
181181

182+
"test: POST /repos/:user/:repo/merges (merge)": function(next) {
183+
var self = this;
184+
this.client.authenticate({
185+
type: "token",
186+
username: username,
187+
token: token
188+
});
189+
this.client.repos.merge(
190+
{
191+
user: "String",
192+
repo: "String",
193+
base: "String",
194+
head: "String",
195+
commit_message: "String"
196+
},
197+
function(err, res) {
198+
Assert.equal(err, null);
199+
// other assertions go here
200+
}
201+
);
202+
},
203+
182204
"test: GET /repos/:user/:repo/contributors (getContributors)": function(next) {
183205
var self = this;
184206
this.client.authenticate({

api/v3.0.0/routes.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,24 @@
16481648
}
16491649
},
16501650

1651+
"merge": {
1652+
"url": "/repos/:user/:repo/merges",
1653+
"method": "POST",
1654+
"params": {
1655+
"$user": null,
1656+
"$repo": null,
1657+
"$base": null,
1658+
"$head": null,
1659+
"commit_message": {
1660+
"type": "String",
1661+
"required": false,
1662+
"validation": "",
1663+
"invalidmsg": "",
1664+
"description": "Optional string - Commit message to use for the merge commit. If omitted, a default message will be used."
1665+
}
1666+
}
1667+
},
1668+
16511669
"get-contributors": {
16521670
"url": "/repos/:user/:repo/contributors",
16531671
"method": "GET",

0 commit comments

Comments
 (0)