Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fadd687

Browse files
committed
merge pull request
1 parent f4c3e6d commit fadd687

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

README.md

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

122+
Merge a Pull Request.
123+
124+
```js
125+
var pullRequestID = 123;
126+
127+
repo.mergePull({
128+
number: pullRequestID,
129+
// pull request head sha is required to merge a pull request safely
130+
sha: 'f4c3e6d8045ea567cccdc0802e1769a85c6b690c'
131+
}, optionalMessage, function(err, mergeResult){});
132+
133+
// or simply:
134+
repo.getPull(pullRequestID, function(err, pullRequestInfo) {
135+
repo.mergePull(pullRequestInfo, function(err, mergeResult){});
136+
});
137+
```
138+
122139
Create Pull Request.
123140

124141
```js

github.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,26 @@
458458
});
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, function(err, mergeResult, xhr) {
476+
if (err) return cb(err);
477+
cb(null, mergeResult, xhr);
478+
});
479+
};
480+
461481
// Retrieve the changes made between base and head
462482
// -------
463483

test/test.repo.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ if (typeof window === 'undefined') { // We're in NodeJS
4040
// jscs:disable
4141
imageB64 = 'iVBORw0KGgoAAAANSUhEUgAAACsAAAAmCAAAAAB4qD3CAAABgElEQVQ4y9XUsUocURQGYN/pAyMWBhGtrEIMiFiooGuVIoYsSBAsRSQvYGFWC4uFhUBYsilXLERQsDA20YAguIbo5PQp3F3inVFTheSvZoavGO79z+mJP0/Pv2nPtlfLpfLq9tljNquO62S8mj1kmy/8nrHm/Xaz1930bt5n1+SzVmyrilItsod9ON0td1V59xR9hwV2HsMRsbfROLo4amzsRcQw5vO2CZPJEU5CM2cXYTCxg7CY2mwIVhK7AkNZYg9g4CqxVwNwkNg6zOTKMQP1xFZgKWeXoJLYdSjl7BysJ7YBIzk7Ap8TewLOE3oOTtIz6y/64bfQn55ZTIAPd2gNTOTurcbzp7z50v1y/Pq2Q7Wczca8vFjG6LvbMo92hiPL96xO+eYVPkVExMdONetFXZ+l+eP9cuV7RER8a9PZwrloTXv2tfv285ZOt4rnrTXlydxCu9sZmGrdN8eXC3ATERHXsHD5wC7ZL3HdsaX9R3bUzlb7YWvn/9ipf93+An8cHsx3W3WHAAAAAElFTkSuQmCC';
4242
imageBlob = new Blob();
43+
4344
// jscs:enable
4445
}
4546
}
@@ -131,9 +132,9 @@ describe('Github.Repository', function() {
131132

132133
it('should get statuses for a SHA from a repo', function(done) {
133134
repo.getStatuses('20fcff9129005d14cc97b9d59b8a3d37f4fb633b', function(err, statuses) {
134-
statuses.length.should.equal(6)
135+
statuses.length.should.equal(6);
135136
statuses.every(function(status) {
136-
return status.url === 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b'
137+
return status.url === 'https://api.github.com/repos/michael/github/statuses/20fcff9129005d14cc97b9d59b8a3d37f4fb633b';
137138
}).should.equal(true);
138139
done();
139140
});
@@ -272,14 +273,35 @@ describe('Creating new Github.Repository', function() {
272273
it('should get pull requests on repo', function(done) {
273274
var repo = github.getRepo('michael', 'github');
274275

275-
repo.getPull(153, function(err) {
276+
repo.getPull(153, function(err, pull) {
276277
should.not.exist(err);
277-
278-
// @TODO write better assertion
278+
should.exist(pull.number);
279+
pull.number.should.equal(153);
280+
should.exist(pull.head);
281+
should.exist(pull.head.sha);
279282
done();
280283
});
281284
});
282285

286+
it('should merge pull requests on repo', function(done) {
287+
var repo = github.getRepo('michael', 'github');
288+
var expectedDocUrl = 'https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button';
289+
290+
repo.getPull(153, function(err, pull) {
291+
repo.mergePull(pull, function(err) {
292+
should.exist(err);
293+
should.exist(err.request);
294+
should.exist(err.request.response);
295+
var errResponse = JSON.parse(err.request.response);
296+
297+
errResponse.documentation_url.should.equal(expectedDocUrl);
298+
299+
// @TODO write better assertion
300+
done();
301+
});
302+
});
303+
});
304+
283305
it('should delete a file on the repo', function(done) {
284306
repo.write('master', 'REMOVE-TEST.md', 'THIS IS A TEST', 'Remove test', function(err) {
285307
should.not.exist(err);

0 commit comments

Comments
 (0)