|
95 | 95 | path = next; |
96 | 96 | iterate(); |
97 | 97 | } |
| 98 | +<<<<<<< HEAD |
98 | 99 | }); |
99 | 100 | })(); |
| 101 | +======= |
| 102 | + } |
| 103 | + }; |
| 104 | + xhr.setRequestHeader('Accept','application/json'); |
| 105 | + xhr.setRequestHeader('Content-Type','application/json'); |
| 106 | + if ( |
| 107 | + (options.auth == 'oauth' && options.token) || |
| 108 | + (options.auth == 'basic' && options.username && options.password) |
| 109 | + ) { |
| 110 | + xhr.setRequestHeader('Authorization',options.auth == 'oauth' |
| 111 | + ? 'token '+ options.token |
| 112 | + : 'Basic ' + Base64.encode(options.username + ':' + options.password) |
| 113 | + ); |
| 114 | + } |
| 115 | + data ? xhr.send(JSON.stringify(data)) : xhr.send(); |
| 116 | +>>>>>>> c75337c4b3621f8509ebcddd27bdc4a85b51170a |
100 | 117 | } |
101 | 118 |
|
102 | 119 |
|
|
196 | 213 | cb(err, res); |
197 | 214 | }); |
198 | 215 | }; |
| 216 | + |
| 217 | + // Create a repo |
| 218 | + // ------- |
| 219 | + this.createRepo = function(options, cb) { |
| 220 | + _request("POST", "/user/repos", options, cb); |
| 221 | + }; |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
199 | 227 | }; |
200 | 228 |
|
201 | 229 |
|
|
214 | 242 | "sha": null |
215 | 243 | }; |
216 | 244 |
|
| 245 | + |
| 246 | + // Delete a repo |
| 247 | + // -------- |
| 248 | + |
| 249 | + this.deleteRepo = function(cb) { |
| 250 | + _request("DELETE", repoPath, options, cb); |
| 251 | + }; |
| 252 | + |
217 | 253 | // Uses the cache if branch has not been changed |
218 | 254 | // ------- |
219 | 255 |
|
|
333 | 369 | // ------- |
334 | 370 |
|
335 | 371 | this.getSha = function(branch, path, cb) { |
| 372 | +<<<<<<< HEAD |
336 | 373 | // Just use head if path is empty |
337 | 374 | if (path === "") return that.getRef("heads/"+branch, cb); |
338 | 375 | that.getTree(branch+"?recursive=true", function(err, tree) { |
|
341 | 378 | return file.path === path; |
342 | 379 | })[0]; |
343 | 380 | cb(null, file ? file.sha : null); |
| 381 | +======= |
| 382 | + if (!path || path === "") return that.getRef("heads/"+branch, cb); |
| 383 | + _request("GET", repoPath + "/contents/"+path, {ref: branch}, function(err, pathContent) { |
| 384 | + if (err) return cb(err); |
| 385 | + cb(null, pathContent.sha); |
| 386 | +>>>>>>> c75337c4b3621f8509ebcddd27bdc4a85b51170a |
344 | 387 | }); |
345 | 388 | }; |
346 | 389 |
|
|
454 | 497 | // Get contents |
455 | 498 | // -------- |
456 | 499 |
|
| 500 | +<<<<<<< HEAD |
457 | 501 | this.contents = function(branch, path, cb, sync) { |
458 | 502 | return _request("GET", repoPath + "/contents?ref=" + branch + (path ? "&path=" + path : ""), null, cb, 'raw', sync); |
| 503 | +======= |
| 504 | + this.contents = function(ref, path, cb) { |
| 505 | + _request("GET", repoPath + "/contents/"+path, { ref: ref }, cb); |
| 506 | +>>>>>>> c75337c4b3621f8509ebcddd27bdc4a85b51170a |
459 | 507 | }; |
460 | 508 |
|
461 | 509 | // Fork repository |
|
529 | 577 | // ------- |
530 | 578 |
|
531 | 579 | this.read = function(branch, path, cb) { |
532 | | - that.getSha(branch, path, function(err, sha) { |
533 | | - if (!sha) return cb("not found", null); |
534 | | - that.getBlob(sha, function(err, content) { |
535 | | - cb(err, content, sha); |
536 | | - }); |
| 580 | + _request("GET", repoPath + "/contents/"+path, {ref: branch}, function(err, obj) { |
| 581 | + if (err && err.error === 404) return cb("not found", null, null); |
| 582 | + |
| 583 | + if (err) return cb(err); |
| 584 | + var sha = obj.sha |
| 585 | + , content = Base64.decode(obj.content); |
| 586 | + |
| 587 | + cb(null, content, sha); |
537 | 588 | }); |
538 | 589 | }; |
539 | 590 |
|
540 | | - // Remove a file from the tree |
| 591 | + |
| 592 | + // Remove a file |
541 | 593 | // ------- |
542 | 594 |
|
543 | 595 | this.remove = function(branch, path, cb) { |
544 | | - updateTree(branch, function(err, latestCommit) { |
545 | | - that.getTree(latestCommit+"?recursive=true", function(err, tree) { |
546 | | - // Update Tree |
547 | | - var newTree = _.reject(tree, function(ref) { return ref.path === path; }); |
548 | | - _.each(newTree, function(ref) { |
549 | | - if (ref.type === "tree") delete ref.sha; |
550 | | - }); |
551 | | - |
552 | | - that.postTree(newTree, function(err, rootTree) { |
553 | | - that.commit(latestCommit, rootTree, 'Deleted '+path , function(err, commit) { |
554 | | - that.updateHead(branch, commit, function(err) { |
555 | | - cb(err); |
556 | | - }); |
557 | | - }); |
558 | | - }); |
559 | | - }); |
| 596 | + that.getSha(branch, path, function(err, sha) { |
| 597 | + if (err) return cb(err); |
| 598 | + _request("DELETE", repoPath + "/contents/" + path, { |
| 599 | + message: path + " is removed", |
| 600 | + sha: sha, |
| 601 | + branch: branch |
| 602 | + }, cb); |
560 | 603 | }); |
561 | 604 | }; |
562 | 605 |
|
|
604 | 647 | // ------- |
605 | 648 |
|
606 | 649 | this.write = function(branch, path, content, message, cb) { |
607 | | - updateTree(branch, function(err, latestCommit) { |
608 | | - if (err) return cb(err); |
609 | | - that.postBlob(content, function(err, blob) { |
610 | | - if (err) return cb(err); |
611 | | - that.updateTree(latestCommit, path, blob, function(err, tree) { |
612 | | - if (err) return cb(err); |
613 | | - that.commit(latestCommit, tree, message, function(err, commit) { |
614 | | - if (err) return cb(err); |
615 | | - that.updateHead(branch, commit, cb); |
616 | | - }); |
617 | | - }); |
618 | | - }); |
| 650 | + that.getSha(branch, path, function(err, sha) { |
| 651 | + if (err && err.error!=404) return cb(err); |
| 652 | + _request("PUT", repoPath + "/contents/" + path, { |
| 653 | + message: message, |
| 654 | + content: Base64.encode(content), |
| 655 | + branch: branch, |
| 656 | + sha: sha |
| 657 | + }, cb); |
619 | 658 | }); |
620 | 659 | }; |
621 | 660 |
|
| 661 | +<<<<<<< HEAD |
622 | 662 | // List commits on a repository. Takes an object of optional paramaters: |
623 | 663 | // sha: SHA or branch to start listing commits from |
624 | 664 | // path: Only commits containing this file path will be returned |
|
655 | 695 | } |
656 | 696 | _request("GET", url, null, cb); |
657 | 697 | }; |
| 698 | +======= |
| 699 | +>>>>>>> c75337c4b3621f8509ebcddd27bdc4a85b51170a |
658 | 700 | }; |
659 | 701 |
|
660 | 702 | // Gists API |
|
0 commit comments