diff --git a/index.html b/index.html index 9b3b180e..60f7d85e 100644 --- a/index.html +++ b/index.html @@ -365,7 +365,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) { - + diff --git a/src/services.ts b/src/services.ts index 0c42543c..568326a9 100644 --- a/src/services.ts +++ b/src/services.ts @@ -24,6 +24,7 @@ export interface GHSession extends GHRepoMetadata { repo : any; // [repo object] tree? : any; // [tree object] head? : any; // [head ref] + commit?: any; // after commit() paths? : string[]; } @@ -263,7 +264,7 @@ export class GithubService { }); } - commitPush( ghurl:string, message:string, files:{path:string,data:FileData}[] ) : Promise { + commit( ghurl:string, message:string, files:{path:string,data:FileData}[] ) : Promise { var sess : GHSession; return this.getGithubHEADTree(ghurl).then( (session) => { sess = session; @@ -303,10 +304,17 @@ export class GithubService { sess.head.object.sha ] }); + }).then( (commit1) => { + return sess.repo.commits(commit1.sha).fetch(); }).then( (commit) => { - return sess.head.update({ - sha: commit.sha - }); + sess.commit = commit; + return sess; + }); + } + + push(sess:GHSession) : Promise { + return sess.head.update({ + sha: sess.commit.sha }).then( (update) => { return sess; }); diff --git a/src/ui.ts b/src/ui.ts index d1f2ab51..e6277f27 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -402,7 +402,7 @@ function getGithubService() { function getBoundGithubURL() : string { var toks = (repo_id||'').split('/'); if (toks.length != 2) { - alertError("You are not in a GitHub repository. Choose Import or Publish first."); + alertError("You are not in a GitHub repository. Choose one from the pulldown, or Import or Publish one."); return null; } return 'https://github.com/' + toks[0] + '/' + toks[1]; @@ -525,7 +525,9 @@ function pushChangesToGithub(message:string) { setWaitDialog(true); return getGithubService().login().then( () => { setWaitProgress(0.5); - return getGithubService().commitPush(ghurl, message, files); + return getGithubService().commit(ghurl, message, files); + }).then( (sess) => { + return getGithubService().push(sess); }).then( (sess) => { setWaitDialog(false); alertInfo("Pushed files to " + ghurl); @@ -777,7 +779,7 @@ function populateRepos(sel) { } function populateFiles(sel:JQuery, category:string, prefix:string, callback:() => void) { - store.keys(function(err, keys : string[]) { + store.keys().then( (keys:string[]) => { var foundSelected = false; var numFound = 0; if (!keys) keys = []; @@ -804,10 +806,10 @@ function populateFiles(sel:JQuery, category:string, prefix:string, callback:() = function updateSelector() { var sel = $("#preset_select").empty(); if (!repo_id) { + populateRepos(sel); // normal: populate local and shared files populateFiles(sel, "Local Files", "local/", () => { populateFiles(sel, "Shared", "shared/", () => { - populateRepos(sel); populateExamples(sel); sel.css('visibility','visible'); }); diff --git a/test/cli/testgithub.js b/test/cli/testgithub.js index 416cf265..3c254468 100644 --- a/test/cli/testgithub.js +++ b/test/cli/testgithub.js @@ -107,10 +107,13 @@ describe('Store', function() { for (var i=0; i<256; i++) binfile[i] = i; var files = [ - {path:'text.txt', data:'hello world'}, + {path:'text.txt', data:'hello world ' + Math.random()}, {path:'data.bin', data:binfile} ]; - gh.commitPush('https://github.com/pzpinfo/testrepo3', 'test commit', files).then( (sess) => { + gh.commit('https://github.com/pzpinfo/testrepo3', 'test commit', files).then( (sess) => { + return gh.push(sess); + }).then( (sess) => { + console.log(sess.commit); done(); }); }); @@ -122,7 +125,7 @@ describe('Store', function() { var files = [ {path:'text.txt', data:'hello world'} ]; - gh.commitPush('https://github.com/brovador/NESnake/tree/master/src', 'test commit', files) + gh.commit('https://github.com/brovador/NESnake/tree/master/src', 'test commit', files) .catch( (e) => { console.log(e); assert.equal(e, 'Sorry, right now you can only commit files to the root directory of a repository.');