Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

released plugin: handle PR numbers that dont exist #1772

Merged
merged 2 commits into from Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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