Skip to content

Commit 5481366

Browse files
committed
merge pull request
1 parent 3dc854a commit 5481366

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,23 @@ var pullRequestID = 123;
141141
repo.getPull(pullRequestID, function(err, pullRequestInfo) {});
142142
```
143143

144+
Merge a Pull Request.
145+
146+
```js
147+
var pullRequestID = 123;
148+
149+
repo.mergePull({
150+
number: pullRequestID,
151+
// pull request head sha is required to merge a pull request safely
152+
sha: 'f4c3e6d8045ea567cccdc0802e1769a85c6b690c'
153+
}, optionalMessage, function(err, mergeResult){});
154+
155+
// or simply:
156+
repo.getPull(pullRequestID, function(err, pullRequestInfo) {
157+
repo.mergePull(pullRequestInfo, function(err, mergeResult){});
158+
});
159+
```
160+
144161
Create Pull Request.
145162

146163
```js

src/github.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,23 @@
458458
_request('GET', repoPath + '/pulls/' + number, null, cb);
459459
};
460460

461+
// Merge a specific pull request
462+
// -------
463+
464+
this.mergePull = function(pull, message, cb) {
465+
if (typeof message === 'function') {
466+
cb = message;
467+
message = '';
468+
}
469+
470+
var data = {
471+
sha: pull.sha || pull.head.sha,
472+
commit_message: message
473+
};
474+
475+
_request('PUT', repoPath + '/pulls/' + pull.number + '/merge', data, cb);
476+
};
477+
461478
// Retrieve the changes made between base and head
462479
// -------
463480

test/test.repo.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ if (typeof window === 'undefined') { // We're in NodeJS
3333
// jscs:disable
3434
imageB64 = 'iVBORw0KGgoAAAANSUhEUgAAACsAAAAmCAAAAAB4qD3CAAABgElEQVQ4y9XUsUocURQGYN/pAyMWBhGtrEIMiFiooGuVIoYsSBAsRSQvYGFWC4uFhUBYsilXLERQsDA20YAguIbo5PQp3F3inVFTheSvZoavGO79z+mJP0/Pv2nPtlfLpfLq9tljNquO62S8mj1kmy/8nrHm/Xaz1930bt5n1+SzVmyrilItsod9ON0td1V59xR9hwV2HsMRsbfROLo4amzsRcQw5vO2CZPJEU5CM2cXYTCxg7CY2mwIVhK7AkNZYg9g4CqxVwNwkNg6zOTKMQP1xFZgKWeXoJLYdSjl7BysJ7YBIzk7Ap8TewLOE3oOTtIz6y/64bfQn55ZTIAPd2gNTOTurcbzp7z50v1y/Pq2Q7Wczca8vFjG6LvbMo92hiPL96xO+eYVPkVExMdONetFXZ+l+eP9cuV7RER8a9PZwrloTXv2tfv285ZOt4rnrTXlydxCu9sZmGrdN8eXC3ATERHXsHD5wC7ZL3HdsaX9R3bUzlb7YWvn/9ipf93+An8cHsx3W3WHAAAAAElFTkSuQmCC';
3535
imageBlob = new Blob();
36+
3637
// jscs:enable
3738
}
3839
}
@@ -425,6 +426,42 @@ describe('Creating new Github.Repository', function() {
425426
});
426427
});
427428

429+
it.only('should merge pull requests on repo', function(done) {
430+
431+
var baseBranch = 'master';
432+
var headBranch = 'pull-request';
433+
var pullRequestTitle = 'Test pull request';
434+
var pullRequestBody = 'This is a test pull request to be merged';
435+
436+
repo.branch(baseBranch, headBranch, function() {
437+
repo.write(headBranch, 'TEST.md', 'THIS IS AN UPDATED TEST THAT WILL GET MERGED', 'Updating test', function() {
438+
repo.createPullRequest(
439+
{
440+
title: pullRequestTitle,
441+
body: pullRequestBody,
442+
base: baseBranch,
443+
head: headBranch
444+
},
445+
function(err, pullRequest, xhr) {
446+
should.not.exist(err);
447+
xhr.should.be.instanceof(XMLHttpRequest);
448+
449+
repo.mergePull(pullRequest, function(err, mergedPullRequest, xhr) {
450+
should.not.exist(err);
451+
xhr.should.be.instanceof(XMLHttpRequest);
452+
453+
should.exist(mergedPullRequest.sha);
454+
should(mergedPullRequest.merged).equal(true);
455+
should.exist(mergedPullRequest.message);
456+
457+
done();
458+
});
459+
}
460+
);
461+
});
462+
});
463+
});
464+
428465
it('should delete a file on the repo', function(done) {
429466
repo.write('master', 'REMOVE-TEST.md', 'THIS IS A TEST', 'Remove test', function(err) {
430467
should.not.exist(err);

0 commit comments

Comments
 (0)