Skip to content

Commit

Permalink
fix: prevent crash if PR can't be done
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Dec 27, 2023
1 parent 0d43ef5 commit eb0b272
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/GitHub/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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})
Expand Down

0 comments on commit eb0b272

Please sign in to comment.