Skip to content

Commit

Permalink
fix PR label calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Mar 11, 2021
1 parent 069be34 commit 1bc112a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions packages/core/src/__tests__/auto-canary-local.test.ts
Expand Up @@ -11,6 +11,8 @@ const defaults = {
repo: "bar",
};

const listLabelsOnIssue = jest.fn();

process.env.GH_TOKEN = "XXXX";

jest.mock("@octokit/rest", () => {
Expand All @@ -23,6 +25,10 @@ jest.mock("@octokit/rest", () => {
get: jest.fn().mockReturnValue({}),
};

issues = {
listLabelsOnIssue: listLabelsOnIssue.mockReturnValue({ data: []}),
};

hook = {
error: () => undefined,
};
Expand Down Expand Up @@ -54,3 +60,29 @@ test("shipit should publish canary in locally when not on baseBranch", async ()
})
);
});

test("canary should use PR labels correctly", async () => {
const auto = new Auto({
...defaults,
onlyPublishWithReleaseLabel: true,
plugins: [],
});
auto.logger = dummyLog();
// @ts-ignore
auto.checkClean = () => Promise.resolve(true);
await auto.loadConfig();

auto.git!.getLatestRelease = () => Promise.resolve("1.2.3");
auto.git!.getSha = () => Promise.resolve("abcdefghijklmnop");
jest.spyOn(auto.git!, "createComment").mockImplementation();
auto.release!.getCommitsInRelease = () => Promise.resolve([]);
auto.release!.getCommits = () => Promise.resolve([]);
const canary = jest.fn();
auto.hooks.canary.tap("test", canary);
listLabelsOnIssue.mockReturnValueOnce({
data: [{ name: "internal" }, { name: "release" }],
});

await auto.canary({ pr: 123 });
expect(canary).toHaveBeenCalled();
});
2 changes: 1 addition & 1 deletion packages/core/src/auto.ts
Expand Up @@ -1224,7 +1224,7 @@ export default class Auto {

if (pr) {
const prLabels = await this.git.getLabels(Number(pr));
labels.push(prLabels);
labels.unshift(prLabels);
}

let bump = calculateSemVerBump(labels, this.semVerLabels!, this.config);
Expand Down

0 comments on commit 1bc112a

Please sign in to comment.