1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-22 14:33:51 +00:00

fix for github branch names

This commit is contained in:
Steven Hugg 2021-01-05 13:19:47 -06:00
parent b3b93e150d
commit 2bb5e3d27e
2 changed files with 41 additions and 23 deletions

View File

@ -14,16 +14,15 @@ export interface GHRepoMetadata {
platform_id : string; // e.g. "vcs" platform_id : string; // e.g. "vcs"
sha? : string; // head commit sha sha? : string; // head commit sha
mainPath?: string; // main file path mainPath?: string; // main file path
branch? : string; // "master" was default, now fetched from GH
} }
export interface GHSession extends GHRepoMetadata { export interface GHSession extends GHRepoMetadata {
url : string; // github url
user : string; // user name user : string; // user name
reponame : string; // repo name reponame : string; // repo name
repopath : string; // "user/repo" repopath : string; // "user/repo"
subtreepath : string; // tree/master/[...] subtreepath : string; // tree/[branch]/[...]
prefix : string; // file prefix, "local/" or "" prefix : string; // file prefix, "local/" or ""
branch : string; // "master" is default
repo : any; // [repo object] repo : any; // [repo object]
tree? : any; // [tree object] tree? : any; // [tree object]
head? : any; // [head ref] head? : any; // [head ref]
@ -45,7 +44,7 @@ export function getRepos() : {[key:string]:GHRepoMetadata} {
} }
return repos; return repos;
} }
export function parseGithubURL(ghurl:string) { export function parseGithubURL(ghurl:string) {
var toks = ghurl.split('/', 8); var toks = ghurl.split('/', 8);
if (toks.length < 5) return null; if (toks.length < 5) return null;
@ -117,25 +116,37 @@ export class GithubService {
return false; return false;
} }
getGithubSession(ghurl:string) : Promise<GHSession> { async getGithubSession(ghurl:string) : Promise<GHSession> {
return new Promise( (yes,no) => { var urlparse = parseGithubURL(ghurl);
var urlparse = parseGithubURL(ghurl); if (!urlparse) {
if (!urlparse) { throw new Error("Please enter a valid GitHub URL.");
no("Please enter a valid GitHub URL."); }
// use saved branch, or load default from rpo
var saved = getRepos()[urlparse.repopath];
var branch = urlparse.branch || (saved && saved.branch);
var repo = this.github.repos(urlparse.user, urlparse.repo);
if (1 || branch == null) {
try {
branch = (await repo.fetch()).defaultBranch || "master";
} catch (e) {
console.log("could not fetch default branch: " + e);
branch = "main";
} }
var sess = { console.log("branch =", branch);
url: ghurl, }
user: urlparse.user, var sess = {
reponame: urlparse.repo, url: ghurl,
repopath: urlparse.repopath, user: urlparse.user,
branch: urlparse.branch || "master", reponame: urlparse.repo,
subtreepath: urlparse.subtreepath, repopath: urlparse.repopath,
prefix: '', //this.getPrefix(urlparse.user, urlparse.repo), branch: branch,
repo: this.github.repos(urlparse.user, urlparse.repo), subtreepath: urlparse.subtreepath,
platform_id: this.project ? this.project.platform_id : null prefix: '', //this.getPrefix(urlparse.user, urlparse.repo),
}; repo: repo,
yes(sess); platform_id: this.project ? this.project.platform_id : saved.platform_id
}); };
//console.log(sess);
return sess;
} }
getGithubHEADTree(ghurl:string) : Promise<GHSession> { getGithubHEADTree(ghurl:string) : Promise<GHSession> {
@ -169,7 +180,13 @@ export class GithubService {
bind(sess:GHSession, dobind:boolean) { bind(sess:GHSession, dobind:boolean) {
var key = '__repo__' + sess.repopath; var key = '__repo__' + sess.repopath;
if (dobind) { if (dobind) {
var repodata : GHRepoMetadata = {url:sess.url, platform_id:sess.platform_id, mainPath:sess.mainPath, sha:sess.sha}; var repodata : GHRepoMetadata = {
url:sess.url,
branch:sess.branch,
platform_id:sess.platform_id,
mainPath:sess.mainPath,
sha:sess.sha};
console.log('storing', repodata);
localStorage.setItem(key, JSON.stringify(repodata)); localStorage.setItem(key, JSON.stringify(repodata));
} else { } else {
localStorage.removeItem(key); localStorage.removeItem(key);

View File

@ -37,6 +37,7 @@ describe('Store', function() {
url: 'https://github.com/pzpinfo/test123123/', url: 'https://github.com/pzpinfo/test123123/',
platform_id: 'vcs', platform_id: 'vcs',
mainPath:'helloworld.bas', mainPath:'helloworld.bas',
branch:'master'
//sha:'e466d777810838065b7682587ca592c3eefc0b1c' //sha:'e466d777810838065b7682587ca592c3eefc0b1c'
}}); }});
done(); done();