88
99import Requestable from './Requestable' ;
1010import Utf8 from 'utf8' ;
11- import { Base64 } from 'js-base64' ;
11+ import {
12+ Base64
13+ } from 'js-base64' ;
1214import debug from 'debug' ;
1315const log = debug ( 'github:repository' ) ;
1416
@@ -154,7 +156,7 @@ class Repository extends Requestable {
154156 /**
155157 * List the commits on a repository, optionally filtering by path, author or time range
156158 * @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
158160 * @param {string } [options.sha] - the SHA or branch to start from
159161 * @param {string } [options.path] - the path to search on
160162 * @param {string } [options.author] - the commit author
@@ -221,26 +223,34 @@ class Repository extends Requestable {
221223 return this . _request ( 'POST' , `/repos/${ this . __fullname } /git/blobs` , postBody , cb ) ;
222224 }
223225
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+ */
224231 _getContentObject ( content ) {
225232 if ( typeof content === 'string' ) {
226233 log ( 'contet is a string' ) ;
227234 return {
228235 content : Utf8 . encode ( content ) ,
229236 encoding : 'utf-8'
230237 } ;
238+
231239 } else if ( typeof Buffer !== 'undefined' && content instanceof Buffer ) {
232240 log ( 'We appear to be in Node' ) ;
233241 return {
234242 content : content . toString ( 'base64' ) ,
235243 encoding : 'base64'
236244 } ;
245+
237246 } else if ( typeof Blob !== 'undefined' && content instanceof Blob ) {
238247 log ( 'We appear to be in the browser' ) ;
239248 return {
240249 content : Base64 . encode ( content ) ,
241250 encoding : 'base64'
242251 } ;
243- } else {
252+
253+ } else { // eslint-disable-line
244254 log ( `Not sure what this content is: ${ typeof content } , ${ JSON . stringify ( content ) } ` ) ;
245255 throw new Error ( 'Unknown content passed to postBlob. Must be string or Buffer (node) or Blob (web)' ) ;
246256 }
@@ -258,8 +268,8 @@ class Repository extends Requestable {
258268 */
259269 updateTree ( baseTreeSHA , path , blobSHA , cb ) {
260270 let newTree = {
261- ' base_tree' : baseTreeSHA ,
262- ' tree' : [ {
271+ base_tree : baseTreeSHA , // eslint-disable-line
272+ tree : [ {
263273 path : path ,
264274 sha : blobSHA ,
265275 mode : '100644' ,
@@ -279,7 +289,10 @@ class Repository extends Requestable {
279289 * @return {Promise } - the promise for the http request
280290 */
281291 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 ) ;
283296 }
284297
285298 /**
@@ -315,7 +328,10 @@ class Repository extends Requestable {
315328 * @return {Promise } - the promise for the http request
316329 */
317330 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 ) ;
319335 }
320336
321337 /**
@@ -371,7 +387,9 @@ class Repository extends Requestable {
371387 */
372388 getContents ( ref , path , raw , cb ) {
373389 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 ) ;
375393 }
376394
377395 /**
@@ -411,7 +429,10 @@ class Repository extends Requestable {
411429 return this . getRef ( `heads/${ oldBranch } ` )
412430 . then ( ( response ) => {
413431 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 ) ;
415436 } ) ;
416437 }
417438
@@ -502,33 +523,33 @@ class Repository extends Requestable {
502523 }
503524
504525 /**
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
506527 * @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
509530 * @param {Function } cb - will receive the commit in which the move occurred
510531 * @return {Promise } - the promise for the http request
511532 */
512- move ( branch , old_path , new_path , cb ) {
533+ move ( branch , oldPath , newPath , cb ) {
513534 return this . getRef ( `heads/${ branch } ` )
514535 . then ( ( response ) => {
515536 return this . getTree ( `${ response . data . object . sha } ?recursive=true` )
516537 . then ( ( response ) => {
517- var _resp = response ;
538+ let _resp = response ;
518539 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 ;
521542 }
522543 if ( ref . type === 'tree' ) {
523544 delete ref . sha ;
524545 }
525546 } ) ;
526547 return this . createTree ( response . data . tree ) . then (
527548 ( 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+ } ) ;
532553 }
533554 ) ;
534555 } ) ;
@@ -542,7 +563,7 @@ class Repository extends Requestable {
542563 * @param {string } path - the path for the file
543564 * @param {string } content - the contents of the file
544565 * @param {string } message - the commit message
545- * @param {Object } [options]
566+ * @param {Object } [options] - commit options
546567 * @param {Object } [options.author] - the author of the commit
547568 * @param {Object } [options.commiter] - the committer
548569 * @param {boolean } [options.encode] - true if the content should be base64 encoded
0 commit comments