mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-03 14:18:03 +02:00
fix: handle missing readme
This commit is contained in:
@@ -98,23 +98,26 @@ export class GitHubRepository {
|
|||||||
|
|
||||||
this._data.branches = await this.branches(opt);
|
this._data.branches = await this.branches(opt);
|
||||||
model.branches = this._data.branches;
|
model.branches = this._data.branches;
|
||||||
|
|
||||||
const selected = model.branches.filter((f) => f.name == opt.branch)[0];
|
const selected = model.branches.filter((f) => f.name == opt.branch)[0];
|
||||||
if (selected && (!selected.readme || opt?.force === true)) {
|
if (selected && (!selected.readme || opt?.force === true)) {
|
||||||
// get the list of repo from github
|
// get the list of repo from github
|
||||||
const octokit = new Octokit({ auth: opt.accessToken });
|
const octokit = new Octokit({ auth: opt.accessToken });
|
||||||
const ghRes = await octokit.repos.getReadme({
|
try {
|
||||||
owner: this.owner,
|
const ghRes = await octokit.repos.getReadme({
|
||||||
repo: this.repo,
|
owner: this.owner,
|
||||||
ref: selected?.commit,
|
repo: this.repo,
|
||||||
});
|
ref: selected?.commit,
|
||||||
const readme = Buffer.from(
|
});
|
||||||
ghRes.data.content,
|
const readme = Buffer.from(
|
||||||
ghRes.data.encoding as BufferEncoding
|
ghRes.data.content,
|
||||||
).toString("utf-8");
|
ghRes.data.encoding as BufferEncoding
|
||||||
selected.readme = readme;
|
).toString("utf-8");
|
||||||
|
selected.readme = readme;
|
||||||
await model.save();
|
await model.save();
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error("readme_not_available");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return selected.readme;
|
return selected.readme;
|
||||||
|
|||||||
Reference in New Issue
Block a user