Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/Repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/repository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down