From 36c1098d55cb683b4eab187619c39b3e2d2627ba Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 6 Sep 2021 20:48:58 +0200 Subject: [PATCH] fix: handle missing readme --- src/source/GitHubRepository.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/source/GitHubRepository.ts b/src/source/GitHubRepository.ts index add0e85..0876e46 100644 --- a/src/source/GitHubRepository.ts +++ b/src/source/GitHubRepository.ts @@ -98,23 +98,26 @@ export class GitHubRepository { this._data.branches = await this.branches(opt); model.branches = this._data.branches; - + const selected = model.branches.filter((f) => f.name == opt.branch)[0]; if (selected && (!selected.readme || opt?.force === true)) { // get the list of repo from github const octokit = new Octokit({ auth: opt.accessToken }); - const ghRes = await octokit.repos.getReadme({ - owner: this.owner, - repo: this.repo, - ref: selected?.commit, - }); - const readme = Buffer.from( - ghRes.data.content, - ghRes.data.encoding as BufferEncoding - ).toString("utf-8"); - selected.readme = readme; - - await model.save(); + try { + const ghRes = await octokit.repos.getReadme({ + owner: this.owner, + repo: this.repo, + ref: selected?.commit, + }); + const readme = Buffer.from( + ghRes.data.content, + ghRes.data.encoding as BufferEncoding + ).toString("utf-8"); + selected.readme = readme; + await model.save(); + } catch (error) { + throw new Error("readme_not_available"); + } } return selected.readme;