Skip to content

Commit ccd71af

Browse files
committed
Use authenticated name and email when committing
fix #128
1 parent b4b55ba commit ccd71af

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

github.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,22 +407,26 @@
407407
// -------
408408

409409
this.commit = function(parent, tree, message, cb) {
410-
var data = {
411-
"message": message,
412-
"author": {
413-
"name": options.user
414-
},
415-
"parents": [
416-
parent
417-
],
418-
"tree": tree
419-
};
420-
421-
_request("POST", repoPath + "/git/commits", data, function(err, res) {
410+
var user = new Github.User();
411+
user.show(null, function(err, userData){
422412
if (err) return cb(err);
423-
currentTree.sha = res.sha; // update latest commit
424-
cb(null, res.sha);
425-
});
413+
var data = {
414+
"message": message,
415+
"author": {
416+
"name": options.user,
417+
"email": userData.email
418+
},
419+
"parents": [
420+
parent
421+
],
422+
"tree": tree
423+
};
424+
_request("POST", repoPath + "/git/commits", data, function(err, res) {
425+
if (err) return cb(err);
426+
currentTree.sha = res.sha; // update latest commit
427+
cb(null, res.sha);
428+
});
429+
})
426430
};
427431

428432
// Update the reference of your head to point to the new commit SHA

test/commit_test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ describe("Repo", function(){
1919
it("should return commit errors correctly", function(done){
2020
var repo = github.getRepo(TEST_USERNAME, TEST_REPO);
2121
repo.commit("broken-parent-hash", "broken-tree-hash", "commit message", function(err){
22-
done();
22+
if (err != null && err.request != null && err.request.status == 500) {
23+
done();
24+
} else {
25+
done(new Error("No `err` passed to .commit callback"));
26+
}
2327
});
2428
});
2529

0 commit comments

Comments
 (0)