From 18db4df49481ee311a74b0ece568aed692977594 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Mon, 1 Feb 2021 11:53:43 -0800 Subject: [PATCH] released plugin: handle PR versions that dont exist --- plugins/released/src/index.ts | 58 +++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/plugins/released/src/index.ts b/plugins/released/src/index.ts index 671c04034..d38a5ac65 100644 --- a/plugins/released/src/index.ts +++ b/plugins/released/src/index.ts @@ -126,38 +126,42 @@ export default class ReleasedLabelPlugin implements IPlugin { const isPrerelease = releases.some((r) => r.data.prerelease); if (commit.pullRequest) { - const pr = await auto.git!.getPullRequest(commit.pullRequest.number); - const branch = pr?.data.head.ref; + try { + const pr = await auto.git!.getPullRequest(commit.pullRequest.number); + const branch = pr?.data.head.ref; - if (branch && auto.config?.prereleaseBranches.includes(branch)) { - return; - } + if (branch && auto.config?.prereleaseBranches.includes(branch)) { + return; + } - if ( - !this.options.includeBotPrs && - commit.authors.some( - (author) => - (author.name && botList.includes(author.name)) || - (author.username && botList.includes(author.username)) || - author.type === "Bot" - ) - ) { - return; - } + if ( + !this.options.includeBotPrs && + commit.authors.some( + (author) => + (author.name && botList.includes(author.name)) || + (author.username && botList.includes(author.username)) || + author.type === "Bot" + ) + ) { + return; + } - await this.addCommentAndLabel({ - auto, - prOrIssue: commit.pullRequest.number, - isPrerelease, - releases, - }); + await this.addCommentAndLabel({ + auto, + prOrIssue: commit.pullRequest.number, + isPrerelease, + releases, + }); - pr.data.body?.split("\n").map((line) => messages.push(line)); + pr.data.body?.split("\n").map((line) => messages.push(line)); - const commitsInPr = await auto.git!.getCommitsForPR( - commit.pullRequest.number - ); - commitsInPr.map((c) => messages.push(c.commit.message)); + const commitsInPr = await auto.git!.getCommitsForPR( + commit.pullRequest.number + ); + commitsInPr.map((c) => messages.push(c.commit.message)); + } catch (error) { + auto.logger.verbose.log(error); + } } const issues = messages