|
184 | 184 | // Delete a repo |
185 | 185 | // -------- |
186 | 186 |
|
187 | | - this.delete = function(cb) { |
188 | | - console.error (repoPath); |
| 187 | + this.deleteRepo = function(cb) { |
189 | 188 | _request("DELETE", repoPath, options, cb); |
190 | 189 | }; |
191 | 190 |
|
|
373 | 372 | // ------- |
374 | 373 |
|
375 | 374 | this.fork = function(cb) { |
| 375 | + console.error(repoPath); |
376 | 376 | _request("POST", repoPath + "/forks", null, cb); |
377 | 377 | }; |
378 | 378 |
|
|
395 | 395 | }); |
396 | 396 | }; |
397 | 397 |
|
398 | | - // Remove a file from the tree |
| 398 | + |
| 399 | + // Remove a file |
399 | 400 | // ------- |
400 | 401 |
|
401 | 402 | 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); |
418 | 410 | }); |
419 | 411 | }; |
420 | 412 |
|
|
445 | 437 | // ------- |
446 | 438 |
|
447 | 439 | this.write = function(branch, path, content, message, cb) { |
448 | | - updateTree(branch, function(err, latestCommit) { |
| 440 | + that.getSha(branch, path, function(err, sha) { |
449 | 441 | 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); |
460 | 448 | }); |
461 | 449 | }; |
| 450 | + |
462 | 451 | }; |
463 | 452 |
|
464 | 453 | // Gists API |
|
0 commit comments