From eb0b2728dbfe7e19cdfafd5363aca846fa609e15 Mon Sep 17 00:00:00 2001 From: Mara-Li Date: Wed, 27 Dec 2023 10:16:26 +0100 Subject: [PATCH] fix: prevent crash if PR can't be done --- src/GitHub/branch.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GitHub/branch.ts b/src/GitHub/branch.ts index 74c6428e..39629591 100644 --- a/src/GitHub/branch.ts +++ b/src/GitHub/branch.ts @@ -121,6 +121,7 @@ export class GithubBranch extends FilesManagement { return PR.data.number; } catch (e) { logs({settings: this.settings, e: true}, e); + //trying to get the last open PR number try { const PR = await this.octokit.request( "GET /repos/{owner}/{repo}/pulls", @@ -130,8 +131,9 @@ export class GithubBranch extends FilesManagement { state: "open", } ); - return PR.data[0].number; + return PR.data[0]?.number || 0; } catch (e) { + // there is no open PR and impossible to create a new one notif( {settings: this.settings, e: true}, i18next.t("publish.branch.error", {error: e, repo: repoFrontmatter})