Skip to content

Fix env variable in CI detection #73

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ beforeEach(() => {
});

describe("guessBranch", () => {
it("ensure the branch is guessed if ESLINT_PLUGIN_COMMIT is not already set", async () => {
delete process.env.ESLINT_PLUGIN_COMMIT;
it("ensure the branch is guessed if ESLINT_PLUGIN_DIFF_COMMIT is not already set", async () => {
delete process.env.ESLINT_PLUGIN_DIFF_COMMIT;
const { guessBranch } = await import("./ci");
expect(() => guessBranch()).not.toThrowError(/ESLINT_PLUGIN_COMMIT/u);
expect(() => guessBranch()).not.toThrowError(/ESLINT_PLUGIN_DIFF_COMMIT/u);
});

it("ensure the branch is not guessed if ESLINT_PLUGIN_COMMIT is already set", async () => {
process.env.ESLINT_PLUGIN_COMMIT = "origin/main";
it("ensure the branch is not guessed if ESLINT_PLUGIN_DIFF_COMMIT is already set", async () => {
process.env.ESLINT_PLUGIN_DIFF_COMMIT = "origin/main";
const { guessBranch } = await import("./ci");
expect(() => guessBranch()).toThrowError(/ESLINT_PLUGIN_COMMIT/u);
expect(() => guessBranch()).toThrowError(/ESLINT_PLUGIN_DIFF_COMMIT/u);
});

it("fails when too many providers were found as candidates", async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ const guessProviders = () =>
);

const guessBranch = (): string | undefined => {
if ((process.env.ESLINT_PLUGIN_COMMIT ?? "").length > 0) {
throw Error("ESLINT_PLUGIN_COMMIT already set");
if ((process.env.ESLINT_PLUGIN_DIFF_COMMIT ?? "").length > 0) {
throw Error("ESLINT_PLUGIN_DIFF_COMMIT already set");
}

const guessedProviders = guessProviders();
Expand All @@ -103,7 +103,7 @@ const guessBranch = (): string | undefined => {
.map(({ name }) => name)
.join(
", "
)}). Please specify your target branch explicitly instead, e.g. ESLINT_PLUGIN_COMMIT="main"`
)}). Please specify your target branch explicitly instead, e.g. ESLINT_PLUGIN_DIFF_COMMIT="main"`
);
}

Expand Down
Loading