8
8
9
9
import Requestable from './Requestable' ;
10
10
import Utf8 from 'utf8' ;
11
- import { Base64 } from 'js-base64' ;
11
+ import {
12
+ Base64
13
+ } from 'js-base64' ;
12
14
import debug from 'debug' ;
13
15
const log = debug ( 'github:repository' ) ;
14
16
@@ -154,7 +156,7 @@ class Repository extends Requestable {
154
156
/**
155
157
* List the commits on a repository, optionally filtering by path, author or time range
156
158
* @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
157
- * @param {Object } [options]
159
+ * @param {Object } [options] - the filtering options for commits
158
160
* @param {string } [options.sha] - the SHA or branch to start from
159
161
* @param {string } [options.path] - the path to search on
160
162
* @param {string } [options.author] - the commit author
@@ -221,26 +223,34 @@ class Repository extends Requestable {
221
223
return this . _request ( 'POST' , `/repos/${ this . __fullname } /git/blobs` , postBody , cb ) ;
222
224
}
223
225
226
+ /**
227
+ * Get the object that represents the provided content
228
+ * @param {string|Buffer|Blob } content - the content to send to the server
229
+ * @return {Object } the representation of `content` for the GitHub API
230
+ */
224
231
_getContentObject ( content ) {
225
232
if ( typeof content === 'string' ) {
226
233
log ( 'contet is a string' ) ;
227
234
return {
228
235
content : Utf8 . encode ( content ) ,
229
236
encoding : 'utf-8'
230
237
} ;
238
+
231
239
} else if ( typeof Buffer !== 'undefined' && content instanceof Buffer ) {
232
240
log ( 'We appear to be in Node' ) ;
233
241
return {
234
242
content : content . toString ( 'base64' ) ,
235
243
encoding : 'base64'
236
244
} ;
245
+
237
246
} else if ( typeof Blob !== 'undefined' && content instanceof Blob ) {
238
247
log ( 'We appear to be in the browser' ) ;
239
248
return {
240
249
content : Base64 . encode ( content ) ,
241
250
encoding : 'base64'
242
251
} ;
243
- } else {
252
+
253
+ } else { // eslint-disable-line
244
254
log ( `Not sure what this content is: ${ typeof content } , ${ JSON . stringify ( content ) } ` ) ;
245
255
throw new Error ( 'Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web)' ) ;
246
256
}
@@ -258,8 +268,8 @@ class Repository extends Requestable {
258
268
*/
259
269
updateTree ( baseTreeSHA , path , blobSHA , cb ) {
260
270
let newTree = {
261
- ' base_tree' : baseTreeSHA ,
262
- ' tree' : [ {
271
+ base_tree : baseTreeSHA , // eslint-disable-line
272
+ tree : [ {
263
273
path : path ,
264
274
sha : blobSHA ,
265
275
mode : '100644' ,
@@ -279,7 +289,10 @@ class Repository extends Requestable {
279
289
* @return {Promise } - the promise for the http request
280
290
*/
281
291
createTree ( tree , baseSHA , cb ) {
282
- return this . _request ( 'POST' , `/repos/${ this . __fullname } /git/trees` , { tree, base_tree : baseSHA } , cb ) ; // jscs:ignore
292
+ return this . _request ( 'POST' , `/repos/${ this . __fullname } /git/trees` , {
293
+ tree,
294
+ base_tree : baseSHA // eslint-disable-line
295
+ } , cb ) ;
283
296
}
284
297
285
298
/**
@@ -315,7 +328,10 @@ class Repository extends Requestable {
315
328
* @return {Promise } - the promise for the http request
316
329
*/
317
330
updateHead ( ref , commitSHA , force , cb ) {
318
- return this . _request ( 'PATCH' , `/repos/${ this . __fullname } /git/refs/${ ref } ` , { sha : commitSHA , force : force } , cb ) ;
331
+ return this . _request ( 'PATCH' , `/repos/${ this . __fullname } /git/refs/${ ref } ` , {
332
+ sha : commitSHA ,
333
+ force : force
334
+ } , cb ) ;
319
335
}
320
336
321
337
/**
@@ -371,7 +387,9 @@ class Repository extends Requestable {
371
387
*/
372
388
getContents ( ref , path , raw , cb ) {
373
389
path = path ? `${ encodeURI ( path ) } ` : '' ;
374
- return this . _request ( 'GET' , `/repos/${ this . __fullname } /contents/${ path } ` , { ref} , cb , raw ) ;
390
+ return this . _request ( 'GET' , `/repos/${ this . __fullname } /contents/${ path } ` , {
391
+ ref
392
+ } , cb , raw ) ;
375
393
}
376
394
377
395
/**
@@ -411,7 +429,10 @@ class Repository extends Requestable {
411
429
return this . getRef ( `heads/${ oldBranch } ` )
412
430
. then ( ( response ) => {
413
431
let sha = response . data . object . sha ;
414
- return this . createRef ( { sha, ref : `refs/heads/${ newBranch } ` } , cb ) ;
432
+ return this . createRef ( {
433
+ sha,
434
+ ref : `refs/heads/${ newBranch } `
435
+ } , cb ) ;
415
436
} ) ;
416
437
}
417
438
@@ -502,33 +523,33 @@ class Repository extends Requestable {
502
523
}
503
524
504
525
/**
505
- * Change all references in a repo from old_path to new_path
526
+ * Change all references in a repo from oldPath to new_path
506
527
* @param {string } branch - the branch to carry out the reference change, or the default branch if not specified
507
- * @param {string } old_path - original path
508
- * @param {string } new_path - new reference path
528
+ * @param {string } oldPath - original path
529
+ * @param {string } newPath - new reference path
509
530
* @param {Function } cb - will receive the commit in which the move occurred
510
531
* @return {Promise } - the promise for the http request
511
532
*/
512
- move ( branch , old_path , new_path , cb ) {
533
+ move ( branch , oldPath , newPath , cb ) {
513
534
return this . getRef ( `heads/${ branch } ` )
514
535
. then ( ( response ) => {
515
536
return this . getTree ( `${ response . data . object . sha } ?recursive=true` )
516
537
. then ( ( response ) => {
517
- var _resp = response ;
538
+ let _resp = response ;
518
539
response . data . tree . forEach ( ( ref ) => {
519
- if ( ref . path === old_path ) {
520
- ref . path = new_path ;
540
+ if ( ref . path === oldPath ) {
541
+ ref . path = newPath ;
521
542
}
522
543
if ( ref . type === 'tree' ) {
523
544
delete ref . sha ;
524
545
}
525
546
} ) ;
526
547
return this . createTree ( response . data . tree ) . then (
527
548
( response ) => {
528
- return this . commit ( _resp . data . sha , response . data . sha , `Renamed '${ old_path } ' to '${ new_path } '` )
529
- . then ( ( response ) => {
530
- return this . updateHead ( `heads/${ branch } ` , response . data . sha , true , cb ) ;
531
- } ) ;
549
+ return this . commit ( _resp . data . sha , response . data . sha , `Renamed '${ oldPath } ' to '${ newPath } '` )
550
+ . then ( ( response ) => {
551
+ return this . updateHead ( `heads/${ branch } ` , response . data . sha , true , cb ) ;
552
+ } ) ;
532
553
}
533
554
) ;
534
555
} ) ;
@@ -542,7 +563,7 @@ class Repository extends Requestable {
542
563
* @param {string } path - the path for the file
543
564
* @param {string } content - the contents of the file
544
565
* @param {string } message - the commit message
545
- * @param {Object } [options]
566
+ * @param {Object } [options] - commit options
546
567
* @param {Object } [options.author] - the author of the commit
547
568
* @param {Object } [options.commiter] - the committer
548
569
* @param {boolean } [options.encode] - true if the content should be base64 encoded
0 commit comments