Skip to content

Commit 566aa9c

Browse files
committed
version 1.1.2
1 parent 73e5596 commit 566aa9c

5 files changed

Lines changed: 53 additions & 25 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "acode-plugin-github",
3-
"version": "1.0.3",
3+
"version": "1.1.2",
44
"description": "Github plugin for acode editor",
55
"main": "dist/main.js",
66
"repository": "https://github.com/deadlyjack/acode-plugin-github.git",

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "acode.plugin.github",
33
"name": "Github",
44
"main": "dist/main.js",
5-
"version": "1.0.3",
5+
"version": "1.1.2",
66
"readme": "readme.md",
77
"icon": "icon.png",
88
"files": [],

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Access your gist/repositories without cloning/downloading it. To access search `
1414

1515
- **1.0.2**: Create/Delete file, directory in repository.
1616
- **1.0.3**: Bugs fixes.
17+
- **1.1.2**: Ask for commit message.

src/githubFs.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

src/main.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ class AcodePlugin {
3030
#gists = [];
3131

3232
async init() {
33-
this.settings = appSettings.value[plugin.id];
34-
35-
if (!this.settings) {
36-
this.settings = {
37-
askCommitMessage: false,
38-
};
39-
appSettings.value[plugin.id] = this.settings;
40-
appSettings.update();
41-
}
42-
4333
this.commands.forEach(command => {
4434
editorManager.editor.commands.addCommand(command);
4535
});
@@ -487,6 +477,35 @@ class AcodePlugin {
487477
}
488478
]
489479
}
480+
481+
get settings() {
482+
const settings = appSettings.value[plugin.id];
483+
if (!settings) {
484+
appSettings.value[plugin.id] = {
485+
askCommitMessage: true,
486+
};
487+
appSettings.update();
488+
}
489+
return appSettings.value[plugin.id];
490+
}
491+
492+
get settingsJson() {
493+
const list = [
494+
{
495+
key: 'askCommitMessage',
496+
text: 'Ask for commit message',
497+
checkbox: this.settings.askCommitMessage,
498+
}
499+
];
500+
501+
return {
502+
list,
503+
cb: (key, value) => {
504+
this.settings[key] = value;
505+
appSettings.update();
506+
}
507+
}
508+
}
490509
}
491510

492511
if (window.acode) {
@@ -497,7 +516,7 @@ if (window.acode) {
497516
}
498517
acodePlugin.baseUrl = baseUrl;
499518
await acodePlugin.init($page, cacheFile, cacheFileUrl);
500-
});
519+
}, acodePlugin.settingsJson);
501520
acode.setPluginUnmount(plugin.id, () => {
502521
acodePlugin.destroy();
503522
});

0 commit comments

Comments
 (0)