11/**
2- * Github Helper for Boostnote Github Sync.
2+ * Github Helper for Boostnote Github Sync.
33 * This helper currently supports creating/updating files only. Deleting files is not yet supported.
44 */
55
@@ -9,14 +9,14 @@ const { resolve } = require('url');
99const { join, basename } = require ( 'path' ) ;
1010const { promisify } = require ( 'util' ) ;
1111const httpStatus = require ( './httpStatus' ) ;
12- const { pathDepth , trimSlashes} = require ( './helpers' ) ;
12+ const { trimSlashes } = require ( './helpers' ) ;
1313
1414module . exports = class GithubHelper {
1515 /**
1616 * Create a Github Helper object
17- * @param {* } container
18- * @param {* } logger
19- * @param {* } config
17+ * @param {* } container
18+ * @param {* } logger
19+ * @param {* } config
2020 */
2121 constructor ( container , logger , config ) {
2222 this . container = container ;
@@ -45,17 +45,17 @@ module.exports = class GithubHelper {
4545 Authorization : `Bearer ${ this . apiConfig . accessToken } ` ,
4646 'User-Agent' : '' ,
4747 'Content-Type' : 'application/json' ,
48- ' Accept' : 'application/json'
48+ Accept : 'application/json'
4949 } ,
5050 body,
5151 json : true
5252 } ) ;
53-
53+
5454 return {
5555 status : response . statusCode ,
5656 body : response . body
5757 } ;
58- }
58+ } ;
5959 }
6060
6161 /**
@@ -69,7 +69,7 @@ module.exports = class GithubHelper {
6969 * Get github user id
7070 */
7171 async fetchGithubUser ( ) {
72- const { status, body} = await this . sendRequest ( {
72+ const { status, body } = await this . sendRequest ( {
7373 method : 'get' ,
7474 path : '/user'
7575 } ) ;
@@ -87,9 +87,9 @@ module.exports = class GithubHelper {
8787 * Get a reference to the HEAD of sync repository
8888 */
8989 async getHead ( ) {
90- const { status, body} = await this . sendRequest ( {
90+ const { status, body } = await this . sendRequest ( {
9191 method : 'get' ,
92- path : `/repos/${ this . userId } /${ this . repo . name } /git/refs/${ this . defaultRefs } ` , // default notes branch is 'master'
92+ path : `/repos/${ this . userId } /${ this . repo . name } /git/refs/${ this . defaultRefs } ` // default notes branch is 'master'
9393 } ) ;
9494
9595 if ( status !== httpStatus . OK ) {
@@ -103,10 +103,10 @@ module.exports = class GithubHelper {
103103
104104 /**
105105 * Grab the tree information from the commit that HEAD points to
106- * @param {string } hash
106+ * @param {string } hash
107107 */
108108 async getCommitTreeSHA ( hash ) {
109- const { status, body} = await this . sendRequest ( {
109+ const { status, body } = await this . sendRequest ( {
110110 method : 'get' ,
111111 path : `/repos/${ this . userId } /${ this . repo . name } /git/commits/${ hash } `
112112 } ) ;
@@ -123,10 +123,10 @@ module.exports = class GithubHelper {
123123
124124 /**
125125 * Post the content-to-by-synced as a git blob
126- * @param {string } localFile
126+ * @param {string } localFile
127127 */
128128 async publishBlobFromContent ( { content, encoding } ) {
129- const { status, body} = await this . sendRequest ( {
129+ const { status, body } = await this . sendRequest ( {
130130 method : 'post' ,
131131 path : `/repos/${ this . userId } /${ this . repo . name } /git/blobs` ,
132132 body : { content, encoding }
@@ -151,17 +151,17 @@ module.exports = class GithubHelper {
151151 const GITHUB_BLOB_MODE = '100644' ;
152152 const GITHUB_BLOB_TYPE = 'blob' ;
153153
154- const { status, body} = await this . sendRequest ( {
154+ const { status, body } = await this . sendRequest ( {
155155 method : 'post' ,
156156 path : `/repos/${ this . userId } /${ this . repo . name } /git/trees` ,
157157 body : {
158- ' base_tree' : baseTreeSHA ,
159- ' tree' : [
158+ base_tree : baseTreeSHA ,
159+ tree : [
160160 {
161- ' path' : trimSlashes ( remoteFilePath ) , // remove leading and trailing slashes if any
162- ' mode' : GITHUB_BLOB_MODE ,
163- ' type' : GITHUB_BLOB_TYPE ,
164- ' sha' : blobSHA
161+ path : trimSlashes ( remoteFilePath ) , // remove leading and trailing slashes if any
162+ mode : GITHUB_BLOB_MODE ,
163+ type : GITHUB_BLOB_TYPE ,
164+ sha : blobSHA
165165 }
166166 ]
167167 }
@@ -176,24 +176,24 @@ module.exports = class GithubHelper {
176176
177177 /**
178178 * Create a new commit after updating tree
179- * @param {object } options
179+ * @param {object } options
180180 * @param {string } options.parentCommitSHA
181181 * @param {string } options.treeSHA
182182 * @param {string } options.message
183183 */
184184 async commit ( { parentCommitSHA, treeSHA, message } ) {
185- const { status, body} = await this . sendRequest ( {
185+ const { status, body } = await this . sendRequest ( {
186186 method : 'post' ,
187187 path : `/repos/${ this . userId } /${ this . repo . name } /git/commits` ,
188188 body : {
189- 'message' : message ,
190- ' author' : {
191- ' name' : this . commitConfig . userName ,
192- ' email' : this . commitConfig . userEmail ,
193- ' date' : ( new Date ( ) ) . toISOString ( )
189+ message,
190+ author : {
191+ name : this . commitConfig . userName ,
192+ email : this . commitConfig . userEmail ,
193+ date : ( new Date ( ) ) . toISOString ( )
194194 } ,
195- ' parents' : [ parentCommitSHA ] ,
196- ' tree' : treeSHA
195+ parents : [ parentCommitSHA ] ,
196+ tree : treeSHA
197197 }
198198 } ) ;
199199
@@ -206,10 +206,10 @@ module.exports = class GithubHelper {
206206
207207 /**
208208 * Update head with new commit
209- * @param {string } commitSHA
209+ * @param {string } commitSHA
210210 */
211211 async updateHead ( commitSHA ) {
212- const { status, body} = await this . sendRequest ( {
212+ const { status, body } = await this . sendRequest ( {
213213 method : 'patch' ,
214214 path : `/repos/${ this . userId } /${ this . repo . name } /git/refs/${ this . defaultRefs } ` ,
215215 body : {
@@ -224,12 +224,12 @@ module.exports = class GithubHelper {
224224 }
225225 return body ;
226226 }
227-
227+
228228 /**
229229 * Convenience function to sync file to github
230- * @param {object } options
230+ * @param {object } options
231231 * @param {string } options.filePath
232- * @param {string } options.remotePath
232+ * @param {string } options.remotePath
233233 */
234234 async publishFile ( { filePath, remotePath } ) {
235235 const encoding = 'base64' ;
@@ -264,4 +264,4 @@ module.exports = class GithubHelper {
264264 this . logger . debug ( `Commit ${ commitHash } created!` ) ;
265265 await this . updateHead ( commitHash ) ;
266266 }
267- }
267+ } ;
0 commit comments