UNPKG

175 kBJavaScriptView Raw
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GitHub = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2'use strict';
3
4var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
5
6var _Requestable2 = require('./Requestable');
7
8var _Requestable3 = _interopRequireDefault(_Requestable2);
9
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
14function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
15
16function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
17 * @file
18 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
19 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
20 * Github.js is freely distributable.
21 */
22
23/**
24 * A Gist can retrieve and modify gists.
25 */
26var Gist = function (_Requestable) {
27 _inherits(Gist, _Requestable);
28
29 /**
30 * Create a Gist.
31 * @param {string} id - the id of the gist (not required when creating a gist)
32 * @param {Requestable.auth} [auth] - information required to authenticate to Github
33 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
34 */
35 function Gist(id, auth, apiBase) {
36 _classCallCheck(this, Gist);
37
38 var _this = _possibleConstructorReturn(this, (Gist.__proto__ || Object.getPrototypeOf(Gist)).call(this, auth, apiBase));
39
40 _this.__id = id;
41 return _this;
42 }
43
44 /**
45 * Fetch a gist.
46 * @see https://developer.github.com/v3/gists/#get-a-single-gist
47 * @param {Requestable.callback} [cb] - will receive the gist
48 * @return {Promise} - the Promise for the http request
49 */
50
51
52 _createClass(Gist, [{
53 key: 'read',
54 value: function read(cb) {
55 return this._request('GET', '/gists/' + this.__id, null, cb);
56 }
57
58 /**
59 * Create a new gist.
60 * @see https://developer.github.com/v3/gists/#create-a-gist
61 * @param {Object} gist - the data for the new gist
62 * @param {Requestable.callback} [cb] - will receive the new gist upon creation
63 * @return {Promise} - the Promise for the http request
64 */
65
66 }, {
67 key: 'create',
68 value: function create(gist, cb) {
69 var _this2 = this;
70
71 return this._request('POST', '/gists', gist, cb).then(function (response) {
72 _this2.__id = response.data.id;
73 return response;
74 });
75 }
76
77 /**
78 * Delete a gist.
79 * @see https://developer.github.com/v3/gists/#delete-a-gist
80 * @param {Requestable.callback} [cb] - will receive true if the request succeeds
81 * @return {Promise} - the Promise for the http request
82 */
83
84 }, {
85 key: 'delete',
86 value: function _delete(cb) {
87 return this._request('DELETE', '/gists/' + this.__id, null, cb);
88 }
89
90 /**
91 * Fork a gist.
92 * @see https://developer.github.com/v3/gists/#fork-a-gist
93 * @param {Requestable.callback} [cb] - the function that will receive the gist
94 * @return {Promise} - the Promise for the http request
95 */
96
97 }, {
98 key: 'fork',
99 value: function fork(cb) {
100 return this._request('POST', '/gists/' + this.__id + '/forks', null, cb);
101 }
102
103 /**
104 * Update a gist.
105 * @see https://developer.github.com/v3/gists/#edit-a-gist
106 * @param {Object} gist - the new data for the gist
107 * @param {Requestable.callback} [cb] - the function that receives the API result
108 * @return {Promise} - the Promise for the http request
109 */
110
111 }, {
112 key: 'update',
113 value: function update(gist, cb) {
114 return this._request('PATCH', '/gists/' + this.__id, gist, cb);
115 }
116
117 /**
118 * Star a gist.
119 * @see https://developer.github.com/v3/gists/#star-a-gist
120 * @param {Requestable.callback} [cb] - will receive true if the request is successful
121 * @return {Promise} - the Promise for the http request
122 */
123
124 }, {
125 key: 'star',
126 value: function star(cb) {
127 return this._request('PUT', '/gists/' + this.__id + '/star', null, cb);
128 }
129
130 /**
131 * Unstar a gist.
132 * @see https://developer.github.com/v3/gists/#unstar-a-gist
133 * @param {Requestable.callback} [cb] - will receive true if the request is successful
134 * @return {Promise} - the Promise for the http request
135 */
136
137 }, {
138 key: 'unstar',
139 value: function unstar(cb) {
140 return this._request('DELETE', '/gists/' + this.__id + '/star', null, cb);
141 }
142
143 /**
144 * Check if a gist is starred by the user.
145 * @see https://developer.github.com/v3/gists/#check-if-a-gist-is-starred
146 * @param {Requestable.callback} [cb] - will receive true if the gist is starred and false if the gist is not starred
147 * @return {Promise} - the Promise for the http request
148 */
149
150 }, {
151 key: 'isStarred',
152 value: function isStarred(cb) {
153 return this._request204or404('/gists/' + this.__id + '/star', null, cb);
154 }
155
156 /**
157 * List the gist's commits
158 * @see https://developer.github.com/v3/gists/#list-gist-commits
159 * @param {Requestable.callback} [cb] - will receive the array of commits
160 * @return {Promise} - the Promise for the http request
161 */
162
163 }, {
164 key: 'listCommits',
165 value: function listCommits(cb) {
166 return this._requestAllPages('/gists/' + this.__id + '/commits', null, cb);
167 }
168
169 /**
170 * Fetch one of the gist's revision.
171 * @see https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
172 * @param {string} revision - the id of the revision
173 * @param {Requestable.callback} [cb] - will receive the revision
174 * @return {Promise} - the Promise for the http request
175 */
176
177 }, {
178 key: 'getRevision',
179 value: function getRevision(revision, cb) {
180 return this._request('GET', '/gists/' + this.__id + '/' + revision, null, cb);
181 }
182
183 /**
184 * List the gist's comments
185 * @see https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
186 * @param {Requestable.callback} [cb] - will receive the array of comments
187 * @return {Promise} - the promise for the http request
188 */
189
190 }, {
191 key: 'listComments',
192 value: function listComments(cb) {
193 return this._requestAllPages('/gists/' + this.__id + '/comments', null, cb);
194 }
195
196 /**
197 * Fetch one of the gist's comments
198 * @see https://developer.github.com/v3/gists/comments/#get-a-single-comment
199 * @param {number} comment - the id of the comment
200 * @param {Requestable.callback} [cb] - will receive the comment
201 * @return {Promise} - the Promise for the http request
202 */
203
204 }, {
205 key: 'getComment',
206 value: function getComment(comment, cb) {
207 return this._request('GET', '/gists/' + this.__id + '/comments/' + comment, null, cb);
208 }
209
210 /**
211 * Comment on a gist
212 * @see https://developer.github.com/v3/gists/comments/#create-a-comment
213 * @param {string} comment - the comment to add
214 * @param {Requestable.callback} [cb] - the function that receives the API result
215 * @return {Promise} - the Promise for the http request
216 */
217
218 }, {
219 key: 'createComment',
220 value: function createComment(comment, cb) {
221 return this._request('POST', '/gists/' + this.__id + '/comments', { body: comment }, cb);
222 }
223
224 /**
225 * Edit a comment on the gist
226 * @see https://developer.github.com/v3/gists/comments/#edit-a-comment
227 * @param {number} comment - the id of the comment
228 * @param {string} body - the new comment
229 * @param {Requestable.callback} [cb] - will receive the modified comment
230 * @return {Promise} - the promise for the http request
231 */
232
233 }, {
234 key: 'editComment',
235 value: function editComment(comment, body, cb) {
236 return this._request('PATCH', '/gists/' + this.__id + '/comments/' + comment, { body: body }, cb);
237 }
238
239 /**
240 * Delete a comment on the gist.
241 * @see https://developer.github.com/v3/gists/comments/#delete-a-comment
242 * @param {number} comment - the id of the comment
243 * @param {Requestable.callback} [cb] - will receive true if the request succeeds
244 * @return {Promise} - the Promise for the http request
245 */
246
247 }, {
248 key: 'deleteComment',
249 value: function deleteComment(comment, cb) {
250 return this._request('DELETE', '/gists/' + this.__id + '/comments/' + comment, null, cb);
251 }
252 }]);
253
254 return Gist;
255}(_Requestable3.default);
256
257module.exports = Gist;
258
259},{"./Requestable":9}],2:[function(require,module,exports){
260'use strict';
261
262var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
263 * @file
264 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
265 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
266 * Github.js is freely distributable.
267 */
268/* eslint valid-jsdoc: ["error", {"requireReturnDescription": false}] */
269
270var _Gist = require('./Gist');
271
272var _Gist2 = _interopRequireDefault(_Gist);
273
274var _User = require('./User');
275
276var _User2 = _interopRequireDefault(_User);
277
278var _Issue = require('./Issue');
279
280var _Issue2 = _interopRequireDefault(_Issue);
281
282var _Search = require('./Search');
283
284var _Search2 = _interopRequireDefault(_Search);
285
286var _RateLimit = require('./RateLimit');
287
288var _RateLimit2 = _interopRequireDefault(_RateLimit);
289
290var _Repository = require('./Repository');
291
292var _Repository2 = _interopRequireDefault(_Repository);
293
294var _Organization = require('./Organization');
295
296var _Organization2 = _interopRequireDefault(_Organization);
297
298var _Team = require('./Team');
299
300var _Team2 = _interopRequireDefault(_Team);
301
302var _Markdown = require('./Markdown');
303
304var _Markdown2 = _interopRequireDefault(_Markdown);
305
306var _Project = require('./Project');
307
308var _Project2 = _interopRequireDefault(_Project);
309
310function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
311
312function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
313
314/**
315 * GitHub encapsulates the functionality to create various API wrapper objects.
316 */
317var GitHub = function () {
318 /**
319 * Create a new GitHub.
320 * @param {Requestable.auth} [auth] - the credentials to authenticate to Github. If auth is
321 * not provided requests will be made unauthenticated
322 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
323 */
324 function GitHub(auth) {
325 var apiBase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'https://api.github.com';
326
327 _classCallCheck(this, GitHub);
328
329 this.__apiBase = apiBase;
330 this.__auth = auth || {};
331 }
332
333 /**
334 * Create a new Gist wrapper
335 * @param {string} [id] - the id for the gist, leave undefined when creating a new gist
336 * @return {Gist}
337 */
338
339
340 _createClass(GitHub, [{
341 key: 'getGist',
342 value: function getGist(id) {
343 return new _Gist2.default(id, this.__auth, this.__apiBase);
344 }
345
346 /**
347 * Create a new User wrapper
348 * @param {string} [user] - the name of the user to get information about
349 * leave undefined for the authenticated user
350 * @return {User}
351 */
352
353 }, {
354 key: 'getUser',
355 value: function getUser(user) {
356 return new _User2.default(user, this.__auth, this.__apiBase);
357 }
358
359 /**
360 * Create a new Organization wrapper
361 * @param {string} organization - the name of the organization
362 * @return {Organization}
363 */
364
365 }, {
366 key: 'getOrganization',
367 value: function getOrganization(organization) {
368 return new _Organization2.default(organization, this.__auth, this.__apiBase);
369 }
370
371 /**
372 * create a new Team wrapper
373 * @param {string} teamId - the name of the team
374 * @return {team}
375 */
376
377 }, {
378 key: 'getTeam',
379 value: function getTeam(teamId) {
380 return new _Team2.default(teamId, this.__auth, this.__apiBase);
381 }
382
383 /**
384 * Create a new Repository wrapper
385 * @param {string} user - the user who owns the repository
386 * @param {string} repo - the name of the repository
387 * @return {Repository}
388 */
389
390 }, {
391 key: 'getRepo',
392 value: function getRepo(user, repo) {
393 return new _Repository2.default(this._getFullName(user, repo), this.__auth, this.__apiBase);
394 }
395
396 /**
397 * Create a new Issue wrapper
398 * @param {string} user - the user who owns the repository
399 * @param {string} repo - the name of the repository
400 * @return {Issue}
401 */
402
403 }, {
404 key: 'getIssues',
405 value: function getIssues(user, repo) {
406 return new _Issue2.default(this._getFullName(user, repo), this.__auth, this.__apiBase);
407 }
408
409 /**
410 * Create a new Search wrapper
411 * @param {string} query - the query to search for
412 * @return {Search}
413 */
414
415 }, {
416 key: 'search',
417 value: function search(query) {
418 return new _Search2.default(query, this.__auth, this.__apiBase);
419 }
420
421 /**
422 * Create a new RateLimit wrapper
423 * @return {RateLimit}
424 */
425
426 }, {
427 key: 'getRateLimit',
428 value: function getRateLimit() {
429 return new _RateLimit2.default(this.__auth, this.__apiBase);
430 }
431
432 /**
433 * Create a new Markdown wrapper
434 * @return {Markdown}
435 */
436
437 }, {
438 key: 'getMarkdown',
439 value: function getMarkdown() {
440 return new _Markdown2.default(this.__auth, this.__apiBase);
441 }
442
443 /**
444 * Create a new Project wrapper
445 * @param {string} id - the id of the project
446 * @return {Project}
447 */
448
449 }, {
450 key: 'getProject',
451 value: function getProject(id) {
452 return new _Project2.default(id, this.__auth, this.__apiBase);
453 }
454
455 /**
456 * Computes the full repository name
457 * @param {string} user - the username (or the full name)
458 * @param {string} repo - the repository name, must not be passed if `user` is the full name
459 * @return {string} the repository's full name
460 */
461
462 }, {
463 key: '_getFullName',
464 value: function _getFullName(user, repo) {
465 var fullname = user;
466
467 if (repo) {
468 fullname = user + '/' + repo;
469 }
470
471 return fullname;
472 }
473 }]);
474
475 return GitHub;
476}();
477
478module.exports = GitHub;
479
480},{"./Gist":1,"./Issue":3,"./Markdown":4,"./Organization":5,"./Project":6,"./RateLimit":7,"./Repository":8,"./Search":10,"./Team":11,"./User":12}],3:[function(require,module,exports){
481'use strict';
482
483var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
484
485var _Requestable2 = require('./Requestable');
486
487var _Requestable3 = _interopRequireDefault(_Requestable2);
488
489function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
490
491function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
492
493function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
494
495function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
496 * @file
497 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
498 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
499 * Github.js is freely distributable.
500 */
501
502/**
503 * Issue wraps the functionality to get issues for repositories
504 */
505var Issue = function (_Requestable) {
506 _inherits(Issue, _Requestable);
507
508 /**
509 * Create a new Issue
510 * @param {string} repository - the full name of the repository (`:user/:repo`) to get issues for
511 * @param {Requestable.auth} [auth] - information required to authenticate to Github
512 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
513 */
514 function Issue(repository, auth, apiBase) {
515 _classCallCheck(this, Issue);
516
517 var _this = _possibleConstructorReturn(this, (Issue.__proto__ || Object.getPrototypeOf(Issue)).call(this, auth, apiBase));
518
519 _this.__repository = repository;
520 return _this;
521 }
522
523 /**
524 * Create a new issue
525 * @see https://developer.github.com/v3/issues/#create-an-issue
526 * @param {Object} issueData - the issue to create
527 * @param {Requestable.callback} [cb] - will receive the created issue
528 * @return {Promise} - the promise for the http request
529 */
530
531
532 _createClass(Issue, [{
533 key: 'createIssue',
534 value: function createIssue(issueData, cb) {
535 return this._request('POST', '/repos/' + this.__repository + '/issues', issueData, cb);
536 }
537
538 /**
539 * List the issues for the repository
540 * @see https://developer.github.com/v3/issues/#list-issues-for-a-repository
541 * @param {Object} options - filtering options
542 * @param {Requestable.callback} [cb] - will receive the array of issues
543 * @return {Promise} - the promise for the http request
544 */
545
546 }, {
547 key: 'listIssues',
548 value: function listIssues(options, cb) {
549 return this._requestAllPages('/repos/' + this.__repository + '/issues', options, cb);
550 }
551
552 /**
553 * List the events for an issue
554 * @see https://developer.github.com/v3/issues/events/#list-events-for-an-issue
555 * @param {number} issue - the issue to get events for
556 * @param {Requestable.callback} [cb] - will receive the list of events
557 * @return {Promise} - the promise for the http request
558 */
559
560 }, {
561 key: 'listIssueEvents',
562 value: function listIssueEvents(issue, cb) {
563 return this._request('GET', '/repos/' + this.__repository + '/issues/' + issue + '/events', null, cb);
564 }
565
566 /**
567 * List comments on an issue
568 * @see https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
569 * @param {number} issue - the id of the issue to get comments from
570 * @param {Requestable.callback} [cb] - will receive the comments
571 * @return {Promise} - the promise for the http request
572 */
573
574 }, {
575 key: 'listIssueComments',
576 value: function listIssueComments(issue, cb) {
577 return this._request('GET', '/repos/' + this.__repository + '/issues/' + issue + '/comments', null, cb);
578 }
579
580 /**
581 * Get a single comment on an issue
582 * @see https://developer.github.com/v3/issues/comments/#get-a-single-comment
583 * @param {number} id - the comment id to get
584 * @param {Requestable.callback} [cb] - will receive the comment
585 * @return {Promise} - the promise for the http request
586 */
587
588 }, {
589 key: 'getIssueComment',
590 value: function getIssueComment(id, cb) {
591 return this._request('GET', '/repos/' + this.__repository + '/issues/comments/' + id, null, cb);
592 }
593
594 /**
595 * Comment on an issue
596 * @see https://developer.github.com/v3/issues/comments/#create-a-comment
597 * @param {number} issue - the id of the issue to comment on
598 * @param {string} comment - the comment to add
599 * @param {Requestable.callback} [cb] - will receive the created comment
600 * @return {Promise} - the promise for the http request
601 */
602
603 }, {
604 key: 'createIssueComment',
605 value: function createIssueComment(issue, comment, cb) {
606 return this._request('POST', '/repos/' + this.__repository + '/issues/' + issue + '/comments', { body: comment }, cb);
607 }
608
609 /**
610 * Edit a comment on an issue
611 * @see https://developer.github.com/v3/issues/comments/#edit-a-comment
612 * @param {number} id - the comment id to edit
613 * @param {string} comment - the comment to edit
614 * @param {Requestable.callback} [cb] - will receive the edited comment
615 * @return {Promise} - the promise for the http request
616 */
617
618 }, {
619 key: 'editIssueComment',
620 value: function editIssueComment(id, comment, cb) {
621 return this._request('PATCH', '/repos/' + this.__repository + '/issues/comments/' + id, { body: comment }, cb);
622 }
623
624 /**
625 * Delete a comment on an issue
626 * @see https://developer.github.com/v3/issues/comments/#delete-a-comment
627 * @param {number} id - the comment id to delete
628 * @param {Requestable.callback} [cb] - will receive true if the request is successful
629 * @return {Promise} - the promise for the http request
630 */
631
632 }, {
633 key: 'deleteIssueComment',
634 value: function deleteIssueComment(id, cb) {
635 return this._request('DELETE', '/repos/' + this.__repository + '/issues/comments/' + id, null, cb);
636 }
637
638 /**
639 * Edit an issue
640 * @see https://developer.github.com/v3/issues/#edit-an-issue
641 * @param {number} issue - the issue number to edit
642 * @param {Object} issueData - the new issue data
643 * @param {Requestable.callback} [cb] - will receive the modified issue
644 * @return {Promise} - the promise for the http request
645 */
646
647 }, {
648 key: 'editIssue',
649 value: function editIssue(issue, issueData, cb) {
650 return this._request('PATCH', '/repos/' + this.__repository + '/issues/' + issue, issueData, cb);
651 }
652
653 /**
654 * Get a particular issue
655 * @see https://developer.github.com/v3/issues/#get-a-single-issue
656 * @param {number} issue - the issue number to fetch
657 * @param {Requestable.callback} [cb] - will receive the issue
658 * @return {Promise} - the promise for the http request
659 */
660
661 }, {
662 key: 'getIssue',
663 value: function getIssue(issue, cb) {
664 return this._request('GET', '/repos/' + this.__repository + '/issues/' + issue, null, cb);
665 }
666
667 /**
668 * List the milestones for the repository
669 * @see https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
670 * @param {Object} options - filtering options
671 * @param {Requestable.callback} [cb] - will receive the array of milestones
672 * @return {Promise} - the promise for the http request
673 */
674
675 }, {
676 key: 'listMilestones',
677 value: function listMilestones(options, cb) {
678 return this._request('GET', '/repos/' + this.__repository + '/milestones', options, cb);
679 }
680
681 /**
682 * Get a milestone
683 * @see https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
684 * @param {string} milestone - the id of the milestone to fetch
685 * @param {Requestable.callback} [cb] - will receive the milestone
686 * @return {Promise} - the promise for the http request
687 */
688
689 }, {
690 key: 'getMilestone',
691 value: function getMilestone(milestone, cb) {
692 return this._request('GET', '/repos/' + this.__repository + '/milestones/' + milestone, null, cb);
693 }
694
695 /**
696 * Create a new milestone
697 * @see https://developer.github.com/v3/issues/milestones/#create-a-milestone
698 * @param {Object} milestoneData - the milestone definition
699 * @param {Requestable.callback} [cb] - will receive the milestone
700 * @return {Promise} - the promise for the http request
701 */
702
703 }, {
704 key: 'createMilestone',
705 value: function createMilestone(milestoneData, cb) {
706 return this._request('POST', '/repos/' + this.__repository + '/milestones', milestoneData, cb);
707 }
708
709 /**
710 * Edit a milestone
711 * @see https://developer.github.com/v3/issues/milestones/#update-a-milestone
712 * @param {string} milestone - the id of the milestone to edit
713 * @param {Object} milestoneData - the updates to make to the milestone
714 * @param {Requestable.callback} [cb] - will receive the updated milestone
715 * @return {Promise} - the promise for the http request
716 */
717
718 }, {
719 key: 'editMilestone',
720 value: function editMilestone(milestone, milestoneData, cb) {
721 return this._request('PATCH', '/repos/' + this.__repository + '/milestones/' + milestone, milestoneData, cb);
722 }
723
724 /**
725 * Delete a milestone (this is distinct from closing a milestone)
726 * @see https://developer.github.com/v3/issues/milestones/#delete-a-milestone
727 * @param {string} milestone - the id of the milestone to delete
728 * @param {Requestable.callback} [cb] - will receive the status
729 * @return {Promise} - the promise for the http request
730 */
731
732 }, {
733 key: 'deleteMilestone',
734 value: function deleteMilestone(milestone, cb) {
735 return this._request('DELETE', '/repos/' + this.__repository + '/milestones/' + milestone, null, cb);
736 }
737
738 /**
739 * Create a new label
740 * @see https://developer.github.com/v3/issues/labels/#create-a-label
741 * @param {Object} labelData - the label definition
742 * @param {Requestable.callback} [cb] - will receive the object representing the label
743 * @return {Promise} - the promise for the http request
744 */
745
746 }, {
747 key: 'createLabel',
748 value: function createLabel(labelData, cb) {
749 return this._request('POST', '/repos/' + this.__repository + '/labels', labelData, cb);
750 }
751
752 /**
753 * List the labels for the repository
754 * @see https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
755 * @param {Object} options - filtering options
756 * @param {Requestable.callback} [cb] - will receive the array of labels
757 * @return {Promise} - the promise for the http request
758 */
759
760 }, {
761 key: 'listLabels',
762 value: function listLabels(options, cb) {
763 return this._request('GET', '/repos/' + this.__repository + '/labels', options, cb);
764 }
765
766 /**
767 * Get a label
768 * @see https://developer.github.com/v3/issues/labels/#get-a-single-label
769 * @param {string} label - the name of the label to fetch
770 * @param {Requestable.callback} [cb] - will receive the label
771 * @return {Promise} - the promise for the http request
772 */
773
774 }, {
775 key: 'getLabel',
776 value: function getLabel(label, cb) {
777 return this._request('GET', '/repos/' + this.__repository + '/labels/' + label, null, cb);
778 }
779
780 /**
781 * Edit a label
782 * @see https://developer.github.com/v3/issues/labels/#update-a-label
783 * @param {string} label - the name of the label to edit
784 * @param {Object} labelData - the updates to make to the label
785 * @param {Requestable.callback} [cb] - will receive the updated label
786 * @return {Promise} - the promise for the http request
787 */
788
789 }, {
790 key: 'editLabel',
791 value: function editLabel(label, labelData, cb) {
792 return this._request('PATCH', '/repos/' + this.__repository + '/labels/' + label, labelData, cb);
793 }
794
795 /**
796 * Delete a label
797 * @see https://developer.github.com/v3/issues/labels/#delete-a-label
798 * @param {string} label - the name of the label to delete
799 * @param {Requestable.callback} [cb] - will receive the status
800 * @return {Promise} - the promise for the http request
801 */
802
803 }, {
804 key: 'deleteLabel',
805 value: function deleteLabel(label, cb) {
806 return this._request('DELETE', '/repos/' + this.__repository + '/labels/' + label, null, cb);
807 }
808 }]);
809
810 return Issue;
811}(_Requestable3.default);
812
813module.exports = Issue;
814
815},{"./Requestable":9}],4:[function(require,module,exports){
816'use strict';
817
818var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
819
820var _Requestable2 = require('./Requestable');
821
822var _Requestable3 = _interopRequireDefault(_Requestable2);
823
824function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
825
826function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
827
828function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
829
830function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
831 * @file
832 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
833 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
834 * Github.js is freely distributable.
835 */
836
837/**
838 * Renders html from Markdown text
839 */
840var Markdown = function (_Requestable) {
841 _inherits(Markdown, _Requestable);
842
843 /**
844 * construct a Markdown
845 * @param {Requestable.auth} auth - the credentials to authenticate to GitHub
846 * @param {string} [apiBase] - the base Github API URL
847 * @return {Promise} - the promise for the http request
848 */
849 function Markdown(auth, apiBase) {
850 _classCallCheck(this, Markdown);
851
852 return _possibleConstructorReturn(this, (Markdown.__proto__ || Object.getPrototypeOf(Markdown)).call(this, auth, apiBase));
853 }
854
855 /**
856 * Render html from Markdown text.
857 * @see https://developer.github.com/v3/markdown/#render-an-arbitrary-markdown-document
858 * @param {Object} options - conversion options
859 * @param {string} [options.text] - the markdown text to convert
860 * @param {string} [options.mode=markdown] - can be either `markdown` or `gfm`
861 * @param {string} [options.context] - repository name if mode is gfm
862 * @param {Requestable.callback} [cb] - will receive the converted html
863 * @return {Promise} - the promise for the http request
864 */
865
866
867 _createClass(Markdown, [{
868 key: 'render',
869 value: function render(options, cb) {
870 return this._request('POST', '/markdown', options, cb, true);
871 }
872 }]);
873
874 return Markdown;
875}(_Requestable3.default);
876
877module.exports = Markdown;
878
879},{"./Requestable":9}],5:[function(require,module,exports){
880'use strict';
881
882var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
883
884var _Requestable2 = require('./Requestable');
885
886var _Requestable3 = _interopRequireDefault(_Requestable2);
887
888function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
889
890function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
891
892function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
893
894function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
895 * @file
896 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
897 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
898 * Github.js is freely distributable.
899 */
900
901/**
902 * Organization encapsulates the functionality to create repositories in organizations
903 */
904var Organization = function (_Requestable) {
905 _inherits(Organization, _Requestable);
906
907 /**
908 * Create a new Organization
909 * @param {string} organization - the name of the organization
910 * @param {Requestable.auth} [auth] - information required to authenticate to Github
911 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
912 */
913 function Organization(organization, auth, apiBase) {
914 _classCallCheck(this, Organization);
915
916 var _this = _possibleConstructorReturn(this, (Organization.__proto__ || Object.getPrototypeOf(Organization)).call(this, auth, apiBase));
917
918 _this.__name = organization;
919 return _this;
920 }
921
922 /**
923 * Create a repository in an organization
924 * @see https://developer.github.com/v3/repos/#create
925 * @param {Object} options - the repository definition
926 * @param {Requestable.callback} [cb] - will receive the created repository
927 * @return {Promise} - the promise for the http request
928 */
929
930
931 _createClass(Organization, [{
932 key: 'createRepo',
933 value: function createRepo(options, cb) {
934 return this._request('POST', '/orgs/' + this.__name + '/repos', options, cb);
935 }
936
937 /**
938 * List the repositories in an organization
939 * @see https://developer.github.com/v3/repos/#list-organization-repositories
940 * @param {Requestable.callback} [cb] - will receive the list of repositories
941 * @return {Promise} - the promise for the http request
942 */
943
944 }, {
945 key: 'getRepos',
946 value: function getRepos(cb) {
947 var requestOptions = this._getOptionsWithDefaults({ direction: 'desc' });
948
949 return this._requestAllPages('/orgs/' + this.__name + '/repos', requestOptions, cb);
950 }
951
952 /**
953 * Query if the user is a member or not
954 * @param {string} username - the user in question
955 * @param {Requestable.callback} [cb] - will receive true if the user is a member
956 * @return {Promise} - the promise for the http request
957 */
958
959 }, {
960 key: 'isMember',
961 value: function isMember(username, cb) {
962 return this._request204or404('/orgs/' + this.__name + '/members/' + username, null, cb);
963 }
964
965 /**
966 * List the users who are members of the company
967 * @see https://developer.github.com/v3/orgs/members/#members-list
968 * @param {object} options - filtering options
969 * @param {string} [options.filter=all] - can be either `2fa_disabled` or `all`
970 * @param {string} [options.role=all] - can be one of: `all`, `admin`, or `member`
971 * @param {Requestable.callback} [cb] - will receive the list of users
972 * @return {Promise} - the promise for the http request
973 */
974
975 }, {
976 key: 'listMembers',
977 value: function listMembers(options, cb) {
978 return this._request('GET', '/orgs/' + this.__name + '/members', options, cb);
979 }
980
981 /**
982 * List the Teams in the Organization
983 * @see https://developer.github.com/v3/orgs/teams/#list-teams
984 * @param {Requestable.callback} [cb] - will receive the list of teams
985 * @return {Promise} - the promise for the http request
986 */
987
988 }, {
989 key: 'getTeams',
990 value: function getTeams(cb) {
991 return this._requestAllPages('/orgs/' + this.__name + '/teams', undefined, cb);
992 }
993
994 /**
995 * Create a team
996 * @see https://developer.github.com/v3/orgs/teams/#create-team
997 * @param {object} options - Team creation parameters
998 * @param {string} options.name - The name of the team
999 * @param {string} [options.description] - Team description
1000 * @param {string} [options.repo_names] - Repos to add the team to
1001 * @param {string} [options.privacy=secret] - The level of privacy the team should have. Can be either one
1002 * of: `secret`, or `closed`
1003 * @param {Requestable.callback} [cb] - will receive the created team
1004 * @return {Promise} - the promise for the http request
1005 */
1006
1007 }, {
1008 key: 'createTeam',
1009 value: function createTeam(options, cb) {
1010 return this._request('POST', '/orgs/' + this.__name + '/teams', options, cb);
1011 }
1012
1013 /**
1014 * Get information about all projects
1015 * @see https://developer.github.com/v3/projects/#list-organization-projects
1016 * @param {Requestable.callback} [cb] - will receive the list of projects
1017 * @return {Promise} - the promise for the http request
1018 */
1019
1020 }, {
1021 key: 'listProjects',
1022 value: function listProjects(cb) {
1023 return this._requestAllPages('/orgs/' + this.__name + '/projects', { AcceptHeader: 'inertia-preview' }, cb);
1024 }
1025
1026 /**
1027 * Create a new project
1028 * @see https://developer.github.com/v3/repos/projects/#create-a-project
1029 * @param {Object} options - the description of the project
1030 * @param {Requestable.callback} cb - will receive the newly created project
1031 * @return {Promise} - the promise for the http request
1032 */
1033
1034 }, {
1035 key: 'createProject',
1036 value: function createProject(options, cb) {
1037 options = options || {};
1038 options.AcceptHeader = 'inertia-preview';
1039 return this._request('POST', '/orgs/' + this.__name + '/projects', options, cb);
1040 }
1041 }]);
1042
1043 return Organization;
1044}(_Requestable3.default);
1045
1046module.exports = Organization;
1047
1048},{"./Requestable":9}],6:[function(require,module,exports){
1049'use strict';
1050
1051var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1052
1053var _Requestable2 = require('./Requestable');
1054
1055var _Requestable3 = _interopRequireDefault(_Requestable2);
1056
1057function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1058
1059function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
1060
1061function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1062
1063function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1064
1065function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
1066 * @file
1067 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
1068 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
1069 * Github.js is freely distributable.
1070 */
1071
1072/**
1073 * Project encapsulates the functionality to create, query, and modify cards and columns.
1074 */
1075var Project = function (_Requestable) {
1076 _inherits(Project, _Requestable);
1077
1078 /**
1079 * Create a Project.
1080 * @param {string} id - the id of the project
1081 * @param {Requestable.auth} [auth] - information required to authenticate to Github
1082 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
1083 */
1084 function Project(id, auth, apiBase) {
1085 _classCallCheck(this, Project);
1086
1087 var _this = _possibleConstructorReturn(this, (Project.__proto__ || Object.getPrototypeOf(Project)).call(this, auth, apiBase, 'inertia-preview'));
1088
1089 _this.__id = id;
1090 return _this;
1091 }
1092
1093 /**
1094 * Get information about a project
1095 * @see https://developer.github.com/v3/projects/#get-a-project
1096 * @param {Requestable.callback} cb - will receive the project information
1097 * @return {Promise} - the promise for the http request
1098 */
1099
1100
1101 _createClass(Project, [{
1102 key: 'getProject',
1103 value: function getProject(cb) {
1104 return this._request('GET', '/projects/' + this.__id, null, cb);
1105 }
1106
1107 /**
1108 * Edit a project
1109 * @see https://developer.github.com/v3/projects/#update-a-project
1110 * @param {Object} options - the description of the project
1111 * @param {Requestable.callback} cb - will receive the modified project
1112 * @return {Promise} - the promise for the http request
1113 */
1114
1115 }, {
1116 key: 'updateProject',
1117 value: function updateProject(options, cb) {
1118 return this._request('PATCH', '/projects/' + this.__id, options, cb);
1119 }
1120
1121 /**
1122 * Delete a project
1123 * @see https://developer.github.com/v3/projects/#delete-a-project
1124 * @param {Requestable.callback} cb - will receive true if the operation is successful
1125 * @return {Promise} - the promise for the http request
1126 */
1127
1128 }, {
1129 key: 'deleteProject',
1130 value: function deleteProject(cb) {
1131 return this._request('DELETE', '/projects/' + this.__id, null, cb);
1132 }
1133
1134 /**
1135 * Get information about all columns of a project
1136 * @see https://developer.github.com/v3/projects/columns/#list-project-columns
1137 * @param {Requestable.callback} [cb] - will receive the list of columns
1138 * @return {Promise} - the promise for the http request
1139 */
1140
1141 }, {
1142 key: 'listProjectColumns',
1143 value: function listProjectColumns(cb) {
1144 return this._requestAllPages('/projects/' + this.__id + '/columns', null, cb);
1145 }
1146
1147 /**
1148 * Get information about a column
1149 * @see https://developer.github.com/v3/projects/columns/#get-a-project-column
1150 * @param {string} colId - the id of the column
1151 * @param {Requestable.callback} cb - will receive the column information
1152 * @return {Promise} - the promise for the http request
1153 */
1154
1155 }, {
1156 key: 'getProjectColumn',
1157 value: function getProjectColumn(colId, cb) {
1158 return this._request('GET', '/projects/columns/' + colId, null, cb);
1159 }
1160
1161 /**
1162 * Create a new column
1163 * @see https://developer.github.com/v3/projects/columns/#create-a-project-column
1164 * @param {Object} options - the description of the column
1165 * @param {Requestable.callback} cb - will receive the newly created column
1166 * @return {Promise} - the promise for the http request
1167 */
1168
1169 }, {
1170 key: 'createProjectColumn',
1171 value: function createProjectColumn(options, cb) {
1172 return this._request('POST', '/projects/' + this.__id + '/columns', options, cb);
1173 }
1174
1175 /**
1176 * Edit a column
1177 * @see https://developer.github.com/v3/projects/columns/#update-a-project-column
1178 * @param {string} colId - the column id
1179 * @param {Object} options - the description of the column
1180 * @param {Requestable.callback} cb - will receive the modified column
1181 * @return {Promise} - the promise for the http request
1182 */
1183
1184 }, {
1185 key: 'updateProjectColumn',
1186 value: function updateProjectColumn(colId, options, cb) {
1187 return this._request('PATCH', '/projects/columns/' + colId, options, cb);
1188 }
1189
1190 /**
1191 * Delete a column
1192 * @see https://developer.github.com/v3/projects/columns/#delete-a-project-column
1193 * @param {string} colId - the column to be deleted
1194 * @param {Requestable.callback} cb - will receive true if the operation is successful
1195 * @return {Promise} - the promise for the http request
1196 */
1197
1198 }, {
1199 key: 'deleteProjectColumn',
1200 value: function deleteProjectColumn(colId, cb) {
1201 return this._request('DELETE', '/projects/columns/' + colId, null, cb);
1202 }
1203
1204 /**
1205 * Move a column
1206 * @see https://developer.github.com/v3/projects/columns/#move-a-project-column
1207 * @param {string} colId - the column to be moved
1208 * @param {string} position - can be one of first, last, or after:<column-id>,
1209 * where <column-id> is the id value of a column in the same project.
1210 * @param {Requestable.callback} cb - will receive true if the operation is successful
1211 * @return {Promise} - the promise for the http request
1212 */
1213
1214 }, {
1215 key: 'moveProjectColumn',
1216 value: function moveProjectColumn(colId, position, cb) {
1217 return this._request('POST', '/projects/columns/' + colId + '/moves', { position: position }, cb);
1218 }
1219
1220 /**
1221 * Get information about all cards of a project
1222 * @see https://developer.github.com/v3/projects/cards/#list-project-cards
1223 * @param {Requestable.callback} [cb] - will receive the list of cards
1224 * @return {Promise} - the promise for the http request
1225 */
1226
1227 }, {
1228 key: 'listProjectCards',
1229 value: function listProjectCards(cb) {
1230 var _this2 = this;
1231
1232 return this.listProjectColumns().then(function (_ref) {
1233 var data = _ref.data;
1234
1235 return Promise.all(data.map(function (column) {
1236 return _this2._requestAllPages('/projects/columns/' + column.id + '/cards', null);
1237 }));
1238 }).then(function (cardsInColumns) {
1239 var cards = cardsInColumns.reduce(function (prev, _ref2) {
1240 var data = _ref2.data;
1241
1242 prev.push.apply(prev, _toConsumableArray(data));
1243 return prev;
1244 }, []);
1245 if (cb) {
1246 cb(null, cards);
1247 }
1248 return cards;
1249 }).catch(function (err) {
1250 if (cb) {
1251 cb(err);
1252 return;
1253 }
1254 throw err;
1255 });
1256 }
1257
1258 /**
1259 * Get information about all cards of a column
1260 * @see https://developer.github.com/v3/projects/cards/#list-project-cards
1261 * @param {string} colId - the id of the column
1262 * @param {Requestable.callback} [cb] - will receive the list of cards
1263 * @return {Promise} - the promise for the http request
1264 */
1265
1266 }, {
1267 key: 'listColumnCards',
1268 value: function listColumnCards(colId, cb) {
1269 return this._requestAllPages('/projects/columns/' + colId + '/cards', null, cb);
1270 }
1271
1272 /**
1273 * Get information about a card
1274 * @see https://developer.github.com/v3/projects/cards/#get-a-project-card
1275 * @param {string} cardId - the id of the card
1276 * @param {Requestable.callback} cb - will receive the card information
1277 * @return {Promise} - the promise for the http request
1278 */
1279
1280 }, {
1281 key: 'getProjectCard',
1282 value: function getProjectCard(cardId, cb) {
1283 return this._request('GET', '/projects/columns/cards/' + cardId, null, cb);
1284 }
1285
1286 /**
1287 * Create a new card
1288 * @see https://developer.github.com/v3/projects/cards/#create-a-project-card
1289 * @param {string} colId - the column id
1290 * @param {Object} options - the description of the card
1291 * @param {Requestable.callback} cb - will receive the newly created card
1292 * @return {Promise} - the promise for the http request
1293 */
1294
1295 }, {
1296 key: 'createProjectCard',
1297 value: function createProjectCard(colId, options, cb) {
1298 return this._request('POST', '/projects/columns/' + colId + '/cards', options, cb);
1299 }
1300
1301 /**
1302 * Edit a card
1303 * @see https://developer.github.com/v3/projects/cards/#update-a-project-card
1304 * @param {string} cardId - the card id
1305 * @param {Object} options - the description of the card
1306 * @param {Requestable.callback} cb - will receive the modified card
1307 * @return {Promise} - the promise for the http request
1308 */
1309
1310 }, {
1311 key: 'updateProjectCard',
1312 value: function updateProjectCard(cardId, options, cb) {
1313 return this._request('PATCH', '/projects/columns/cards/' + cardId, options, cb);
1314 }
1315
1316 /**
1317 * Delete a card
1318 * @see https://developer.github.com/v3/projects/cards/#delete-a-project-card
1319 * @param {string} cardId - the card to be deleted
1320 * @param {Requestable.callback} cb - will receive true if the operation is successful
1321 * @return {Promise} - the promise for the http request
1322 */
1323
1324 }, {
1325 key: 'deleteProjectCard',
1326 value: function deleteProjectCard(cardId, cb) {
1327 return this._request('DELETE', '/projects/columns/cards/' + cardId, null, cb);
1328 }
1329
1330 /**
1331 * Move a card
1332 * @see https://developer.github.com/v3/projects/cards/#move-a-project-card
1333 * @param {string} cardId - the card to be moved
1334 * @param {string} position - can be one of top, bottom, or after:<card-id>,
1335 * where <card-id> is the id value of a card in the same project.
1336 * @param {string} colId - the id value of a column in the same project.
1337 * @param {Requestable.callback} cb - will receive true if the operation is successful
1338 * @return {Promise} - the promise for the http request
1339 */
1340
1341 }, {
1342 key: 'moveProjectCard',
1343 value: function moveProjectCard(cardId, position, colId, cb) {
1344 return this._request('POST', '/projects/columns/cards/' + cardId + '/moves', { position: position, column_id: colId }, // eslint-disable-line camelcase
1345 cb);
1346 }
1347 }]);
1348
1349 return Project;
1350}(_Requestable3.default);
1351
1352module.exports = Project;
1353
1354},{"./Requestable":9}],7:[function(require,module,exports){
1355'use strict';
1356
1357var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1358
1359var _Requestable2 = require('./Requestable');
1360
1361var _Requestable3 = _interopRequireDefault(_Requestable2);
1362
1363function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1364
1365function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1366
1367function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1368
1369function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
1370 * @file
1371 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
1372 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
1373 * Github.js is freely distributable.
1374 */
1375
1376/**
1377 * RateLimit allows users to query their rate-limit status
1378 */
1379var RateLimit = function (_Requestable) {
1380 _inherits(RateLimit, _Requestable);
1381
1382 /**
1383 * construct a RateLimit
1384 * @param {Requestable.auth} auth - the credentials to authenticate to GitHub
1385 * @param {string} [apiBase] - the base Github API URL
1386 * @return {Promise} - the promise for the http request
1387 */
1388 function RateLimit(auth, apiBase) {
1389 _classCallCheck(this, RateLimit);
1390
1391 return _possibleConstructorReturn(this, (RateLimit.__proto__ || Object.getPrototypeOf(RateLimit)).call(this, auth, apiBase));
1392 }
1393
1394 /**
1395 * Query the current rate limit
1396 * @see https://developer.github.com/v3/rate_limit/
1397 * @param {Requestable.callback} [cb] - will receive the rate-limit data
1398 * @return {Promise} - the promise for the http request
1399 */
1400
1401
1402 _createClass(RateLimit, [{
1403 key: 'getRateLimit',
1404 value: function getRateLimit(cb) {
1405 return this._request('GET', '/rate_limit', null, cb);
1406 }
1407 }]);
1408
1409 return RateLimit;
1410}(_Requestable3.default);
1411
1412module.exports = RateLimit;
1413
1414},{"./Requestable":9}],8:[function(require,module,exports){
1415(function (Buffer){(function (){
1416'use strict';
1417
1418var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
1419
1420var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1421
1422var _Requestable2 = require('./Requestable');
1423
1424var _Requestable3 = _interopRequireDefault(_Requestable2);
1425
1426var _utf = require('utf8');
1427
1428var _utf2 = _interopRequireDefault(_utf);
1429
1430var _jsBase = require('js-base64');
1431
1432var _debug = require('debug');
1433
1434var _debug2 = _interopRequireDefault(_debug);
1435
1436function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1437
1438function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1439
1440function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1441
1442function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
1443 * @file
1444 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
1445 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
1446 * Github.js is freely distributable.
1447 */
1448
1449var log = (0, _debug2.default)('github:repository');
1450
1451/**
1452 * Repository encapsulates the functionality to create, query, and modify files.
1453 */
1454
1455var Repository = function (_Requestable) {
1456 _inherits(Repository, _Requestable);
1457
1458 /**
1459 * Create a Repository.
1460 * @param {string} fullname - the full name of the repository
1461 * @param {Requestable.auth} [auth] - information required to authenticate to Github
1462 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
1463 */
1464 function Repository(fullname, auth, apiBase) {
1465 _classCallCheck(this, Repository);
1466
1467 var _this = _possibleConstructorReturn(this, (Repository.__proto__ || Object.getPrototypeOf(Repository)).call(this, auth, apiBase));
1468
1469 _this.__fullname = fullname;
1470 _this.__currentTree = {
1471 branch: null,
1472 sha: null
1473 };
1474 return _this;
1475 }
1476
1477 /**
1478 * Get a reference
1479 * @see https://developer.github.com/v3/git/refs/#get-a-reference
1480 * @param {string} ref - the reference to get
1481 * @param {Requestable.callback} [cb] - will receive the reference's refSpec or a list of refSpecs that match `ref`
1482 * @return {Promise} - the promise for the http request
1483 */
1484
1485
1486 _createClass(Repository, [{
1487 key: 'getRef',
1488 value: function getRef(ref, cb) {
1489 return this._request('GET', '/repos/' + this.__fullname + '/git/refs/' + ref, null, cb);
1490 }
1491
1492 /**
1493 * Create a reference
1494 * @see https://developer.github.com/v3/git/refs/#create-a-reference
1495 * @param {Object} options - the object describing the ref
1496 * @param {Requestable.callback} [cb] - will receive the ref
1497 * @return {Promise} - the promise for the http request
1498 */
1499
1500 }, {
1501 key: 'createRef',
1502 value: function createRef(options, cb) {
1503 return this._request('POST', '/repos/' + this.__fullname + '/git/refs', options, cb);
1504 }
1505
1506 /**
1507 * Delete a reference
1508 * @see https://developer.github.com/v3/git/refs/#delete-a-reference
1509 * @param {string} ref - the name of the ref to delte
1510 * @param {Requestable.callback} [cb] - will receive true if the request is successful
1511 * @return {Promise} - the promise for the http request
1512 */
1513
1514 }, {
1515 key: 'deleteRef',
1516 value: function deleteRef(ref, cb) {
1517 return this._request('DELETE', '/repos/' + this.__fullname + '/git/refs/' + ref, null, cb);
1518 }
1519
1520 /**
1521 * Delete a repository
1522 * @see https://developer.github.com/v3/repos/#delete-a-repository
1523 * @param {Requestable.callback} [cb] - will receive true if the request is successful
1524 * @return {Promise} - the promise for the http request
1525 */
1526
1527 }, {
1528 key: 'deleteRepo',
1529 value: function deleteRepo(cb) {
1530 return this._request('DELETE', '/repos/' + this.__fullname, null, cb);
1531 }
1532
1533 /**
1534 * List the tags on a repository
1535 * @see https://developer.github.com/v3/repos/#list-tags
1536 * @param {Requestable.callback} [cb] - will receive the tag data
1537 * @return {Promise} - the promise for the http request
1538 */
1539
1540 }, {
1541 key: 'listTags',
1542 value: function listTags(cb) {
1543 return this._request('GET', '/repos/' + this.__fullname + '/tags', null, cb);
1544 }
1545
1546 /**
1547 * List the open pull requests on the repository
1548 * @see https://developer.github.com/v3/pulls/#list-pull-requests
1549 * @param {Object} options - options to filter the search
1550 * @param {Requestable.callback} [cb] - will receive the list of PRs
1551 * @return {Promise} - the promise for the http request
1552 */
1553
1554 }, {
1555 key: 'listPullRequests',
1556 value: function listPullRequests(options, cb) {
1557 options = options || {};
1558 return this._request('GET', '/repos/' + this.__fullname + '/pulls', options, cb);
1559 }
1560
1561 /**
1562 * Get information about a specific pull request
1563 * @see https://developer.github.com/v3/pulls/#get-a-single-pull-request
1564 * @param {number} number - the PR you wish to fetch
1565 * @param {Requestable.callback} [cb] - will receive the PR from the API
1566 * @return {Promise} - the promise for the http request
1567 */
1568
1569 }, {
1570 key: 'getPullRequest',
1571 value: function getPullRequest(number, cb) {
1572 return this._request('GET', '/repos/' + this.__fullname + '/pulls/' + number, null, cb);
1573 }
1574
1575 /**
1576 * List the files of a specific pull request
1577 * @see https://developer.github.com/v3/pulls/#list-pull-requests-files
1578 * @param {number|string} number - the PR you wish to fetch
1579 * @param {Requestable.callback} [cb] - will receive the list of files from the API
1580 * @return {Promise} - the promise for the http request
1581 */
1582
1583 }, {
1584 key: 'listPullRequestFiles',
1585 value: function listPullRequestFiles(number, cb) {
1586 return this._request('GET', '/repos/' + this.__fullname + '/pulls/' + number + '/files', null, cb);
1587 }
1588
1589 /**
1590 * Compare two branches/commits/repositories
1591 * @see https://developer.github.com/v3/repos/commits/#compare-two-commits
1592 * @param {string} base - the base commit
1593 * @param {string} head - the head commit
1594 * @param {Requestable.callback} cb - will receive the comparison
1595 * @return {Promise} - the promise for the http request
1596 */
1597
1598 }, {
1599 key: 'compareBranches',
1600 value: function compareBranches(base, head, cb) {
1601 return this._request('GET', '/repos/' + this.__fullname + '/compare/' + base + '...' + head, null, cb);
1602 }
1603
1604 /**
1605 * List all the branches for the repository
1606 * @see https://developer.github.com/v3/repos/#list-branches
1607 * @param {Requestable.callback} cb - will receive the list of branches
1608 * @return {Promise} - the promise for the http request
1609 */
1610
1611 }, {
1612 key: 'listBranches',
1613 value: function listBranches(cb) {
1614 return this._request('GET', '/repos/' + this.__fullname + '/branches', null, cb);
1615 }
1616
1617 /**
1618 * Get a raw blob from the repository
1619 * @see https://developer.github.com/v3/git/blobs/#get-a-blob
1620 * @param {string} sha - the sha of the blob to fetch
1621 * @param {Requestable.callback} cb - will receive the blob from the API
1622 * @return {Promise} - the promise for the http request
1623 */
1624
1625 }, {
1626 key: 'getBlob',
1627 value: function getBlob(sha, cb) {
1628 return this._request('GET', '/repos/' + this.__fullname + '/git/blobs/' + sha, null, cb, 'raw');
1629 }
1630
1631 /**
1632 * Get a single branch
1633 * @see https://developer.github.com/v3/repos/branches/#get-branch
1634 * @param {string} branch - the name of the branch to fetch
1635 * @param {Requestable.callback} cb - will receive the branch from the API
1636 * @returns {Promise} - the promise for the http request
1637 */
1638
1639 }, {
1640 key: 'getBranch',
1641 value: function getBranch(branch, cb) {
1642 return this._request('GET', '/repos/' + this.__fullname + '/branches/' + branch, null, cb);
1643 }
1644
1645 /**
1646 * Get a commit from the repository
1647 * @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
1648 * @param {string} sha - the sha for the commit to fetch
1649 * @param {Requestable.callback} cb - will receive the commit data
1650 * @return {Promise} - the promise for the http request
1651 */
1652
1653 }, {
1654 key: 'getCommit',
1655 value: function getCommit(sha, cb) {
1656 return this._request('GET', '/repos/' + this.__fullname + '/git/commits/' + sha, null, cb);
1657 }
1658
1659 /**
1660 * List the commits on a repository, optionally filtering by path, author or time range
1661 * @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
1662 * @param {Object} [options] - the filtering options for commits
1663 * @param {string} [options.sha] - the SHA or branch to start from
1664 * @param {string} [options.path] - the path to search on
1665 * @param {string} [options.author] - the commit author
1666 * @param {(Date|string)} [options.since] - only commits after this date will be returned
1667 * @param {(Date|string)} [options.until] - only commits before this date will be returned
1668 * @param {Requestable.callback} cb - will receive the list of commits found matching the criteria
1669 * @return {Promise} - the promise for the http request
1670 */
1671
1672 }, {
1673 key: 'listCommits',
1674 value: function listCommits(options, cb) {
1675 options = options || {};
1676 if (typeof options === 'function') {
1677 cb = options;
1678 options = {};
1679 }
1680 options.since = this._dateToISO(options.since);
1681 options.until = this._dateToISO(options.until);
1682
1683 return this._request('GET', '/repos/' + this.__fullname + '/commits', options, cb);
1684 }
1685
1686 /**
1687 * List the commits on a pull request
1688 * @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
1689 * @param {number|string} number - the number of the pull request to list the commits
1690 * @param {Object} [options] - the filtering options for commits
1691 * @param {Requestable.callback} [cb] - will receive the commits information
1692 * @return {Promise} - the promise for the http request
1693 */
1694
1695 }, {
1696 key: 'listCommitsOnPR',
1697 value: function listCommitsOnPR(number, options, cb) {
1698 options = options || {};
1699 if (typeof options === 'function') {
1700 cb = options;
1701 options = {};
1702 }
1703 return this._request('GET', '/repos/' + this.__fullname + '/pulls/' + number + '/commits', options, cb);
1704 }
1705
1706 /**
1707 * Gets a single commit information for a repository
1708 * @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
1709 * @param {string} ref - the reference for the commit-ish
1710 * @param {Requestable.callback} cb - will receive the commit information
1711 * @return {Promise} - the promise for the http request
1712 */
1713
1714 }, {
1715 key: 'getSingleCommit',
1716 value: function getSingleCommit(ref, cb) {
1717 ref = ref || '';
1718 return this._request('GET', '/repos/' + this.__fullname + '/commits/' + ref, null, cb);
1719 }
1720
1721 /**
1722 * Get tha sha for a particular object in the repository. This is a convenience function
1723 * @see https://developer.github.com/v3/repos/contents/#get-contents
1724 * @param {string} [branch] - the branch to look in, or the repository's default branch if omitted
1725 * @param {string} path - the path of the file or directory
1726 * @param {Requestable.callback} cb - will receive a description of the requested object, including a `SHA` property
1727 * @return {Promise} - the promise for the http request
1728 */
1729
1730 }, {
1731 key: 'getSha',
1732 value: function getSha(branch, path, cb) {
1733 branch = branch ? '?ref=' + branch : '';
1734 return this._request('GET', '/repos/' + this.__fullname + '/contents/' + path + branch, null, cb);
1735 }
1736
1737 /**
1738 * List the commit statuses for a particular sha, branch, or tag
1739 * @see https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
1740 * @param {string} sha - the sha, branch, or tag to get statuses for
1741 * @param {Requestable.callback} cb - will receive the list of statuses
1742 * @return {Promise} - the promise for the http request
1743 */
1744
1745 }, {
1746 key: 'listStatuses',
1747 value: function listStatuses(sha, cb) {
1748 return this._request('GET', '/repos/' + this.__fullname + '/commits/' + sha + '/statuses', null, cb);
1749 }
1750
1751 /**
1752 * Get the combined view of commit statuses for a particular sha, branch, or tag
1753 * @see https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
1754 * @param {string} sha - the sha, branch, or tag to get the combined status for
1755 * @param {Requestable.callback} cb - will receive the combined status
1756 * @returns {Promise} - the promise for the http request
1757 */
1758
1759 }, {
1760 key: 'getCombinedStatus',
1761 value: function getCombinedStatus(sha, cb) {
1762 return this._request('GET', '/repos/' + this.__fullname + '/commits/' + sha + '/status', null, cb);
1763 }
1764
1765 /**
1766 * Get a description of a git tree
1767 * @see https://developer.github.com/v3/git/trees/#get-a-tree
1768 * @param {string} treeSHA - the SHA of the tree to fetch
1769 * @param {Requestable.callback} cb - will receive the callback data
1770 * @return {Promise} - the promise for the http request
1771 */
1772
1773 }, {
1774 key: 'getTree',
1775 value: function getTree(treeSHA, cb) {
1776 return this._request('GET', '/repos/' + this.__fullname + '/git/trees/' + treeSHA, null, cb);
1777 }
1778
1779 /**
1780 * Create a blob
1781 * @see https://developer.github.com/v3/git/blobs/#create-a-blob
1782 * @param {(string|Buffer|Blob)} content - the content to add to the repository
1783 * @param {Requestable.callback} cb - will receive the details of the created blob
1784 * @return {Promise} - the promise for the http request
1785 */
1786
1787 }, {
1788 key: 'createBlob',
1789 value: function createBlob(content, cb) {
1790 var postBody = this._getContentObject(content);
1791
1792 log('sending content', postBody);
1793 return this._request('POST', '/repos/' + this.__fullname + '/git/blobs', postBody, cb);
1794 }
1795
1796 /**
1797 * Get the object that represents the provided content
1798 * @param {string|Buffer|Blob} content - the content to send to the server
1799 * @return {Object} the representation of `content` for the GitHub API
1800 */
1801
1802 }, {
1803 key: '_getContentObject',
1804 value: function _getContentObject(content) {
1805 if (typeof content === 'string') {
1806 log('contet is a string');
1807 return {
1808 content: _utf2.default.encode(content),
1809 encoding: 'utf-8'
1810 };
1811 } else if (typeof Buffer !== 'undefined' && content instanceof Buffer) {
1812 log('We appear to be in Node');
1813 return {
1814 content: content.toString('base64'),
1815 encoding: 'base64'
1816 };
1817 } else if (typeof Blob !== 'undefined' && content instanceof Blob) {
1818 log('We appear to be in the browser');
1819 return {
1820 content: _jsBase.Base64.encode(content),
1821 encoding: 'base64'
1822 };
1823 } else {
1824 // eslint-disable-line
1825 log('Not sure what this content is: ' + (typeof content === 'undefined' ? 'undefined' : _typeof(content)) + ', ' + JSON.stringify(content));
1826 throw new Error('Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web)');
1827 }
1828 }
1829
1830 /**
1831 * Update a tree in Git
1832 * @see https://developer.github.com/v3/git/trees/#create-a-tree
1833 * @param {string} baseTreeSHA - the SHA of the tree to update
1834 * @param {string} path - the path for the new file
1835 * @param {string} blobSHA - the SHA for the blob to put at `path`
1836 * @param {Requestable.callback} cb - will receive the new tree that is created
1837 * @return {Promise} - the promise for the http request
1838 * @deprecated use {@link Repository#createTree} instead
1839 */
1840
1841 }, {
1842 key: 'updateTree',
1843 value: function updateTree(baseTreeSHA, path, blobSHA, cb) {
1844 var newTree = {
1845 base_tree: baseTreeSHA, // eslint-disable-line
1846 tree: [{
1847 path: path,
1848 sha: blobSHA,
1849 mode: '100644',
1850 type: 'blob'
1851 }]
1852 };
1853
1854 return this._request('POST', '/repos/' + this.__fullname + '/git/trees', newTree, cb);
1855 }
1856
1857 /**
1858 * Create a new tree in git
1859 * @see https://developer.github.com/v3/git/trees/#create-a-tree
1860 * @param {Object} tree - the tree to create
1861 * @param {string} baseSHA - the root sha of the tree
1862 * @param {Requestable.callback} cb - will receive the new tree that is created
1863 * @return {Promise} - the promise for the http request
1864 */
1865
1866 }, {
1867 key: 'createTree',
1868 value: function createTree(tree, baseSHA, cb) {
1869 return this._request('POST', '/repos/' + this.__fullname + '/git/trees', {
1870 tree: tree,
1871 base_tree: baseSHA // eslint-disable-line camelcase
1872 }, cb);
1873 }
1874
1875 /**
1876 * Add a commit to the repository
1877 * @see https://developer.github.com/v3/git/commits/#create-a-commit
1878 * @param {string} parent - the SHA of the parent commit
1879 * @param {string} tree - the SHA of the tree for this commit
1880 * @param {string} message - the commit message
1881 * @param {Object} [options] - commit options
1882 * @param {Object} [options.author] - the author of the commit
1883 * @param {Object} [options.commiter] - the committer
1884 * @param {Requestable.callback} cb - will receive the commit that is created
1885 * @return {Promise} - the promise for the http request
1886 */
1887
1888 }, {
1889 key: 'commit',
1890 value: function commit(parent, tree, message, options, cb) {
1891 var _this2 = this;
1892
1893 if (typeof options === 'function') {
1894 cb = options;
1895 options = {};
1896 }
1897
1898 var data = {
1899 message: message,
1900 tree: tree,
1901 parents: [parent]
1902 };
1903
1904 data = Object.assign({}, options, data);
1905
1906 return this._request('POST', '/repos/' + this.__fullname + '/git/commits', data, cb).then(function (response) {
1907 _this2.__currentTree.sha = response.data.sha; // Update latest commit
1908 return response;
1909 });
1910 }
1911
1912 /**
1913 * Update a ref
1914 * @see https://developer.github.com/v3/git/refs/#update-a-reference
1915 * @param {string} ref - the ref to update
1916 * @param {string} commitSHA - the SHA to point the reference to
1917 * @param {boolean} force - indicates whether to force or ensure a fast-forward update
1918 * @param {Requestable.callback} cb - will receive the updated ref back
1919 * @return {Promise} - the promise for the http request
1920 */
1921
1922 }, {
1923 key: 'updateHead',
1924 value: function updateHead(ref, commitSHA, force, cb) {
1925 return this._request('PATCH', '/repos/' + this.__fullname + '/git/refs/' + ref, {
1926 sha: commitSHA,
1927 force: force
1928 }, cb);
1929 }
1930
1931 /**
1932 * Update commit status
1933 * @see https://developer.github.com/v3/repos/statuses/
1934 * @param {string} commitSHA - the SHA of the commit that should be updated
1935 * @param {object} options - Commit status parameters
1936 * @param {string} options.state - The state of the status. Can be one of: pending, success, error, or failure.
1937 * @param {string} [options.target_url] - The target URL to associate with this status.
1938 * @param {string} [options.description] - A short description of the status.
1939 * @param {string} [options.context] - A string label to differentiate this status among CI systems.
1940 * @param {Requestable.callback} cb - will receive the updated commit back
1941 * @return {Promise} - the promise for the http request
1942 */
1943
1944 }, {
1945 key: 'updateStatus',
1946 value: function updateStatus(commitSHA, options, cb) {
1947 return this._request('POST', '/repos/' + this.__fullname + '/statuses/' + commitSHA, options, cb);
1948 }
1949
1950 /**
1951 * Update repository information
1952 * @see https://developer.github.com/v3/repos/#edit
1953 * @param {object} options - New parameters that will be set to the repository
1954 * @param {string} options.name - Name of the repository
1955 * @param {string} [options.description] - A short description of the repository
1956 * @param {string} [options.homepage] - A URL with more information about the repository
1957 * @param {boolean} [options.private] - Either true to make the repository private, or false to make it public.
1958 * @param {boolean} [options.has_issues] - Either true to enable issues for this repository, false to disable them.
1959 * @param {boolean} [options.has_wiki] - Either true to enable the wiki for this repository, false to disable it.
1960 * @param {boolean} [options.has_downloads] - Either true to enable downloads, false to disable them.
1961 * @param {string} [options.default_branch] - Updates the default branch for this repository.
1962 * @param {Requestable.callback} cb - will receive the updated repository back
1963 * @return {Promise} - the promise for the http request
1964 */
1965
1966 }, {
1967 key: 'updateRepository',
1968 value: function updateRepository(options, cb) {
1969 return this._request('PATCH', '/repos/' + this.__fullname, options, cb);
1970 }
1971
1972 /**
1973 * Get information about the repository
1974 * @see https://developer.github.com/v3/repos/#get
1975 * @param {Requestable.callback} cb - will receive the information about the repository
1976 * @return {Promise} - the promise for the http request
1977 */
1978
1979 }, {
1980 key: 'getDetails',
1981 value: function getDetails(cb) {
1982 return this._request('GET', '/repos/' + this.__fullname, null, cb);
1983 }
1984
1985 /**
1986 * List the contributors to the repository
1987 * @see https://developer.github.com/v3/repos/#list-contributors
1988 * @param {Requestable.callback} cb - will receive the list of contributors
1989 * @return {Promise} - the promise for the http request
1990 */
1991
1992 }, {
1993 key: 'getContributors',
1994 value: function getContributors(cb) {
1995 return this._request('GET', '/repos/' + this.__fullname + '/contributors', null, cb);
1996 }
1997
1998 /**
1999 * List the contributor stats to the repository
2000 * @see https://developer.github.com/v3/repos/#list-contributors
2001 * @param {Requestable.callback} cb - will receive the list of contributors
2002 * @return {Promise} - the promise for the http request
2003 */
2004
2005 }, {
2006 key: 'getContributorStats',
2007 value: function getContributorStats(cb) {
2008 return this._request('GET', '/repos/' + this.__fullname + '/stats/contributors', null, cb);
2009 }
2010
2011 /**
2012 * List the users who are collaborators on the repository. The currently authenticated user must have
2013 * push access to use this method
2014 * @see https://developer.github.com/v3/repos/collaborators/#list-collaborators
2015 * @param {Requestable.callback} cb - will receive the list of collaborators
2016 * @return {Promise} - the promise for the http request
2017 */
2018
2019 }, {
2020 key: 'getCollaborators',
2021 value: function getCollaborators(cb) {
2022 return this._request('GET', '/repos/' + this.__fullname + '/collaborators', null, cb);
2023 }
2024
2025 /**
2026 * Check if a user is a collaborator on the repository
2027 * @see https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator
2028 * @param {string} username - the user to check
2029 * @param {Requestable.callback} cb - will receive true if the user is a collaborator and false if they are not
2030 * @return {Promise} - the promise for the http request {Boolean} [description]
2031 */
2032
2033 }, {
2034 key: 'isCollaborator',
2035 value: function isCollaborator(username, cb) {
2036 return this._request('GET', '/repos/' + this.__fullname + '/collaborators/' + username, null, cb);
2037 }
2038
2039 /**
2040 * Get the contents of a repository
2041 * @see https://developer.github.com/v3/repos/contents/#get-contents
2042 * @param {string} ref - the ref to check
2043 * @param {string} path - the path containing the content to fetch
2044 * @param {boolean} raw - `true` if the results should be returned raw instead of GitHub's normalized format
2045 * @param {Requestable.callback} cb - will receive the fetched data
2046 * @return {Promise} - the promise for the http request
2047 */
2048
2049 }, {
2050 key: 'getContents',
2051 value: function getContents(ref, path, raw, cb) {
2052 path = path ? '' + encodeURI(path) : '';
2053 return this._request('GET', '/repos/' + this.__fullname + '/contents/' + path, {
2054 ref: ref
2055 }, cb, raw);
2056 }
2057
2058 /**
2059 * Get the README of a repository
2060 * @see https://developer.github.com/v3/repos/contents/#get-the-readme
2061 * @param {string} ref - the ref to check
2062 * @param {boolean} raw - `true` if the results should be returned raw instead of GitHub's normalized format
2063 * @param {Requestable.callback} cb - will receive the fetched data
2064 * @return {Promise} - the promise for the http request
2065 */
2066
2067 }, {
2068 key: 'getReadme',
2069 value: function getReadme(ref, raw, cb) {
2070 return this._request('GET', '/repos/' + this.__fullname + '/readme', {
2071 ref: ref
2072 }, cb, raw);
2073 }
2074
2075 /**
2076 * Fork a repository
2077 * @see https://developer.github.com/v3/repos/forks/#create-a-fork
2078 * @param {Requestable.callback} cb - will receive the information about the newly created fork
2079 * @return {Promise} - the promise for the http request
2080 */
2081
2082 }, {
2083 key: 'fork',
2084 value: function fork(cb) {
2085 return this._request('POST', '/repos/' + this.__fullname + '/forks', null, cb);
2086 }
2087
2088 /**
2089 * Fork a repository to an organization
2090 * @see https://developer.github.com/v3/repos/forks/#create-a-fork
2091 * @param {String} org - organization where you'd like to create the fork.
2092 * @param {Requestable.callback} cb - will receive the information about the newly created fork
2093 * @return {Promise} - the promise for the http request
2094 *
2095 */
2096
2097 }, {
2098 key: 'forkToOrg',
2099 value: function forkToOrg(org, cb) {
2100 return this._request('POST', '/repos/' + this.__fullname + '/forks?organization=' + org, null, cb);
2101 }
2102
2103 /**
2104 * List a repository's forks
2105 * @see https://developer.github.com/v3/repos/forks/#list-forks
2106 * @param {Requestable.callback} cb - will receive the list of repositories forked from this one
2107 * @return {Promise} - the promise for the http request
2108 */
2109
2110 }, {
2111 key: 'listForks',
2112 value: function listForks(cb) {
2113 return this._request('GET', '/repos/' + this.__fullname + '/forks', null, cb);
2114 }
2115
2116 /**
2117 * Create a new branch from an existing branch.
2118 * @param {string} [oldBranch=master] - the name of the existing branch
2119 * @param {string} newBranch - the name of the new branch
2120 * @param {Requestable.callback} cb - will receive the commit data for the head of the new branch
2121 * @return {Promise} - the promise for the http request
2122 */
2123
2124 }, {
2125 key: 'createBranch',
2126 value: function createBranch(oldBranch, newBranch, cb) {
2127 var _this3 = this;
2128
2129 if (typeof newBranch === 'function') {
2130 cb = newBranch;
2131 newBranch = oldBranch;
2132 oldBranch = 'master';
2133 }
2134
2135 return this.getRef('heads/' + oldBranch).then(function (response) {
2136 var sha = response.data.object.sha;
2137 return _this3.createRef({
2138 sha: sha,
2139 ref: 'refs/heads/' + newBranch
2140 }, cb);
2141 });
2142 }
2143
2144 /**
2145 * Create a new pull request
2146 * @see https://developer.github.com/v3/pulls/#create-a-pull-request
2147 * @param {Object} options - the pull request description
2148 * @param {Requestable.callback} cb - will receive the new pull request
2149 * @return {Promise} - the promise for the http request
2150 */
2151
2152 }, {
2153 key: 'createPullRequest',
2154 value: function createPullRequest(options, cb) {
2155 return this._request('POST', '/repos/' + this.__fullname + '/pulls', options, cb);
2156 }
2157
2158 /**
2159 * Update a pull request
2160 * @see https://developer.github.com/v3/pulls/#update-a-pull-request
2161 * @param {number|string} number - the number of the pull request to update
2162 * @param {Object} options - the pull request description
2163 * @param {Requestable.callback} [cb] - will receive the pull request information
2164 * @return {Promise} - the promise for the http request
2165 */
2166
2167 }, {
2168 key: 'updatePullRequest',
2169 value: function updatePullRequest(number, options, cb) {
2170 return this._request('PATCH', '/repos/' + this.__fullname + '/pulls/' + number, options, cb);
2171 }
2172
2173 /**
2174 * List the hooks for the repository
2175 * @see https://developer.github.com/v3/repos/hooks/#list-hooks
2176 * @param {Requestable.callback} cb - will receive the list of hooks
2177 * @return {Promise} - the promise for the http request
2178 */
2179
2180 }, {
2181 key: 'listHooks',
2182 value: function listHooks(cb) {
2183 return this._request('GET', '/repos/' + this.__fullname + '/hooks', null, cb);
2184 }
2185
2186 /**
2187 * Get a hook for the repository
2188 * @see https://developer.github.com/v3/repos/hooks/#get-single-hook
2189 * @param {number} id - the id of the webook
2190 * @param {Requestable.callback} cb - will receive the details of the webook
2191 * @return {Promise} - the promise for the http request
2192 */
2193
2194 }, {
2195 key: 'getHook',
2196 value: function getHook(id, cb) {
2197 return this._request('GET', '/repos/' + this.__fullname + '/hooks/' + id, null, cb);
2198 }
2199
2200 /**
2201 * Add a new hook to the repository
2202 * @see https://developer.github.com/v3/repos/hooks/#create-a-hook
2203 * @param {Object} options - the configuration describing the new hook
2204 * @param {Requestable.callback} cb - will receive the new webhook
2205 * @return {Promise} - the promise for the http request
2206 */
2207
2208 }, {
2209 key: 'createHook',
2210 value: function createHook(options, cb) {
2211 return this._request('POST', '/repos/' + this.__fullname + '/hooks', options, cb);
2212 }
2213
2214 /**
2215 * Edit an existing webhook
2216 * @see https://developer.github.com/v3/repos/hooks/#edit-a-hook
2217 * @param {number} id - the id of the webhook
2218 * @param {Object} options - the new description of the webhook
2219 * @param {Requestable.callback} cb - will receive the updated webhook
2220 * @return {Promise} - the promise for the http request
2221 */
2222
2223 }, {
2224 key: 'updateHook',
2225 value: function updateHook(id, options, cb) {
2226 return this._request('PATCH', '/repos/' + this.__fullname + '/hooks/' + id, options, cb);
2227 }
2228
2229 /**
2230 * Delete a webhook
2231 * @see https://developer.github.com/v3/repos/hooks/#delete-a-hook
2232 * @param {number} id - the id of the webhook to be deleted
2233 * @param {Requestable.callback} cb - will receive true if the call is successful
2234 * @return {Promise} - the promise for the http request
2235 */
2236
2237 }, {
2238 key: 'deleteHook',
2239 value: function deleteHook(id, cb) {
2240 return this._request('DELETE', '/repos/' + this.__fullname + '/hooks/' + id, null, cb);
2241 }
2242
2243 /**
2244 * List the deploy keys for the repository
2245 * @see https://developer.github.com/v3/repos/keys/#list-deploy-keys
2246 * @param {Requestable.callback} cb - will receive the list of deploy keys
2247 * @return {Promise} - the promise for the http request
2248 */
2249
2250 }, {
2251 key: 'listKeys',
2252 value: function listKeys(cb) {
2253 return this._request('GET', '/repos/' + this.__fullname + '/keys', null, cb);
2254 }
2255
2256 /**
2257 * Get a deploy key for the repository
2258 * @see https://developer.github.com/v3/repos/keys/#get-a-deploy-key
2259 * @param {number} id - the id of the deploy key
2260 * @param {Requestable.callback} cb - will receive the details of the deploy key
2261 * @return {Promise} - the promise for the http request
2262 */
2263
2264 }, {
2265 key: 'getKey',
2266 value: function getKey(id, cb) {
2267 return this._request('GET', '/repos/' + this.__fullname + '/keys/' + id, null, cb);
2268 }
2269
2270 /**
2271 * Add a new deploy key to the repository
2272 * @see https://developer.github.com/v3/repos/keys/#add-a-new-deploy-key
2273 * @param {Object} options - the configuration describing the new deploy key
2274 * @param {Requestable.callback} cb - will receive the new deploy key
2275 * @return {Promise} - the promise for the http request
2276 */
2277
2278 }, {
2279 key: 'createKey',
2280 value: function createKey(options, cb) {
2281 return this._request('POST', '/repos/' + this.__fullname + '/keys', options, cb);
2282 }
2283
2284 /**
2285 * Delete a deploy key
2286 * @see https://developer.github.com/v3/repos/keys/#remove-a-deploy-key
2287 * @param {number} id - the id of the deploy key to be deleted
2288 * @param {Requestable.callback} cb - will receive true if the call is successful
2289 * @return {Promise} - the promise for the http request
2290 */
2291
2292 }, {
2293 key: 'deleteKey',
2294 value: function deleteKey(id, cb) {
2295 return this._request('DELETE', '/repos/' + this.__fullname + '/keys/' + id, null, cb);
2296 }
2297
2298 /**
2299 * Delete a file from a branch
2300 * @see https://developer.github.com/v3/repos/contents/#delete-a-file
2301 * @param {string} branch - the branch to delete from, or the default branch if not specified
2302 * @param {string} path - the path of the file to remove
2303 * @param {Requestable.callback} cb - will receive the commit in which the delete occurred
2304 * @return {Promise} - the promise for the http request
2305 */
2306
2307 }, {
2308 key: 'deleteFile',
2309 value: function deleteFile(branch, path, cb) {
2310 var _this4 = this;
2311
2312 return this.getSha(branch, path).then(function (response) {
2313 var deleteCommit = {
2314 message: 'Delete the file at \'' + path + '\'',
2315 sha: response.data.sha,
2316 branch: branch
2317 };
2318 return _this4._request('DELETE', '/repos/' + _this4.__fullname + '/contents/' + path, deleteCommit, cb);
2319 });
2320 }
2321
2322 /**
2323 * Change all references in a repo from oldPath to new_path
2324 * @param {string} branch - the branch to carry out the reference change, or the default branch if not specified
2325 * @param {string} oldPath - original path
2326 * @param {string} newPath - new reference path
2327 * @param {Requestable.callback} cb - will receive the commit in which the move occurred
2328 * @return {Promise} - the promise for the http request
2329 */
2330
2331 }, {
2332 key: 'move',
2333 value: function move(branch, oldPath, newPath, cb) {
2334 var _this5 = this;
2335
2336 var oldSha = void 0;
2337 return this.getRef('heads/' + branch).then(function (_ref) {
2338 var object = _ref.data.object;
2339 return _this5.getTree(object.sha + '?recursive=true');
2340 }).then(function (_ref2) {
2341 var _ref2$data = _ref2.data,
2342 tree = _ref2$data.tree,
2343 sha = _ref2$data.sha;
2344
2345 oldSha = sha;
2346 var newTree = tree.map(function (ref) {
2347 if (ref.path === oldPath) {
2348 ref.path = newPath;
2349 }
2350 if (ref.type === 'tree') {
2351 delete ref.sha;
2352 }
2353 return ref;
2354 });
2355 return _this5.createTree(newTree);
2356 }).then(function (_ref3) {
2357 var tree = _ref3.data;
2358 return _this5.commit(oldSha, tree.sha, 'Renamed \'' + oldPath + '\' to \'' + newPath + '\'');
2359 }).then(function (_ref4) {
2360 var commit = _ref4.data;
2361 return _this5.updateHead('heads/' + branch, commit.sha, true, cb);
2362 });
2363 }
2364
2365 /**
2366 * Write a file to the repository
2367 * @see https://developer.github.com/v3/repos/contents/#update-a-file
2368 * @param {string} branch - the name of the branch
2369 * @param {string} path - the path for the file
2370 * @param {string} content - the contents of the file
2371 * @param {string} message - the commit message
2372 * @param {Object} [options] - commit options
2373 * @param {Object} [options.author] - the author of the commit
2374 * @param {Object} [options.commiter] - the committer
2375 * @param {boolean} [options.encode] - true if the content should be base64 encoded
2376 * @param {Requestable.callback} cb - will receive the new commit
2377 * @return {Promise} - the promise for the http request
2378 */
2379
2380 }, {
2381 key: 'writeFile',
2382 value: function writeFile(branch, path, content, message, options, cb) {
2383 var _this6 = this;
2384
2385 options = options || {};
2386 if (typeof options === 'function') {
2387 cb = options;
2388 options = {};
2389 }
2390 var filePath = path ? encodeURI(path) : '';
2391 var shouldEncode = options.encode !== false;
2392 var commit = {
2393 branch: branch,
2394 message: message,
2395 author: options.author,
2396 committer: options.committer,
2397 content: shouldEncode ? _jsBase.Base64.encode(content) : content
2398 };
2399
2400 return this.getSha(branch, filePath).then(function (response) {
2401 commit.sha = response.data.sha;
2402 return _this6._request('PUT', '/repos/' + _this6.__fullname + '/contents/' + filePath, commit, cb);
2403 }, function () {
2404 return _this6._request('PUT', '/repos/' + _this6.__fullname + '/contents/' + filePath, commit, cb);
2405 });
2406 }
2407
2408 /**
2409 * Check if a repository is starred by you
2410 * @see https://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository
2411 * @param {Requestable.callback} cb - will receive true if the repository is starred and false if the repository
2412 * is not starred
2413 * @return {Promise} - the promise for the http request {Boolean} [description]
2414 */
2415
2416 }, {
2417 key: 'isStarred',
2418 value: function isStarred(cb) {
2419 return this._request204or404('/user/starred/' + this.__fullname, null, cb);
2420 }
2421
2422 /**
2423 * Star a repository
2424 * @see https://developer.github.com/v3/activity/starring/#star-a-repository
2425 * @param {Requestable.callback} cb - will receive true if the repository is starred
2426 * @return {Promise} - the promise for the http request
2427 */
2428
2429 }, {
2430 key: 'star',
2431 value: function star(cb) {
2432 return this._request('PUT', '/user/starred/' + this.__fullname, null, cb);
2433 }
2434
2435 /**
2436 * Unstar a repository
2437 * @see https://developer.github.com/v3/activity/starring/#unstar-a-repository
2438 * @param {Requestable.callback} cb - will receive true if the repository is unstarred
2439 * @return {Promise} - the promise for the http request
2440 */
2441
2442 }, {
2443 key: 'unstar',
2444 value: function unstar(cb) {
2445 return this._request('DELETE', '/user/starred/' + this.__fullname, null, cb);
2446 }
2447
2448 /**
2449 * Create a new release
2450 * @see https://developer.github.com/v3/repos/releases/#create-a-release
2451 * @param {Object} options - the description of the release
2452 * @param {Requestable.callback} cb - will receive the newly created release
2453 * @return {Promise} - the promise for the http request
2454 */
2455
2456 }, {
2457 key: 'createRelease',
2458 value: function createRelease(options, cb) {
2459 return this._request('POST', '/repos/' + this.__fullname + '/releases', options, cb);
2460 }
2461
2462 /**
2463 * Edit a release
2464 * @see https://developer.github.com/v3/repos/releases/#edit-a-release
2465 * @param {string} id - the id of the release
2466 * @param {Object} options - the description of the release
2467 * @param {Requestable.callback} cb - will receive the modified release
2468 * @return {Promise} - the promise for the http request
2469 */
2470
2471 }, {
2472 key: 'updateRelease',
2473 value: function updateRelease(id, options, cb) {
2474 return this._request('PATCH', '/repos/' + this.__fullname + '/releases/' + id, options, cb);
2475 }
2476
2477 /**
2478 * Get information about all releases
2479 * @see https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
2480 * @param {Requestable.callback} cb - will receive the release information
2481 * @return {Promise} - the promise for the http request
2482 */
2483
2484 }, {
2485 key: 'listReleases',
2486 value: function listReleases(cb) {
2487 return this._request('GET', '/repos/' + this.__fullname + '/releases', null, cb);
2488 }
2489
2490 /**
2491 * Get information about a release
2492 * @see https://developer.github.com/v3/repos/releases/#get-a-single-release
2493 * @param {string} id - the id of the release
2494 * @param {Requestable.callback} cb - will receive the release information
2495 * @return {Promise} - the promise for the http request
2496 */
2497
2498 }, {
2499 key: 'getRelease',
2500 value: function getRelease(id, cb) {
2501 return this._request('GET', '/repos/' + this.__fullname + '/releases/' + id, null, cb);
2502 }
2503
2504 /**
2505 * Delete a release
2506 * @see https://developer.github.com/v3/repos/releases/#delete-a-release
2507 * @param {string} id - the release to be deleted
2508 * @param {Requestable.callback} cb - will receive true if the operation is successful
2509 * @return {Promise} - the promise for the http request
2510 */
2511
2512 }, {
2513 key: 'deleteRelease',
2514 value: function deleteRelease(id, cb) {
2515 return this._request('DELETE', '/repos/' + this.__fullname + '/releases/' + id, null, cb);
2516 }
2517
2518 /**
2519 * Merge a pull request
2520 * @see https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
2521 * @param {number|string} number - the number of the pull request to merge
2522 * @param {Object} options - the merge options for the pull request
2523 * @param {Requestable.callback} [cb] - will receive the merge information if the operation is successful
2524 * @return {Promise} - the promise for the http request
2525 */
2526
2527 }, {
2528 key: 'mergePullRequest',
2529 value: function mergePullRequest(number, options, cb) {
2530 return this._request('PUT', '/repos/' + this.__fullname + '/pulls/' + number + '/merge', options, cb);
2531 }
2532
2533 /**
2534 * Get information about all projects
2535 * @see https://developer.github.com/v3/projects/#list-repository-projects
2536 * @param {Requestable.callback} [cb] - will receive the list of projects
2537 * @return {Promise} - the promise for the http request
2538 */
2539
2540 }, {
2541 key: 'listProjects',
2542 value: function listProjects(cb) {
2543 return this._requestAllPages('/repos/' + this.__fullname + '/projects', { AcceptHeader: 'inertia-preview' }, cb);
2544 }
2545
2546 /**
2547 * Create a new project
2548 * @see https://developer.github.com/v3/projects/#create-a-repository-project
2549 * @param {Object} options - the description of the project
2550 * @param {Requestable.callback} cb - will receive the newly created project
2551 * @return {Promise} - the promise for the http request
2552 */
2553
2554 }, {
2555 key: 'createProject',
2556 value: function createProject(options, cb) {
2557 options = options || {};
2558 options.AcceptHeader = 'inertia-preview';
2559 return this._request('POST', '/repos/' + this.__fullname + '/projects', options, cb);
2560 }
2561 }]);
2562
2563 return Repository;
2564}(_Requestable3.default);
2565
2566module.exports = Repository;
2567
2568}).call(this)}).call(this,require("buffer").Buffer)
2569
2570},{"./Requestable":9,"buffer":undefined,"debug":undefined,"js-base64":undefined,"utf8":undefined}],9:[function(require,module,exports){
2571'use strict';
2572
2573var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2574
2575var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2576
2577var _axios = require('axios');
2578
2579var _axios2 = _interopRequireDefault(_axios);
2580
2581var _debug = require('debug');
2582
2583var _debug2 = _interopRequireDefault(_debug);
2584
2585var _jsBase = require('js-base64');
2586
2587function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2588
2589function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2590
2591function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2592
2593function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2594
2595function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
2596 * @file
2597 * @copyright 2016 Yahoo Inc.
2598 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
2599 * Github.js is freely distributable.
2600 */
2601
2602var log = (0, _debug2.default)('github:request');
2603
2604/**
2605 * The error structure returned when a network call fails
2606 */
2607
2608var ResponseError = function (_Error) {
2609 _inherits(ResponseError, _Error);
2610
2611 /**
2612 * Construct a new ResponseError
2613 * @param {string} message - an message to return instead of the the default error message
2614 * @param {string} path - the requested path
2615 * @param {Object} response - the object returned by Axios
2616 */
2617 function ResponseError(message, path, response) {
2618 _classCallCheck(this, ResponseError);
2619
2620 var _this = _possibleConstructorReturn(this, (ResponseError.__proto__ || Object.getPrototypeOf(ResponseError)).call(this, message));
2621
2622 _this.path = path;
2623 _this.request = response.config;
2624 _this.response = (response || {}).response || response;
2625 _this.status = response.status;
2626 return _this;
2627 }
2628
2629 return ResponseError;
2630}(Error);
2631
2632/**
2633 * Requestable wraps the logic for making http requests to the API
2634 */
2635
2636
2637var Requestable = function () {
2638 /**
2639 * Either a username and password or an oauth token for Github
2640 * @typedef {Object} Requestable.auth
2641 * @prop {string} [username] - the Github username
2642 * @prop {string} [password] - the user's password
2643 * @prop {token} [token] - an OAuth token
2644 */
2645 /**
2646 * Initialize the http internals.
2647 * @param {Requestable.auth} [auth] - the credentials to authenticate to Github. If auth is
2648 * not provided request will be made unauthenticated
2649 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
2650 * @param {string} [AcceptHeader=v3] - the accept header for the requests
2651 */
2652 function Requestable(auth, apiBase, AcceptHeader) {
2653 _classCallCheck(this, Requestable);
2654
2655 this.__apiBase = apiBase || 'https://api.github.com';
2656 this.__auth = {
2657 token: auth.token,
2658 username: auth.username,
2659 password: auth.password
2660 };
2661 this.__AcceptHeader = AcceptHeader || 'v3';
2662
2663 if (auth.token) {
2664 this.__authorizationHeader = 'token ' + auth.token;
2665 } else if (auth.username && auth.password) {
2666 this.__authorizationHeader = 'Basic ' + _jsBase.Base64.encode(auth.username + ':' + auth.password);
2667 }
2668 }
2669
2670 /**
2671 * Compute the URL to use to make a request.
2672 * @private
2673 * @param {string} path - either a URL relative to the API base or an absolute URL
2674 * @return {string} - the URL to use
2675 */
2676
2677
2678 _createClass(Requestable, [{
2679 key: '__getURL',
2680 value: function __getURL(path) {
2681 var url = path;
2682
2683 if (path.indexOf('//') === -1) {
2684 url = this.__apiBase + path;
2685 }
2686
2687 var newCacheBuster = 'timestamp=' + new Date().getTime();
2688 return url.replace(/(timestamp=\d+)/, newCacheBuster);
2689 }
2690
2691 /**
2692 * Compute the headers required for an API request.
2693 * @private
2694 * @param {boolean} raw - if the request should be treated as JSON or as a raw request
2695 * @param {string} AcceptHeader - the accept header for the request
2696 * @return {Object} - the headers to use in the request
2697 */
2698
2699 }, {
2700 key: '__getRequestHeaders',
2701 value: function __getRequestHeaders(raw, AcceptHeader) {
2702 var headers = {
2703 'Content-Type': 'application/json;charset=UTF-8',
2704 'Accept': 'application/vnd.github.' + (AcceptHeader || this.__AcceptHeader)
2705 };
2706
2707 if (raw) {
2708 headers.Accept += '.raw';
2709 }
2710 headers.Accept += '+json';
2711
2712 if (this.__authorizationHeader) {
2713 headers.Authorization = this.__authorizationHeader;
2714 }
2715
2716 return headers;
2717 }
2718
2719 /**
2720 * Sets the default options for API requests
2721 * @protected
2722 * @param {Object} [requestOptions={}] - the current options for the request
2723 * @return {Object} - the options to pass to the request
2724 */
2725
2726 }, {
2727 key: '_getOptionsWithDefaults',
2728 value: function _getOptionsWithDefaults() {
2729 var requestOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2730
2731 if (!(requestOptions.visibility || requestOptions.affiliation)) {
2732 requestOptions.type = requestOptions.type || 'all';
2733 }
2734 requestOptions.sort = requestOptions.sort || 'updated';
2735 requestOptions.per_page = requestOptions.per_page || '100'; // eslint-disable-line
2736
2737 return requestOptions;
2738 }
2739
2740 /**
2741 * if a `Date` is passed to this function it will be converted to an ISO string
2742 * @param {*} date - the object to attempt to coerce into an ISO date string
2743 * @return {string} - the ISO representation of `date` or whatever was passed in if it was not a date
2744 */
2745
2746 }, {
2747 key: '_dateToISO',
2748 value: function _dateToISO(date) {
2749 if (date && date instanceof Date) {
2750 date = date.toISOString();
2751 }
2752
2753 return date;
2754 }
2755
2756 /**
2757 * A function that receives the result of the API request.
2758 * @callback Requestable.callback
2759 * @param {Requestable.Error} error - the error returned by the API or `null`
2760 * @param {(Object|true)} result - the data returned by the API or `true` if the API returns `204 No Content`
2761 * @param {Object} request - the raw {@linkcode https://github.com/mzabriskie/axios#response-schema Response}
2762 */
2763 /**
2764 * Make a request.
2765 * @param {string} method - the method for the request (GET, PUT, POST, DELETE)
2766 * @param {string} path - the path for the request
2767 * @param {*} [data] - the data to send to the server. For HTTP methods that don't have a body the data
2768 * will be sent as query parameters
2769 * @param {Requestable.callback} [cb] - the callback for the request
2770 * @param {boolean} [raw=false] - if the request should be sent as raw. If this is a falsy value then the
2771 * request will be made as JSON
2772 * @return {Promise} - the Promise for the http request
2773 */
2774
2775 }, {
2776 key: '_request',
2777 value: function _request(method, path, data, cb, raw) {
2778 var url = this.__getURL(path);
2779
2780 var AcceptHeader = (data || {}).AcceptHeader;
2781 if (AcceptHeader) {
2782 delete data.AcceptHeader;
2783 }
2784 var headers = this.__getRequestHeaders(raw, AcceptHeader);
2785
2786 var queryParams = {};
2787
2788 var shouldUseDataAsParams = data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object' && methodHasNoBody(method);
2789 if (shouldUseDataAsParams) {
2790 queryParams = data;
2791 data = undefined;
2792 }
2793
2794 var config = {
2795 url: url,
2796 method: method,
2797 headers: headers,
2798 params: queryParams,
2799 data: data,
2800 responseType: raw ? 'text' : 'json'
2801 };
2802
2803 log(config.method + ' to ' + config.url);
2804 var requestPromise = (0, _axios2.default)(config).catch(callbackErrorOrThrow(cb, path));
2805
2806 if (cb) {
2807 requestPromise.then(function (response) {
2808 if (response.data && Object.keys(response.data).length > 0) {
2809 // When data has results
2810 cb(null, response.data, response);
2811 } else if (config.method !== 'GET' && Object.keys(response.data).length < 1) {
2812 // True when successful submit a request and receive a empty object
2813 cb(null, response.status < 300, response);
2814 } else {
2815 cb(null, response.data, response);
2816 }
2817 });
2818 }
2819
2820 return requestPromise;
2821 }
2822
2823 /**
2824 * Make a request to an endpoint the returns 204 when true and 404 when false
2825 * @param {string} path - the path to request
2826 * @param {Object} data - any query parameters for the request
2827 * @param {Requestable.callback} cb - the callback that will receive `true` or `false`
2828 * @param {method} [method=GET] - HTTP Method to use
2829 * @return {Promise} - the promise for the http request
2830 */
2831
2832 }, {
2833 key: '_request204or404',
2834 value: function _request204or404(path, data, cb) {
2835 var method = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'GET';
2836
2837 return this._request(method, path, data).then(function success(response) {
2838 if (cb) {
2839 cb(null, true, response);
2840 }
2841 return true;
2842 }, function failure(response) {
2843 if (response.response.status === 404) {
2844 if (cb) {
2845 cb(null, false, response);
2846 }
2847 return false;
2848 }
2849
2850 if (cb) {
2851 cb(response);
2852 }
2853 throw response;
2854 });
2855 }
2856
2857 /**
2858 * Make a request and fetch all the available data. Github will paginate responses so for queries
2859 * that might span multiple pages this method is preferred to {@link Requestable#request}
2860 * @param {string} path - the path to request
2861 * @param {Object} options - the query parameters to include
2862 * @param {Requestable.callback} [cb] - the function to receive the data. The returned data will always be an array.
2863 * @param {Object[]} results - the partial results. This argument is intended for internal use only.
2864 * @return {Promise} - a promise which will resolve when all pages have been fetched
2865 * @deprecated This will be folded into {@link Requestable#_request} in the 2.0 release.
2866 */
2867
2868 }, {
2869 key: '_requestAllPages',
2870 value: function _requestAllPages(path, options, cb, results) {
2871 var _this2 = this;
2872
2873 results = results || [];
2874
2875 return this._request('GET', path, options).then(function (response) {
2876 var _results;
2877
2878 var thisGroup = void 0;
2879 if (response.data instanceof Array) {
2880 thisGroup = response.data;
2881 } else if (response.data.items instanceof Array) {
2882 thisGroup = response.data.items;
2883 } else {
2884 var message = 'cannot figure out how to append ' + response.data + ' to the result set';
2885 throw new ResponseError(message, path, response);
2886 }
2887 (_results = results).push.apply(_results, _toConsumableArray(thisGroup));
2888
2889 var nextUrl = getNextPage(response.headers.link);
2890 if (nextUrl) {
2891 if (!options) {
2892 options = {};
2893 }
2894 options.page = parseInt(nextUrl.match(/([&\?]page=[0-9]*)/g).shift().split('=').pop());
2895 if (!(options && typeof options.page !== 'number')) {
2896 log('getting next page: ' + nextUrl);
2897 return _this2._requestAllPages(nextUrl, options, cb, results);
2898 }
2899 }
2900
2901 if (cb) {
2902 cb(null, results, response);
2903 }
2904
2905 response.data = results;
2906 return response;
2907 }).catch(callbackErrorOrThrow(cb, path));
2908 }
2909 }]);
2910
2911 return Requestable;
2912}();
2913
2914module.exports = Requestable;
2915
2916// ////////////////////////// //
2917// Private helper functions //
2918// ////////////////////////// //
2919var METHODS_WITH_NO_BODY = ['GET', 'HEAD', 'DELETE'];
2920function methodHasNoBody(method) {
2921 return METHODS_WITH_NO_BODY.indexOf(method) !== -1;
2922}
2923
2924function getNextPage() {
2925 var linksHeader = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
2926
2927 var links = linksHeader.split(/\s*,\s*/); // splits and strips the urls
2928 return links.reduce(function (nextUrl, link) {
2929 if (link.search(/rel="next"/) !== -1) {
2930 return (link.match(/<(.*)>/) || [])[1];
2931 }
2932
2933 return nextUrl;
2934 }, undefined);
2935}
2936
2937function callbackErrorOrThrow(cb, path) {
2938 return function handler(object) {
2939 var error = void 0;
2940 if (object.hasOwnProperty('config')) {
2941 var _object$response = object.response,
2942 status = _object$response.status,
2943 statusText = _object$response.statusText,
2944 _object$config = object.config,
2945 method = _object$config.method,
2946 url = _object$config.url;
2947
2948 var message = status + ' error making request ' + method + ' ' + url + ': "' + statusText + '"';
2949 error = new ResponseError(message, path, object);
2950 log(message + ' ' + JSON.stringify(object.data));
2951 } else {
2952 error = object;
2953 }
2954 if (cb) {
2955 log('going to error callback');
2956 cb(error);
2957 } else {
2958 log('throwing error');
2959 throw error;
2960 }
2961 };
2962}
2963
2964},{"axios":undefined,"debug":undefined,"js-base64":undefined}],10:[function(require,module,exports){
2965'use strict';
2966
2967var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2968
2969var _Requestable2 = require('./Requestable');
2970
2971var _Requestable3 = _interopRequireDefault(_Requestable2);
2972
2973var _debug = require('debug');
2974
2975var _debug2 = _interopRequireDefault(_debug);
2976
2977function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2978
2979function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2980
2981function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2982
2983function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
2984 * @file
2985 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
2986 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
2987 * Github.js is freely distributable.
2988 */
2989
2990var log = (0, _debug2.default)('github:search');
2991
2992/**
2993 * Wrap the Search API
2994 */
2995
2996var Search = function (_Requestable) {
2997 _inherits(Search, _Requestable);
2998
2999 /**
3000 * Create a Search
3001 * @param {Object} defaults - defaults for the search
3002 * @param {Requestable.auth} [auth] - information required to authenticate to Github
3003 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
3004 */
3005 function Search(defaults, auth, apiBase) {
3006 _classCallCheck(this, Search);
3007
3008 var _this = _possibleConstructorReturn(this, (Search.__proto__ || Object.getPrototypeOf(Search)).call(this, auth, apiBase));
3009
3010 _this.__defaults = _this._getOptionsWithDefaults(defaults);
3011 return _this;
3012 }
3013
3014 /**
3015 * Available search options
3016 * @see https://developer.github.com/v3/search/#parameters
3017 * @typedef {Object} Search.Params
3018 * @param {string} q - the query to make
3019 * @param {string} sort - the sort field, one of `stars`, `forks`, or `updated`.
3020 * Default is [best match](https://developer.github.com/v3/search/#ranking-search-results)
3021 * @param {string} order - the ordering, either `asc` or `desc`
3022 */
3023 /**
3024 * Perform a search on the GitHub API
3025 * @private
3026 * @param {string} path - the scope of the search
3027 * @param {Search.Params} [withOptions] - additional parameters for the search
3028 * @param {Requestable.callback} [cb] - will receive the results of the search
3029 * @return {Promise} - the promise for the http request
3030 */
3031
3032
3033 _createClass(Search, [{
3034 key: '_search',
3035 value: function _search(path) {
3036 var _this2 = this;
3037
3038 var withOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3039 var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
3040
3041 var requestOptions = {};
3042 Object.keys(this.__defaults).forEach(function (prop) {
3043 requestOptions[prop] = _this2.__defaults[prop];
3044 });
3045 Object.keys(withOptions).forEach(function (prop) {
3046 requestOptions[prop] = withOptions[prop];
3047 });
3048
3049 log('searching ' + path + ' with options:', requestOptions);
3050 return this._requestAllPages('/search/' + path, requestOptions, cb);
3051 }
3052
3053 /**
3054 * Search for repositories
3055 * @see https://developer.github.com/v3/search/#search-repositories
3056 * @param {Search.Params} [options] - additional parameters for the search
3057 * @param {Requestable.callback} [cb] - will receive the results of the search
3058 * @return {Promise} - the promise for the http request
3059 */
3060
3061 }, {
3062 key: 'forRepositories',
3063 value: function forRepositories(options, cb) {
3064 return this._search('repositories', options, cb);
3065 }
3066
3067 /**
3068 * Search for code
3069 * @see https://developer.github.com/v3/search/#search-code
3070 * @param {Search.Params} [options] - additional parameters for the search
3071 * @param {Requestable.callback} [cb] - will receive the results of the search
3072 * @return {Promise} - the promise for the http request
3073 */
3074
3075 }, {
3076 key: 'forCode',
3077 value: function forCode(options, cb) {
3078 return this._search('code', options, cb);
3079 }
3080
3081 /**
3082 * Search for issues
3083 * @see https://developer.github.com/v3/search/#search-issues
3084 * @param {Search.Params} [options] - additional parameters for the search
3085 * @param {Requestable.callback} [cb] - will receive the results of the search
3086 * @return {Promise} - the promise for the http request
3087 */
3088
3089 }, {
3090 key: 'forIssues',
3091 value: function forIssues(options, cb) {
3092 return this._search('issues', options, cb);
3093 }
3094
3095 /**
3096 * Search for users
3097 * @see https://developer.github.com/v3/search/#search-users
3098 * @param {Search.Params} [options] - additional parameters for the search
3099 * @param {Requestable.callback} [cb] - will receive the results of the search
3100 * @return {Promise} - the promise for the http request
3101 */
3102
3103 }, {
3104 key: 'forUsers',
3105 value: function forUsers(options, cb) {
3106 return this._search('users', options, cb);
3107 }
3108 }]);
3109
3110 return Search;
3111}(_Requestable3.default);
3112
3113module.exports = Search;
3114
3115},{"./Requestable":9,"debug":undefined}],11:[function(require,module,exports){
3116'use strict';
3117
3118var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
3119
3120var _Requestable2 = require('./Requestable');
3121
3122var _Requestable3 = _interopRequireDefault(_Requestable2);
3123
3124var _debug = require('debug');
3125
3126var _debug2 = _interopRequireDefault(_debug);
3127
3128function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
3129
3130function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3131
3132function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
3133
3134function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
3135 * @file
3136 * @copyright 2016 Matt Smith (Development Seed)
3137 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
3138 * Github.js is freely distributable.
3139 */
3140
3141var log = (0, _debug2.default)('github:team');
3142
3143/**
3144 * A Team allows scoping of API requests to a particular Github Organization Team.
3145 */
3146
3147var Team = function (_Requestable) {
3148 _inherits(Team, _Requestable);
3149
3150 /**
3151 * Create a Team.
3152 * @param {string} [teamId] - the id for the team
3153 * @param {Requestable.auth} [auth] - information required to authenticate to Github
3154 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
3155 */
3156 function Team(teamId, auth, apiBase) {
3157 _classCallCheck(this, Team);
3158
3159 var _this = _possibleConstructorReturn(this, (Team.__proto__ || Object.getPrototypeOf(Team)).call(this, auth, apiBase));
3160
3161 _this.__teamId = teamId;
3162 return _this;
3163 }
3164
3165 /**
3166 * Get Team information
3167 * @see https://developer.github.com/v3/orgs/teams/#get-team
3168 * @param {Requestable.callback} [cb] - will receive the team
3169 * @return {Promise} - the promise for the http request
3170 */
3171
3172
3173 _createClass(Team, [{
3174 key: 'getTeam',
3175 value: function getTeam(cb) {
3176 log('Fetching Team ' + this.__teamId);
3177 return this._request('Get', '/teams/' + this.__teamId, undefined, cb);
3178 }
3179
3180 /**
3181 * List the Team's repositories
3182 * @see https://developer.github.com/v3/orgs/teams/#list-team-repos
3183 * @param {Requestable.callback} [cb] - will receive the list of repositories
3184 * @return {Promise} - the promise for the http request
3185 */
3186
3187 }, {
3188 key: 'listRepos',
3189 value: function listRepos(cb) {
3190 log('Fetching repositories for Team ' + this.__teamId);
3191 return this._requestAllPages('/teams/' + this.__teamId + '/repos', undefined, cb);
3192 }
3193
3194 /**
3195 * Edit Team information
3196 * @see https://developer.github.com/v3/orgs/teams/#edit-team
3197 * @param {object} options - Parameters for team edit
3198 * @param {string} options.name - The name of the team
3199 * @param {string} [options.description] - Team description
3200 * @param {string} [options.repo_names] - Repos to add the team to
3201 * @param {string} [options.privacy=secret] - The level of privacy the team should have. Can be either one
3202 * of: `secret`, or `closed`
3203 * @param {Requestable.callback} [cb] - will receive the updated team
3204 * @return {Promise} - the promise for the http request
3205 */
3206
3207 }, {
3208 key: 'editTeam',
3209 value: function editTeam(options, cb) {
3210 log('Editing Team ' + this.__teamId);
3211 return this._request('PATCH', '/teams/' + this.__teamId, options, cb);
3212 }
3213
3214 /**
3215 * List the users who are members of the Team
3216 * @see https://developer.github.com/v3/orgs/teams/#list-team-members
3217 * @param {object} options - Parameters for listing team users
3218 * @param {string} [options.role=all] - can be one of: `all`, `maintainer`, or `member`
3219 * @param {Requestable.callback} [cb] - will receive the list of users
3220 * @return {Promise} - the promise for the http request
3221 */
3222
3223 }, {
3224 key: 'listMembers',
3225 value: function listMembers(options, cb) {
3226 log('Getting members of Team ' + this.__teamId);
3227 return this._requestAllPages('/teams/' + this.__teamId + '/members', options, cb);
3228 }
3229
3230 /**
3231 * Get Team membership status for a user
3232 * @see https://developer.github.com/v3/orgs/teams/#get-team-membership
3233 * @param {string} username - can be one of: `all`, `maintainer`, or `member`
3234 * @param {Requestable.callback} [cb] - will receive the membership status of a user
3235 * @return {Promise} - the promise for the http request
3236 */
3237
3238 }, {
3239 key: 'getMembership',
3240 value: function getMembership(username, cb) {
3241 log('Getting membership of user ' + username + ' in Team ' + this.__teamId);
3242 return this._request('GET', '/teams/' + this.__teamId + '/memberships/' + username, undefined, cb);
3243 }
3244
3245 /**
3246 * Add a member to the Team
3247 * @see https://developer.github.com/v3/orgs/teams/#add-team-membership
3248 * @param {string} username - can be one of: `all`, `maintainer`, or `member`
3249 * @param {object} options - Parameters for adding a team member
3250 * @param {string} [options.role=member] - The role that this user should have in the team. Can be one
3251 * of: `member`, or `maintainer`
3252 * @param {Requestable.callback} [cb] - will receive the membership status of added user
3253 * @return {Promise} - the promise for the http request
3254 */
3255
3256 }, {
3257 key: 'addMembership',
3258 value: function addMembership(username, options, cb) {
3259 log('Adding user ' + username + ' to Team ' + this.__teamId);
3260 return this._request('PUT', '/teams/' + this.__teamId + '/memberships/' + username, options, cb);
3261 }
3262
3263 /**
3264 * Get repo management status for team
3265 * @see https://developer.github.com/v3/orgs/teams/#remove-team-membership
3266 * @param {string} owner - Organization name
3267 * @param {string} repo - Repo name
3268 * @param {Requestable.callback} [cb] - will receive the membership status of added user
3269 * @return {Promise} - the promise for the http request
3270 */
3271
3272 }, {
3273 key: 'isManagedRepo',
3274 value: function isManagedRepo(owner, repo, cb) {
3275 log('Getting repo management by Team ' + this.__teamId + ' for repo ' + owner + '/' + repo);
3276 return this._request204or404('/teams/' + this.__teamId + '/repos/' + owner + '/' + repo, undefined, cb);
3277 }
3278
3279 /**
3280 * Add or Update repo management status for team
3281 * @see https://developer.github.com/v3/orgs/teams/#add-or-update-team-repository
3282 * @param {string} owner - Organization name
3283 * @param {string} repo - Repo name
3284 * @param {object} options - Parameters for adding or updating repo management for the team
3285 * @param {string} [options.permission] - The permission to grant the team on this repository. Can be one
3286 * of: `pull`, `push`, or `admin`
3287 * @param {Requestable.callback} [cb] - will receive the membership status of added user
3288 * @return {Promise} - the promise for the http request
3289 */
3290
3291 }, {
3292 key: 'manageRepo',
3293 value: function manageRepo(owner, repo, options, cb) {
3294 log('Adding or Updating repo management by Team ' + this.__teamId + ' for repo ' + owner + '/' + repo);
3295 return this._request204or404('/teams/' + this.__teamId + '/repos/' + owner + '/' + repo, options, cb, 'PUT');
3296 }
3297
3298 /**
3299 * Remove repo management status for team
3300 * @see https://developer.github.com/v3/orgs/teams/#remove-team-repository
3301 * @param {string} owner - Organization name
3302 * @param {string} repo - Repo name
3303 * @param {Requestable.callback} [cb] - will receive the membership status of added user
3304 * @return {Promise} - the promise for the http request
3305 */
3306
3307 }, {
3308 key: 'unmanageRepo',
3309 value: function unmanageRepo(owner, repo, cb) {
3310 log('Remove repo management by Team ' + this.__teamId + ' for repo ' + owner + '/' + repo);
3311 return this._request204or404('/teams/' + this.__teamId + '/repos/' + owner + '/' + repo, undefined, cb, 'DELETE');
3312 }
3313
3314 /**
3315 * Delete Team
3316 * @see https://developer.github.com/v3/orgs/teams/#delete-team
3317 * @param {Requestable.callback} [cb] - will receive the list of repositories
3318 * @return {Promise} - the promise for the http request
3319 */
3320
3321 }, {
3322 key: 'deleteTeam',
3323 value: function deleteTeam(cb) {
3324 log('Deleting Team ' + this.__teamId);
3325 return this._request204or404('/teams/' + this.__teamId, undefined, cb, 'DELETE');
3326 }
3327 }]);
3328
3329 return Team;
3330}(_Requestable3.default);
3331
3332module.exports = Team;
3333
3334},{"./Requestable":9,"debug":undefined}],12:[function(require,module,exports){
3335'use strict';
3336
3337var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
3338
3339var _Requestable2 = require('./Requestable');
3340
3341var _Requestable3 = _interopRequireDefault(_Requestable2);
3342
3343var _debug = require('debug');
3344
3345var _debug2 = _interopRequireDefault(_debug);
3346
3347function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
3348
3349function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3350
3351function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
3352
3353function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
3354 * @file
3355 * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.
3356 * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.
3357 * Github.js is freely distributable.
3358 */
3359
3360var log = (0, _debug2.default)('github:user');
3361
3362/**
3363 * A User allows scoping of API requests to a particular Github user.
3364 */
3365
3366var User = function (_Requestable) {
3367 _inherits(User, _Requestable);
3368
3369 /**
3370 * Create a User.
3371 * @param {string} [username] - the user to use for user-scoped queries
3372 * @param {Requestable.auth} [auth] - information required to authenticate to Github
3373 * @param {string} [apiBase=https://api.github.com] - the base Github API URL
3374 */
3375 function User(username, auth, apiBase) {
3376 _classCallCheck(this, User);
3377
3378 var _this = _possibleConstructorReturn(this, (User.__proto__ || Object.getPrototypeOf(User)).call(this, auth, apiBase));
3379
3380 _this.__user = username;
3381 return _this;
3382 }
3383
3384 /**
3385 * Get the url for the request. (dependent on if we're requesting for the authenticated user or not)
3386 * @private
3387 * @param {string} endpoint - the endpoint being requested
3388 * @return {string} - the resolved endpoint
3389 */
3390
3391
3392 _createClass(User, [{
3393 key: '__getScopedUrl',
3394 value: function __getScopedUrl(endpoint) {
3395 if (this.__user) {
3396 return endpoint ? '/users/' + this.__user + '/' + endpoint : '/users/' + this.__user;
3397 } else {
3398 // eslint-disable-line
3399 switch (endpoint) {
3400 case '':
3401 return '/user';
3402
3403 case 'notifications':
3404 case 'gists':
3405 return '/' + endpoint;
3406
3407 default:
3408 return '/user/' + endpoint;
3409 }
3410 }
3411 }
3412
3413 /**
3414 * List the user's repositories
3415 * @see https://developer.github.com/v3/repos/#list-user-repositories
3416 * @param {Object} [options={}] - any options to refine the search
3417 * @param {Requestable.callback} [cb] - will receive the list of repositories
3418 * @return {Promise} - the promise for the http request
3419 */
3420
3421 }, {
3422 key: 'listRepos',
3423 value: function listRepos(options, cb) {
3424 if (typeof options === 'function') {
3425 cb = options;
3426 options = {};
3427 }
3428
3429 options = this._getOptionsWithDefaults(options);
3430
3431 log('Fetching repositories with options: ' + JSON.stringify(options));
3432 return this._requestAllPages(this.__getScopedUrl('repos'), options, cb);
3433 }
3434
3435 /**
3436 * List the orgs that the user belongs to
3437 * @see https://developer.github.com/v3/orgs/#list-user-organizations
3438 * @param {Requestable.callback} [cb] - will receive the list of organizations
3439 * @return {Promise} - the promise for the http request
3440 */
3441
3442 }, {
3443 key: 'listOrgs',
3444 value: function listOrgs(cb) {
3445 return this._request('GET', this.__getScopedUrl('orgs'), null, cb);
3446 }
3447
3448 /**
3449 * List followers of a user
3450 * @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user
3451 * @param {Requestable.callback} [cb] - will receive the list of followers
3452 * @return {Promise} - the promise for the http request
3453 */
3454
3455 }, {
3456 key: 'listFollowers',
3457 value: function listFollowers(cb) {
3458 return this._request('GET', this.__getScopedUrl('followers'), null, cb);
3459 }
3460
3461 /**
3462 * List users followed by another user
3463 * @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
3464 * @param {Requestable.callback} [cb] - will receive the list of who a user is following
3465 * @return {Promise} - the promise for the http request
3466 */
3467
3468 }, {
3469 key: 'listFollowing',
3470 value: function listFollowing(cb) {
3471 return this._request('GET', this.__getScopedUrl('following'), null, cb);
3472 }
3473
3474 /**
3475 * List the user's gists
3476 * @see https://developer.github.com/v3/gists/#list-a-users-gists
3477 * @param {Requestable.callback} [cb] - will receive the list of gists
3478 * @return {Promise} - the promise for the http request
3479 */
3480
3481 }, {
3482 key: 'listGists',
3483 value: function listGists(cb) {
3484 return this._request('GET', this.__getScopedUrl('gists'), null, cb);
3485 }
3486
3487 /**
3488 * List the user's notifications
3489 * @see https://developer.github.com/v3/activity/notifications/#list-your-notifications
3490 * @param {Object} [options={}] - any options to refine the search
3491 * @param {Requestable.callback} [cb] - will receive the list of repositories
3492 * @return {Promise} - the promise for the http request
3493 */
3494
3495 }, {
3496 key: 'listNotifications',
3497 value: function listNotifications(options, cb) {
3498 options = options || {};
3499 if (typeof options === 'function') {
3500 cb = options;
3501 options = {};
3502 }
3503
3504 options.since = this._dateToISO(options.since);
3505 options.before = this._dateToISO(options.before);
3506
3507 return this._request('GET', this.__getScopedUrl('notifications'), options, cb);
3508 }
3509
3510 /**
3511 * Show the user's profile
3512 * @see https://developer.github.com/v3/users/#get-a-single-user
3513 * @param {Requestable.callback} [cb] - will receive the user's information
3514 * @return {Promise} - the promise for the http request
3515 */
3516
3517 }, {
3518 key: 'getProfile',
3519 value: function getProfile(cb) {
3520 return this._request('GET', this.__getScopedUrl(''), null, cb);
3521 }
3522
3523 /**
3524 * Gets the list of starred repositories for the user
3525 * @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
3526 * @param {Requestable.callback} [cb] - will receive the list of starred repositories
3527 * @return {Promise} - the promise for the http request
3528 */
3529
3530 }, {
3531 key: 'listStarredRepos',
3532 value: function listStarredRepos(cb) {
3533 var requestOptions = this._getOptionsWithDefaults();
3534 return this._requestAllPages(this.__getScopedUrl('starred'), requestOptions, cb);
3535 }
3536
3537 /**
3538 * Gets the list of starred gists for the user
3539 * @see https://developer.github.com/v3/gists/#list-starred-gists
3540 * @param {Object} [options={}] - any options to refine the search
3541 * @param {Requestable.callback} [cb] - will receive the list of gists
3542 * @return {Promise} - the promise for the http request
3543 */
3544
3545 }, {
3546 key: 'listStarredGists',
3547 value: function listStarredGists(options, cb) {
3548 options = options || {};
3549 if (typeof options === 'function') {
3550 cb = options;
3551 options = {};
3552 }
3553 options.since = this._dateToISO(options.since);
3554 return this._request('GET', '/gists/starred', options, cb);
3555 }
3556
3557 /**
3558 * List email addresses for a user
3559 * @see https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
3560 * @param {Requestable.callback} [cb] - will receive the list of emails
3561 * @return {Promise} - the promise for the http request
3562 */
3563
3564 }, {
3565 key: 'getEmails',
3566 value: function getEmails(cb) {
3567 return this._request('GET', '/user/emails', null, cb);
3568 }
3569
3570 /**
3571 * Have the authenticated user follow this user
3572 * @see https://developer.github.com/v3/users/followers/#follow-a-user
3573 * @param {string} username - the user to follow
3574 * @param {Requestable.callback} [cb] - will receive true if the request succeeds
3575 * @return {Promise} - the promise for the http request
3576 */
3577
3578 }, {
3579 key: 'follow',
3580 value: function follow(username, cb) {
3581 return this._request('PUT', '/user/following/' + username, null, cb);
3582 }
3583
3584 /**
3585 * Have the currently authenticated user unfollow this user
3586 * @see https://developer.github.com/v3/users/followers/#follow-a-user
3587 * @param {string} username - the user to unfollow
3588 * @param {Requestable.callback} [cb] - receives true if the request succeeds
3589 * @return {Promise} - the promise for the http request
3590 */
3591
3592 }, {
3593 key: 'unfollow',
3594 value: function unfollow(username, cb) {
3595 return this._request('DELETE', '/user/following/' + username, null, cb);
3596 }
3597
3598 /**
3599 * Create a new repository for the currently authenticated user
3600 * @see https://developer.github.com/v3/repos/#create
3601 * @param {object} options - the repository definition
3602 * @param {Requestable.callback} [cb] - will receive the API response
3603 * @return {Promise} - the promise for the http request
3604 */
3605
3606 }, {
3607 key: 'createRepo',
3608 value: function createRepo(options, cb) {
3609 return this._request('POST', '/user/repos', options, cb);
3610 }
3611 }]);
3612
3613 return User;
3614}(_Requestable3.default);
3615
3616module.exports = User;
3617
3618},{"./Requestable":9,"debug":undefined}]},{},[2])(2)
3619});
3620
3621//# sourceMappingURL=GitHub.js.map