github: confirm push w/ dialog

This commit is contained in:
Steven Hugg 2019-05-12 15:01:33 -04:00
parent efe0e032fb
commit 1cb3c960ee
3 changed files with 34 additions and 3 deletions

View File

@ -155,7 +155,6 @@ TODO:
- local/ files in repository?
- build ca65 projects w/ no crt0? https://github.com/pinobatch/thwaite-nes/blob/master/makefile
- switching platform of a repo?
- should have a preview of commit
WEB WORKER FORMAT

View File

@ -307,7 +307,7 @@ function _createNewFile(e) {
getSkeletonFile(path).then( (result) => {
return store.setItem(path, result || "\n");
}).then(() => {
reloadProject("local/" + filename);
reloadProject(path);
});
}
}
@ -509,6 +509,35 @@ function _pullProjectFromGithub(e) {
});
}
function confirmCommit(sess) : Promise<GHSession> {
return new Promise( (resolve, reject) => {
var files = sess.commit.files;
console.log(files);
// anything changed?
if (files.length == 0) {
setWaitDialog(false);
bootbox.alert("No files changed.");
}
// build commit confirm message
var msg = "";
for (var f of files) {
msg += f.filename + ": " + f.status;
if (f.additions || f.deletions || f.changes) {
msg += " (" + f.additions + " additions, " + f.deletions + " deletions, " + f.changes + " changes)";
}
msg += "<br/>";
}
// show dialog, continue when yes
bootbox.confirm(msg, (ok) => {
if (ok) {
resolve(sess);
} else {
setWaitDialog(false);
}
});
});
}
function pushChangesToGithub(message:string) {
var ghurl = getBoundGithubURL();
if (!ghurl) return;
@ -526,6 +555,8 @@ function pushChangesToGithub(message:string) {
return getGithubService().login().then( () => {
setWaitProgress(0.5);
return getGithubService().commit(ghurl, message, files);
}).then( (sess) => {
return confirmCommit(sess);
}).then( (sess) => {
return getGithubService().push(sess);
}).then( (sess) => {

View File

@ -107,13 +107,14 @@ describe('Store', function() {
for (var i=0; i<256; i++)
binfile[i] = i;
var files = [
{path:'text.txt', data:'hello world ' + Math.random()},
{path:'text.txt', data:'hello world'},
{path:'data.bin', data:binfile}
];
gh.commit('https://github.com/pzpinfo/testrepo3', 'test commit', files).then( (sess) => {
return gh.push(sess);
}).then( (sess) => {
console.log(sess.commit);
assert.equal(0, sess.commit.files.length);
done();
});
});