Skip to content

Commit a454f8a

Browse files
committed
Merge pull request #141 from michael/iamdanfox-improve-repo-commit-method
Iamdanfox improve repo commit method closes #130
2 parents e4ffdb4 + e86d4e9 commit a454f8a

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

github.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -414,21 +414,25 @@
414414
// -------
415415

416416
this.commit = function(parent, tree, message, cb) {
417-
var data = {
418-
"message": message,
419-
"author": {
420-
"name": options.username
421-
},
422-
"parents": [
423-
parent
424-
],
425-
"tree": tree
426-
};
427-
428-
_request("POST", repoPath + "/git/commits", data, function(err, res) {
429-
currentTree.sha = res.sha; // update latest commit
417+
var user = new Github.User();
418+
user.show(null, function(err, userData){
430419
if (err) return cb(err);
431-
cb(null, res.sha);
420+
var data = {
421+
"message": message,
422+
"author": {
423+
"name": options.user,
424+
"email": userData.email
425+
},
426+
"parents": [
427+
parent
428+
],
429+
"tree": tree
430+
};
431+
_request("POST", repoPath + "/git/commits", data, function(err, res) {
432+
if (err) return cb(err);
433+
currentTree.sha = res.sha; // update latest commit
434+
cb(null, res.sha);
435+
});
432436
});
433437
};
434438

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-api",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"description": "A higher-level wrapper around the Github API.",
55
"main": "github.js",
66
"dependencies": {

test/test.repo.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,23 @@ test("Repo API", function(t) {
4646
t.end();
4747

4848
});
49+
50+
test('Repo Returns commit errors correctly', function(t){
51+
var timeout = setTimeout(function () { t.fail(); }, 10000);
52+
var github = new Github({
53+
username: test_user.USERNAME,
54+
password: test_user.PASSWORD,
55+
auth: "basic"
56+
});
57+
var repo = github.getRepo(test_user.USERNAME, test_user.REPO);
58+
59+
repo.commit("broken-parent-hash", "broken-tree-hash", "commit message", function(err){
60+
t.ok(err, 'error thrown for bad commit');
61+
t.ok(err.request);
62+
t.equals(err.request.status, 422, 'Returns 422 status');
63+
clearTimeout(timeout);
64+
t.end();
65+
});
66+
67+
68+
});

test/user.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"USERNAME": "mikedeboertest",
3-
"PASSWORD": "test1324"
3+
"PASSWORD": "test1324",
4+
"REPO": "github"
45
}

0 commit comments

Comments
 (0)