diff --git a/doc/notes.txt b/doc/notes.txt index 28fe4166..0d52a834 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -71,7 +71,6 @@ TODO: - what if error in include file you can't edit b/c it never appears? - markdown, verilog: can't share - https://www.crowdsupply.com/tinyfpga/tinyfpga-bx -- HTTPS warning - stego shareable images (http://pico-8.wikia.com/wiki/P8PNGFileFormat) - https://makecode.com/language? - open ROM from URL? diff --git a/src/services.ts b/src/services.ts index 2ac19f60..4b46d154 100644 --- a/src/services.ts +++ b/src/services.ts @@ -10,6 +10,7 @@ declare var firebase; export interface GHRepoMetadata { url : string; // github url platform_id : string; // e.g. "vcs" + sha? : string; // head commit sha mainPath?: string; // main file path } @@ -31,7 +32,16 @@ export interface GHSession extends GHRepoMetadata { const README_md_template = "$NAME\n=====\n\n[Open this project in 8bitworkshop](http://8bitworkshop.com/redir.html?platform=$PLATFORM&importURL=$GITHUBURL&file=$MAINFILE).\n"; export function getRepos() : {[key:string]:GHRepoMetadata} { - return JSON.parse(localStorage.getItem('__repos') || '{}'); + var repos = {}; + for (var i=0; i { sess.head = head; - return sess.repo.git.trees(head.object.sha).fetch(); + sess.sha = head.object.sha; + return sess.repo.git.trees(sess.sha).fetch(); }) .then( (tree) => { if (sess.subtreepath) { @@ -154,13 +165,13 @@ export class GithubService { } bind(sess:GHSession, dobind:boolean) { - var repos = getRepos(); + var key = '__repo__' + sess.repopath; if (dobind) { - repos[sess.repopath] = {url:sess.url, platform_id:sess.platform_id, mainPath:sess.mainPath}; + var repodata : GHRepoMetadata = {url:sess.url, platform_id:sess.platform_id, mainPath:sess.mainPath, sha:sess.sha}; + localStorage.setItem(key, JSON.stringify(repodata)); } else { - delete repos[sess.repopath]; + localStorage.removeItem(key); } - localStorage.setItem('__repos', JSON.stringify(repos)); } import(ghurl:string) : Promise { diff --git a/test/cli/testgithub.js b/test/cli/testgithub.js index eb587216..79aebbd7 100644 --- a/test/cli/testgithub.js +++ b/test/cli/testgithub.js @@ -15,7 +15,7 @@ var Octokat = require('octokat'); var test_platform_id = "_TEST"; function newGH(store, platform_id) { - localStorage.removeItem('__repos'); + localStorage.clear(); // pzpinfo user var project = new prj.CodeProject({}, platform_id||test_platform_id, null, store); project.mainPath = 'local/main.asm'; @@ -33,7 +33,12 @@ describe('Store', function() { gh.importAndPull('https://github.com/pzpinfo/test123123/').then( (sess) => { console.log(sess.paths); assert.equal(2, sess.paths.length); - assert.deepEqual(serv.getRepos(), {"pzpinfo/test123123":{url: 'https://github.com/pzpinfo/test123123/', platform_id: 'vcs', mainPath:'helloworld.bas'}}); + assert.deepEqual(serv.getRepos(), {"pzpinfo/test123123":{ + url: 'https://github.com/pzpinfo/test123123/', + platform_id: 'vcs', + mainPath:'helloworld.bas', + //sha:'e466d777810838065b7682587ca592c3eefc0b1c' + }}); done(); }); });