From d68aab64d627a5e481ad5d2aaf817d931d10536e Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Fri, 5 Apr 2019 17:46:19 -0600 Subject: [PATCH 1/3] Added test for commit. --- test/repository.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/repository.spec.js b/test/repository.spec.js index 40d43397..31139570 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -600,6 +600,22 @@ 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 create a release', function(done) { const releaseDef = { name: releaseName, From c2d279c639debd7727c21a4d057a83f8d3211c6c Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Fri, 5 Apr 2019 19:00:00 -0600 Subject: [PATCH 2/3] Created test for commit author change. --- test/repository.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/repository.spec.js b/test/repository.spec.js index 31139570..62bb3ba6 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -616,6 +616,29 @@ describe('Repository', function() { }); }); + 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, From 09f2042b1b2c2fc085dc2bb98405e38b5133b16b Mon Sep 17 00:00:00 2001 From: Jared Rewerts Date: Fri, 5 Apr 2019 19:03:16 -0600 Subject: [PATCH 3/3] Added optional options to commit. I borrowed this strategy from the writeFile approach. --- lib/Repository.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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