|
52 | 52 | cb({path: path, request: this, error: this.status}); |
53 | 53 | } |
54 | 54 | } |
55 | | - } |
56 | | - }; |
| 55 | + }; |
| 56 | + } |
57 | 57 | xhr.setRequestHeader('Accept','application/vnd.github.v3.raw+json'); |
58 | 58 | xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8'); |
59 | 59 | if ((options.token) || (options.username && options.password)) { |
60 | | - xhr.setRequestHeader('Authorization', options.token |
61 | | - ? 'token '+ options.token |
62 | | - : 'Basic ' + Base64.encode(options.username + ':' + options.password) |
63 | | - ); |
64 | | - } |
65 | | - data ? xhr.send(JSON.stringify(data)) : xhr.send(); |
| 60 | + var authorization = options.token ? 'token ' + options.token : 'Basic ' + Base64.encode(options.username + ':' + options.password); |
| 61 | + xhr.setRequestHeader('Authorization', authorization); |
| 62 | + } |
| 63 | + if (data) |
| 64 | + xhr.send(JSON.stringify(data)); |
| 65 | + else |
| 66 | + xhr.send(); |
66 | 67 | if (sync) return xhr.response; |
67 | 68 | } |
68 | 69 |
|
|
252 | 253 | _request("DELETE", repoPath + "/git/refs/"+ref, options, cb); |
253 | 254 | }; |
254 | 255 |
|
255 | | - // Create a repo |
| 256 | + // Create a repo |
256 | 257 | // ------- |
257 | 258 |
|
258 | 259 | this.createRepo = function(options, cb) { |
259 | 260 | _request("POST", "/user/repos", options, cb); |
260 | 261 | }; |
261 | 262 |
|
262 | | - // Delete a repo |
263 | | - // -------- |
| 263 | + // Delete a repo |
| 264 | + // -------- |
264 | 265 |
|
265 | | - this.deleteRepo = function(cb) { |
266 | | - _request("DELETE", repoPath, options, cb); |
| 266 | + this.deleteRepo = function(cb) { |
| 267 | + _request("DELETE", repoPath, options, cb); |
267 | 268 | }; |
268 | 269 |
|
269 | 270 | // List all tags of a repository |
|
455 | 456 | _request("POST", repoPath + "/forks", null, cb); |
456 | 457 | }; |
457 | 458 |
|
458 | | - // Branch repository |
459 | | - // -------- |
460 | | - |
| 459 | + // Branch repository |
| 460 | + // -------- |
| 461 | + |
461 | 462 | this.branch = function(oldBranch,newBranch,cb) { |
462 | 463 | if(arguments.length === 2 && typeof arguments[1] === "function") { |
463 | 464 | cb = newBranch; |
|
471 | 472 | sha: ref |
472 | 473 | },cb); |
473 | 474 | }); |
474 | | - } |
| 475 | + }; |
475 | 476 |
|
476 | 477 | // Create pull request |
477 | 478 | // -------- |
|
549 | 550 | }); |
550 | 551 | }); |
551 | 552 | }; |
552 | | - |
| 553 | + |
553 | 554 | // Delete a file from the tree |
554 | 555 | // ------- |
555 | | - |
| 556 | + |
556 | 557 | this.delete = function(branch, path, cb) { |
557 | 558 | that.getSha(branch, path, function(err, sha) { |
558 | 559 | if (!sha) return cb("not found", null); |
559 | 560 | var delPath = repoPath + "/contents/" + path; |
560 | 561 | var params = { |
561 | 562 | "message": "Deleted " + path, |
562 | | - "sha": sha |
| 563 | + "sha": sha |
563 | 564 | }; |
564 | 565 | delPath += "?message=" + encodeURIComponent(params.message); |
565 | 566 | delPath += "&sha=" + encodeURIComponent(params.sha); |
566 | 567 | _request("DELETE", delPath, null, cb); |
567 | | - }) |
568 | | - } |
569 | | - |
| 568 | + }); |
| 569 | + }; |
| 570 | + |
570 | 571 | // Move a file to a new location |
571 | 572 | // ------- |
572 | 573 |
|
|
741 | 742 | var path = "/repos/" + options.user + "/" + options.repo + "/issues"; |
742 | 743 |
|
743 | 744 | this.list = function(options, cb) { |
744 | | - _request("GET", path, options, function(err, res) { |
745 | | - cb(err,res) |
746 | | - }); |
| 745 | + _request("GET", path, options, cb); |
747 | 746 | }; |
748 | 747 | }; |
749 | 748 |
|
|
0 commit comments