Skip to content

Commit

Permalink
Merge pull request #1772 from intuit/released-bug
Browse files Browse the repository at this point in the history
released plugin: handle PR numbers that dont exist
  • Loading branch information
hipstersmoothie committed Feb 1, 2021
2 parents 24f7c32 + 5a4eceb commit 1149c98
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
26 changes: 26 additions & 0 deletions plugins/released/__tests__/released-label.test.ts
Expand Up @@ -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();
Expand Down
58 changes: 31 additions & 27 deletions plugins/released/src/index.ts
Expand Up @@ -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
Expand Down

0 comments on commit 1149c98

Please sign in to comment.