wip handle empty repo

This commit is contained in:
tdurieux
2022-10-04 10:26:20 +02:00
parent 388116cf41
commit 4041883ae5
+30 -22
View File
@@ -92,7 +92,8 @@ export default class GitHubStream extends GitHubBase implements SourceBase {
recursive: "1", recursive: "1",
}); });
} catch (error) { } catch (error) {
if (error.status == 409 && error.message == "Git Repository is empty.") { console.log(error, error.status);
if (error.status == 409) {
return {}; return {};
} }
await this.repository.resetSate("error", "repo_not_accessible"); await this.repository.resetSate("error", "repo_not_accessible");
@@ -124,33 +125,40 @@ export default class GitHubStream extends GitHubBase implements SourceBase {
const octokit = new Octokit({ const octokit = new Octokit({
auth: await this.getToken(), auth: await this.getToken(),
}); });
const ghRes = await octokit.git.getTree({ try {
owner: this.githubRepository.owner, const ghRes = await octokit.git.getTree({
repo: this.githubRepository.repo, owner: this.githubRepository.owner,
tree_sha: sha, repo: this.githubRepository.repo,
}); tree_sha: sha,
const tree = ghRes.data.tree; });
const tree = ghRes.data.tree;
for (let elem of tree) { for (let elem of tree) {
if (!elem.path) continue; if (!elem.path) continue;
if (elem.type == "tree") { if (elem.type == "tree") {
const elementPath = path.join(parentPath, elem.path); const elementPath = path.join(parentPath, elem.path);
const paths = elementPath.split("/"); const paths = elementPath.split("/");
let current = truncatedTree; let current = truncatedTree;
for (let i = 0; i < paths.length; i++) { for (let i = 0; i < paths.length; i++) {
let p = paths[i]; let p = paths[i];
if (!current[p]) { if (!current[p]) {
if (elem.sha) if (elem.sha)
await this.getTree(elem.sha, truncatedTree, elementPath); await this.getTree(elem.sha, truncatedTree, elementPath);
break; break;
}
current = current[p] as Tree;
} }
current = current[p] as Tree;
} }
} }
this.tree2Tree(ghRes.data.tree, truncatedTree, parentPath);
return truncatedTree;
} catch (error) {
console.log(error, error.status);
if (error.status == 409) {
}
return truncatedTree;
} }
this.tree2Tree(ghRes.data.tree, truncatedTree, parentPath);
return truncatedTree;
} }
private tree2Tree( private tree2Tree(