Skip to content

Commit ea2095a

Browse files
committed
repo.write and repo.remove is updated to use new Github api: 2 calls versus multiple
1 parent 755c7f8 commit ea2095a

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

github.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@
184184
// Delete a repo
185185
// --------
186186

187-
this.delete = function(cb) {
188-
console.error (repoPath);
187+
this.deleteRepo = function(cb) {
189188
_request("DELETE", repoPath, options, cb);
190189
};
191190

@@ -373,6 +372,7 @@
373372
// -------
374373

375374
this.fork = function(cb) {
375+
console.error(repoPath);
376376
_request("POST", repoPath + "/forks", null, cb);
377377
};
378378

@@ -395,26 +395,18 @@
395395
});
396396
};
397397

398-
// Remove a file from the tree
398+
399+
// Remove a file
399400
// -------
400401

401402
this.remove = function(branch, path, cb) {
402-
updateTree(branch, function(err, latestCommit) {
403-
that.getTree(latestCommit+"?recursive=true", function(err, tree) {
404-
// Update Tree
405-
var newTree = _.reject(tree, function(ref) { return ref.path === path; });
406-
_.each(newTree, function(ref) {
407-
if (ref.type === "tree") delete ref.sha;
408-
});
409-
410-
that.postTree(newTree, function(err, rootTree) {
411-
that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) {
412-
that.updateHead(branch, commit, function(err) {
413-
cb(err);
414-
});
415-
});
416-
});
417-
});
403+
that.getSha(branch, path, function(err, sha) {
404+
if (err) return cb(err);
405+
_request("DELETE", repoPath + "/contents/" + path, {
406+
message: path + " is removed",
407+
sha: sha,
408+
branch: branch
409+
}, cb);
418410
});
419411
};
420412

@@ -445,20 +437,17 @@
445437
// -------
446438

447439
this.write = function(branch, path, content, message, cb) {
448-
updateTree(branch, function(err, latestCommit) {
440+
that.getSha(branch, path, function(err, sha) {
449441
if (err) return cb(err);
450-
that.postBlob(content, function(err, blob) {
451-
if (err) return cb(err);
452-
that.updateTree(latestCommit, path, blob, function(err, tree) {
453-
if (err) return cb(err);
454-
that.commit(latestCommit, tree, message, function(err, commit) {
455-
if (err) return cb(err);
456-
that.updateHead(branch, commit, cb);
457-
});
458-
});
459-
});
442+
_request("PUT", repoPath + "/contents/" + path, {
443+
message: message,
444+
content: Base64.encode(content),
445+
branch: branch,
446+
sha: sha
447+
}, cb);
460448
});
461449
};
450+
462451
};
463452

464453
// Gists API

0 commit comments

Comments
 (0)