Skip to content

Commit 90fb78b

Browse files
j-rewertsclayreimann
authored andcommitted
feature: Add commit author (#547)
1 parent 38530fa commit 90fb78b

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/Repository.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,26 @@ class Repository extends Requestable {
334334
* @param {string} parent - the SHA of the parent commit
335335
* @param {string} tree - the SHA of the tree for this commit
336336
* @param {string} message - the commit message
337+
* @param {Object} [options] - commit options
338+
* @param {Object} [options.author] - the author of the commit
339+
* @param {Object} [options.commiter] - the committer
337340
* @param {Requestable.callback} cb - will receive the commit that is created
338341
* @return {Promise} - the promise for the http request
339342
*/
340-
commit(parent, tree, message, cb) {
343+
commit(parent, tree, message, options, cb) {
344+
if (typeof options === 'function') {
345+
cb = options;
346+
options = {};
347+
}
348+
341349
let data = {
342350
message,
343351
tree,
344352
parents: [parent],
345353
};
346354

355+
data = Object.assign({}, options, data);
356+
347357
return this._request('POST', `/repos/${this.__fullname}/git/commits`, data, cb)
348358
.then((response) => {
349359
this.__currentTree.sha = response.data.sha; // Update latest commit

test/repository.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,45 @@ describe('Repository', function() {
600600
}));
601601
});
602602

603+
it('should succeed on proper commit', function(done) {
604+
let parentSHA = '';
605+
let treeSHA = '';
606+
remoteRepo.getRef('heads/master').then((ref) => {
607+
parentSHA = ref.data.object.sha;
608+
return remoteRepo.getCommit(parentSHA);
609+
}).then((commit) => {
610+
treeSHA = commit.data.tree.sha;
611+
return remoteRepo.commit(parentSHA, treeSHA, 'is this thing on?');
612+
}).then((commit) => {
613+
expect(commit.data.author).to.have.own('name', 'Mike de Boer');
614+
expect(commit.data.author).to.have.own('email', 'mike@c9.io');
615+
done();
616+
});
617+
});
618+
619+
it('should allow commit to change author', function(done) {
620+
let parentSHA = '';
621+
let treeSHA = '';
622+
remoteRepo.getRef('heads/master').then((ref) => {
623+
parentSHA = ref.data.object.sha;
624+
return remoteRepo.getCommit(parentSHA);
625+
}).then((commit) => {
626+
treeSHA = commit.data.tree.sha;
627+
return remoteRepo.commit(parentSHA, treeSHA, 'Who made this commit?', {
628+
author: {
629+
name: 'Jimothy Halpert',
630+
email: 'jim@dundermifflin.com',
631+
},
632+
});
633+
}).then((commit) => {
634+
expect(commit.data.author).to.have.own('name', 'Jimothy Halpert');
635+
expect(commit.data.author).to.have.own('email', 'jim@dundermifflin.com');
636+
done();
637+
}).catch((err) => {
638+
throw err;
639+
});
640+
});
641+
603642
it('should create a release', function(done) {
604643
const releaseDef = {
605644
name: releaseName,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy