diff --git a/plugins/released/__tests__/released-label.test.ts b/plugins/released/__tests__/released-label.test.ts index be69ec43d..6d2eb40c4 100644 --- a/plugins/released/__tests__/released-label.test.ts +++ b/plugins/released/__tests__/released-label.test.ts @@ -144,6 +144,32 @@ describe("release label plugin", () => { expect(comment).not.toHaveBeenCalled(); }); + test("should do nothing with PR that doesn't exist", async () => { + const releasedLabel = new ReleasedLabelPlugin(); + const autoHooks = makeHooks(); + releasedLabel.apply(({ + hooks: autoHooks, + labels: defaultLabels, + logger: dummyLog(), + options: {}, + comment, + git, + } as unknown) as Auto); + + getPr.mockRejectedValueOnce(new Error("PR dont exist")); + const commit = makeCommitFromMsg("normal commit with no bump (#123)"); + await autoHooks.afterRelease.promise({ + newVersion: "1.0.0", + lastRelease: "0.1.0", + commits: await log.normalizeCommits([commit]), + releaseNotes: "", + // @ts-ignore + response: mockResponse, + }); + + expect(comment).not.toHaveBeenCalled(); + }); + test("should do nothing without commits", async () => { const releasedLabel = new ReleasedLabelPlugin(); const autoHooks = makeHooks(); 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