@@ -81,6 +81,18 @@ export default function githubFs(token, settings) {
8181 } ;
8282 }
8383
84+ /**
85+ * Get commit message from user
86+ * @param {string } message
87+ * @returns
88+ */
89+ async function getCommitMessage ( message ) {
90+ if ( settings . askCommitMessage ) {
91+ return await prompt ( 'Commit message' , message , 'text' ) ;
92+ }
93+ return message ;
94+ }
95+
8496 /**
8597 *
8698 * @param {string } user
@@ -135,26 +147,19 @@ export default function githubFs(token, settings) {
135147 let { data } = await repo . getBlob ( sha , 'blob' ) ;
136148 data = await data . arrayBuffer ( ) ;
137149
138- // const textEncoder = new TextEncoder();
139- // data = textEncoder.encode(window.atob(data));
140-
141150 if ( encoding ) {
142151 return helpers . decodeText ( data , encoding ) ;
143152 }
144153
145154 return data ;
146155 } ,
147156 async writeFile ( data ) {
157+ const commitMessage = await getCommitMessage ( `update ${ path } ` ) ;
148158 await init ( ) ;
149- let commitMessage = `update ${ path } ` ;
150-
151- if ( settings . askCommitMessage ) {
152- commitMessage = await prompt ( 'Commit message' , commitMessage , 'text' ) ;
153- }
154-
155159 await repo . writeFile ( branch , path , data , commitMessage ) ;
156160 } ,
157161 async createFile ( name , data = '' ) {
162+ await init ( ) ;
158163 const newPath = path === '' ? name : Url . join ( path , name ) ;
159164 // check if file exists
160165 let sha ;
@@ -168,7 +173,8 @@ export default function githubFs(token, settings) {
168173 throw new Error ( 'File already exists' ) ;
169174 }
170175
171- await repo . writeFile ( branch , newPath , data , `create ${ newPath } ` ) ;
176+ const commitMessage = await getCommitMessage ( `create ${ newPath } ` ) ;
177+ await repo . writeFile ( branch , newPath , data , commitMessage ) ;
172178 return githubFs . constructUrl ( 'repo' , user , repoName , newPath , branch ) ;
173179 } ,
174180 async createDirectory ( dirname ) {
@@ -187,7 +193,8 @@ export default function githubFs(token, settings) {
187193 }
188194
189195 const createPath = Url . join ( newPath , '.gitkeep' ) ;
190- await repo . writeFile ( branch , createPath , '' , `create ${ newPath } ` ) ;
196+ const commitMessage = await getCommitMessage ( `create ${ newPath } ` ) ;
197+ await repo . writeFile ( branch , createPath , '' , commitMessage ) ;
191198 return githubFs . constructUrl ( 'repo' , user , repoName , newPath , branch ) ;
192199 } ,
193200 async copyTo ( dest ) {
@@ -196,7 +203,8 @@ export default function githubFs(token, settings) {
196203 async delete ( ) {
197204 await init ( ) ;
198205 await getSha ( ) ;
199- await repo . deleteFile ( branch , path , `delete ${ path } ` , sha ) ;
206+ const commitMessage = await getCommitMessage ( `delete ${ path } ` ) ;
207+ await repo . deleteFile ( branch , path , commitMessage , sha ) ;
200208 } ,
201209 async moveTo ( dest ) {
202210 await init ( ) ;
0 commit comments