mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-26 10:49:17 +00:00
fix for github branch names
This commit is contained in:
parent
b3b93e150d
commit
2bb5e3d27e
@ -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]
|
||||||
@ -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) {
|
||||||
no("Please enter a valid GitHub URL.");
|
throw new Error("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";
|
||||||
|
}
|
||||||
|
console.log("branch =", branch);
|
||||||
}
|
}
|
||||||
var sess = {
|
var sess = {
|
||||||
url: ghurl,
|
url: ghurl,
|
||||||
user: urlparse.user,
|
user: urlparse.user,
|
||||||
reponame: urlparse.repo,
|
reponame: urlparse.repo,
|
||||||
repopath: urlparse.repopath,
|
repopath: urlparse.repopath,
|
||||||
branch: urlparse.branch || "master",
|
branch: branch,
|
||||||
subtreepath: urlparse.subtreepath,
|
subtreepath: urlparse.subtreepath,
|
||||||
prefix: '', //this.getPrefix(urlparse.user, urlparse.repo),
|
prefix: '', //this.getPrefix(urlparse.user, urlparse.repo),
|
||||||
repo: this.github.repos(urlparse.user, urlparse.repo),
|
repo: repo,
|
||||||
platform_id: this.project ? this.project.platform_id : null
|
platform_id: this.project ? this.project.platform_id : saved.platform_id
|
||||||
};
|
};
|
||||||
yes(sess);
|
//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);
|
||||||
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user