diff --git a/lib/Repository.js b/lib/Repository.js index 45ca3f94..f59cf0d0 100644 --- a/lib/Repository.js +++ b/lib/Repository.js @@ -334,16 +334,26 @@ class Repository extends Requestable { * @param {string} parent - the SHA of the parent commit * @param {string} tree - the SHA of the tree for this commit * @param {string} message - the commit message + * @param {Object} [options] - commit options + * @param {Object} [options.author] - the author of the commit + * @param {Object} [options.commiter] - the committer * @param {Requestable.callback} cb - will receive the commit that is created * @return {Promise} - the promise for the http request */ - commit(parent, tree, message, cb) { + commit(parent, tree, message, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } + let data = { message, tree, parents: [parent], }; + data = Object.assign({}, options, data); + return this._request('POST', `/repos/${this.__fullname}/git/commits`, data, cb) .then((response) => { this.__currentTree.sha = response.data.sha; // Update latest commit diff --git a/test/repository.spec.js b/test/repository.spec.js index 40d43397..62bb3ba6 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -600,6 +600,45 @@ describe('Repository', function() { })); }); + it('should succeed on proper commit', function(done) { + let parentSHA = ''; + let treeSHA = ''; + remoteRepo.getRef('heads/master').then((ref) => { + parentSHA = ref.data.object.sha; + return remoteRepo.getCommit(parentSHA); + }).then((commit) => { + treeSHA = commit.data.tree.sha; + return remoteRepo.commit(parentSHA, treeSHA, 'is this thing on?'); + }).then((commit) => { + expect(commit.data.author).to.have.own('name', 'Mike de Boer'); + expect(commit.data.author).to.have.own('email', 'mike@c9.io'); + done(); + }); + }); + + it('should allow commit to change author', function(done) { + let parentSHA = ''; + let treeSHA = ''; + remoteRepo.getRef('heads/master').then((ref) => { + parentSHA = ref.data.object.sha; + return remoteRepo.getCommit(parentSHA); + }).then((commit) => { + treeSHA = commit.data.tree.sha; + return remoteRepo.commit(parentSHA, treeSHA, 'Who made this commit?', { + author: { + name: 'Jimothy Halpert', + email: 'jim@dundermifflin.com', + }, + }); + }).then((commit) => { + expect(commit.data.author).to.have.own('name', 'Jimothy Halpert'); + expect(commit.data.author).to.have.own('email', 'jim@dundermifflin.com'); + done(); + }).catch((err) => { + throw err; + }); + }); + it('should create a release', function(done) { const releaseDef = { name: releaseName,