|
14 | 14 | (function (root, factory) { |
15 | 15 | /* istanbul ignore next */ |
16 | 16 | if (typeof define === 'function' && define.amd) { |
17 | | - define(['es6-promise', 'base-64', 'utf8', 'axios'], function (Promise, Base64, Utf8, axios) { |
18 | | - return (root.Github = factory(Promise, Base64, Utf8, axios)); |
19 | | - }); |
| 17 | + define( |
| 18 | + [ |
| 19 | + 'es6-promise', |
| 20 | + 'base-64', |
| 21 | + 'utf8', |
| 22 | + 'axios' |
| 23 | + ], |
| 24 | + function (Promise, Base64, Utf8, axios) { |
| 25 | + return (root.Github = factory(Promise, Base64, Utf8, axios)); |
| 26 | + } |
| 27 | + ); |
20 | 28 | } else if (typeof module === 'object' && module.exports) { |
21 | 29 | module.exports = factory(require('es6-promise'), require('base-64'), require('utf8'), require('axios')); |
22 | 30 | } else { |
23 | 31 | root.Github = factory(root.Promise, root.base64, root.utf8, root.axios); |
24 | 32 | } |
25 | | -}(this, function(Promise, Base64, Utf8, axios) { |
| 33 | +}(this, function(Promise, Base64, Utf8, axios) { // jshint ignore:line |
26 | 34 | function b64encode(string) { |
27 | 35 | return Base64.encode(Utf8.encode(string)); |
28 | 36 | } |
|
49 | 57 | url += ((/\?/).test(url) ? '&' : '?'); |
50 | 58 |
|
51 | 59 | if (data && typeof data === 'object' && ['GET', 'HEAD', 'DELETE'].indexOf(method) > -1) { |
52 | | - for (var param in data) { |
| 60 | + for(var param in data) { |
53 | 61 | if (data.hasOwnProperty(param)) { |
54 | 62 | url += '&' + encodeURIComponent(param) + '=' + encodeURIComponent(data[param]); |
55 | 63 | } |
|
71 | 79 | }; |
72 | 80 |
|
73 | 81 | if ((options.token) || (options.username && options.password)) { |
74 | | - config.headers['Authorization'] = options.token ? |
| 82 | + config.headers.Authorization = options.token ? |
75 | 83 | 'token ' + options.token : |
76 | 84 | 'Basic ' + b64encode(options.username + ':' + options.password); |
77 | 85 | } |
|
160 | 168 |
|
161 | 169 | url += '?' + params.join('&'); |
162 | 170 |
|
163 | | - _requestAllPages(url, cb); |
| 171 | + _requestAllPages(url, cb); |
164 | 172 | }; |
165 | 173 |
|
166 | 174 | // List user organizations |
|
450 | 458 |
|
451 | 459 | this.listBranches = function (cb) { |
452 | 460 | _request('GET', repoPath + '/git/refs/heads', null, function (err, heads, xhr) { |
453 | | - if (err) return cb(err); |
| 461 | + if (err) { |
| 462 | + return cb(err); |
| 463 | + } |
| 464 | + |
454 | 465 | cb(null, heads.map(function (head) { |
455 | 466 | return head.ref.replace(/^refs\/heads\//, ''); |
456 | 467 | }), xhr); |
|
475 | 486 | // ------- |
476 | 487 |
|
477 | 488 | this.getSha = function (branch, path, cb) { |
478 | | - if (!path || path === '') return that.getRef('heads/' + branch, cb); |
| 489 | + if (!path || path === '') { |
| 490 | + return that.getRef('heads/' + branch, cb); |
| 491 | + } |
| 492 | + |
479 | 493 | _request('GET', repoPath + '/contents/' + path + (branch ? '?ref=' + branch : ''), |
480 | 494 | null, function (err, pathContent, xhr) { |
481 | | - if (err) return cb(err); |
| 495 | + if (err) { |
| 496 | + return cb(err); |
| 497 | + } |
| 498 | + |
482 | 499 | cb(null, pathContent.sha, xhr); |
483 | 500 | }); |
484 | 501 | }; |
|
495 | 512 |
|
496 | 513 | this.getTree = function (tree, cb) { |
497 | 514 | _request('GET', repoPath + '/git/trees/' + tree, null, function (err, res, xhr) { |
498 | | - if (err) return cb(err); |
| 515 | + if (err) { |
| 516 | + return cb(err); |
| 517 | + } |
| 518 | + |
499 | 519 | cb(null, res.tree, xhr); |
500 | 520 | }); |
501 | 521 | }; |
|
517 | 537 | } |
518 | 538 |
|
519 | 539 | _request('POST', repoPath + '/git/blobs', content, function (err, res) { |
520 | | - if (err) return cb(err); |
| 540 | + if (err) { |
| 541 | + return cb(err); |
| 542 | + } |
| 543 | + |
521 | 544 | cb(null, res.sha); |
522 | 545 | }); |
523 | 546 | }; |
|
539 | 562 | }; |
540 | 563 |
|
541 | 564 | _request('POST', repoPath + '/git/trees', data, function (err, res) { |
542 | | - if (err) return cb(err); |
| 565 | + if (err) { |
| 566 | + return cb(err); |
| 567 | + } |
| 568 | + |
543 | 569 | cb(null, res.sha); |
544 | 570 | }); |
545 | 571 | }; |
|
552 | 578 | _request('POST', repoPath + '/git/trees', { |
553 | 579 | tree: tree |
554 | 580 | }, function (err, res) { |
555 | | - if (err) return cb(err); |
| 581 | + if (err) { |
| 582 | + return cb(err); |
| 583 | + } |
| 584 | + |
556 | 585 | cb(null, res.sha); |
557 | 586 | }); |
558 | 587 | }; |
|
565 | 594 | var user = new Github.User(); |
566 | 595 |
|
567 | 596 | user.show(null, function (err, userData) { |
568 | | - if (err) return cb(err); |
| 597 | + if (err) { |
| 598 | + return cb(err); |
| 599 | + } |
| 600 | + |
569 | 601 | var data = { |
570 | 602 | message: message, |
571 | 603 | author: { |
|
579 | 611 | }; |
580 | 612 |
|
581 | 613 | _request('POST', repoPath + '/git/commits', data, function (err, res) { |
582 | | - if (err) return cb(err); |
| 614 | + if (err) { |
| 615 | + return cb(err); |
| 616 | + } |
| 617 | + |
583 | 618 | currentTree.sha = res.sha; // Update latest commit |
584 | 619 | cb(null, res.sha); |
585 | 620 | }); |
|
610 | 645 | var that = this; |
611 | 646 |
|
612 | 647 | _request('GET', repoPath + '/stats/contributors', null, function (err, data, xhr) { |
613 | | - if (err) return cb(err); |
| 648 | + if (err) { |
| 649 | + return cb(err); |
| 650 | + } |
614 | 651 |
|
615 | 652 | if (xhr.status === 202) { |
616 | 653 | setTimeout( |
|
660 | 697 | } |
661 | 698 |
|
662 | 699 | this.getRef('heads/' + oldBranch, function (err, ref) { |
663 | | - if (err && cb) return cb(err); |
| 700 | + if (err && cb) { |
| 701 | + return cb(err); |
| 702 | + } |
| 703 | + |
664 | 704 | that.createRef({ |
665 | 705 | ref: 'refs/heads/' + newBranch, |
666 | 706 | sha: ref |
|
716 | 756 | this.read = function (branch, path, cb) { |
717 | 757 | _request('GET', repoPath + '/contents/' + encodeURI(path) + (branch ? '?ref=' + branch : ''), |
718 | 758 | null, function (err, obj, xhr) { |
719 | | - if (err && err.error === 404) return cb('not found', null, null); |
| 759 | + if (err && err.error === 404) { |
| 760 | + return cb('not found', null, null); |
| 761 | + } |
| 762 | + |
| 763 | + if (err) { |
| 764 | + return cb(err); |
| 765 | + } |
720 | 766 |
|
721 | | - if (err) return cb(err); |
722 | 767 | cb(null, obj, xhr); |
723 | 768 | }, true); |
724 | 769 | }; |
|
728 | 773 |
|
729 | 774 | this.remove = function (branch, path, cb) { |
730 | 775 | that.getSha(branch, path, function (err, sha) { |
731 | | - if (err) return cb(err); |
| 776 | + if (err) { |
| 777 | + return cb(err); |
| 778 | + } |
| 779 | + |
732 | 780 | _request('DELETE', repoPath + '/contents/' + path, { |
733 | 781 | message: path + ' is removed', |
734 | 782 | sha: sha, |
|
749 | 797 | that.getTree(latestCommit + '?recursive=true', function (err, tree) { |
750 | 798 | // Update Tree |
751 | 799 | tree.forEach(function (ref) { |
752 | | - if (ref.path === path) ref.path = newPath; |
| 800 | + if (ref.path === path) { |
| 801 | + ref.path = newPath; |
| 802 | + } |
753 | 803 |
|
754 | | - if (ref.type === 'tree') delete ref.sha; |
| 804 | + if (ref.type === 'tree') { |
| 805 | + delete ref.sha; |
| 806 | + } |
755 | 807 | }); |
756 | 808 |
|
757 | 809 | that.postTree(tree, function (err, rootTree) { |
|
782 | 834 | }; |
783 | 835 |
|
784 | 836 | // If no error, we set the sha to overwrite an existing file |
785 | | - if (!(err && err.error !== 404)) writeOptions.sha = sha; |
| 837 | + if (!(err && err.error !== 404)) { |
| 838 | + writeOptions.sha = sha; |
| 839 | + } |
| 840 | + |
786 | 841 | _request('PUT', repoPath + '/contents/' + encodeURI(path), writeOptions, cb); |
787 | 842 | }); |
788 | 843 | }; |
|
858 | 913 | // -------- |
859 | 914 |
|
860 | 915 | this.star = function(owner, repository, cb) { |
861 | | - _request('PUT', '/user/starred/' + owner + '/' + repository, null, cb) |
| 916 | + _request('PUT', '/user/starred/' + owner + '/' + repository, null, cb); |
862 | 917 | }; |
863 | 918 |
|
864 | 919 | // Unstar a repository. |
865 | 920 | // -------- |
866 | 921 |
|
867 | 922 | this.unstar = function(owner, repository, cb) { |
868 | | - _request('DELETE', '/user/starred/' + owner + '/' + repository, null, cb) |
| 923 | + _request('DELETE', '/user/starred/' + owner + '/' + repository, null, cb); |
869 | 924 | }; |
870 | 925 | }; |
871 | 926 |
|
|
951 | 1006 | this.list = function (options, cb) { |
952 | 1007 | var query = []; |
953 | 1008 |
|
954 | | - for (var key in options) { |
| 1009 | + for(var key in options) { |
955 | 1010 | if (options.hasOwnProperty(key)) { |
956 | 1011 | query.push(encodeURIComponent(key) + '=' + encodeURIComponent(options[key])); |
957 | 1012 | } |
|
998 | 1053 | this.getRateLimit = function(cb) { |
999 | 1054 | _request('GET', '/rate_limit', null, cb); |
1000 | 1055 | }; |
1001 | | - } |
| 1056 | + }; |
1002 | 1057 |
|
1003 | 1058 | return Github; |
1004 | 1059 | }; |
1005 | 1060 |
|
1006 | | -// Top Level API |
1007 | | -// ------- |
| 1061 | + // Top Level API |
| 1062 | + // ------- |
1008 | 1063 |
|
1009 | 1064 | Github.getIssues = function (user, repo) { |
1010 | 1065 | return new Github.Issue({ |
|
0 commit comments