From 94a46aad4163430564f972d06d0fd3d7e8ad8e59 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 22 Feb 2024 20:00:17 -0400 Subject: [PATCH] fix: Support grabbing branch in Vercel (#80) Grab the branch in Vercel env helper. --- .changeset/early-phones-prove.md | 8 ++++++++ .../bundler-plugin-core/src/utils/providers/Vercel.ts | 4 ++-- .../src/utils/providers/__tests__/Vercel.test.ts | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/early-phones-prove.md diff --git a/.changeset/early-phones-prove.md b/.changeset/early-phones-prove.md new file mode 100644 index 00000000..9638035a --- /dev/null +++ b/.changeset/early-phones-prove.md @@ -0,0 +1,8 @@ +--- +"@codecov/bundler-plugin-core": patch +"@codecov/rollup-plugin": patch +"@codecov/vite-plugin": patch +"@codecov/webpack-plugin": patch +--- + +Grab branch name inside Vercel helper so that we for sure have a branch value diff --git a/packages/bundler-plugin-core/src/utils/providers/Vercel.ts b/packages/bundler-plugin-core/src/utils/providers/Vercel.ts index 7e3b3bfe..15a28fd8 100644 --- a/packages/bundler-plugin-core/src/utils/providers/Vercel.ts +++ b/packages/bundler-plugin-core/src/utils/providers/Vercel.ts @@ -21,9 +21,9 @@ function _getBuildURL(): string { } function _getBranch(inputs: ProviderUtilInputs): string { - const { args } = inputs; + const { args, envs } = inputs; - return args?.branch ?? ""; + return args?.branch ?? envs?.VERCEL_GIT_COMMIT_REF ?? ""; } function _getJob(): string { diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/Vercel.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/Vercel.test.ts index f2b0ae25..5f944e6a 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/Vercel.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/Vercel.test.ts @@ -44,11 +44,12 @@ describe("Vercel Params", () => { VERCEL_GIT_COMMIT_SHA: "testingsha", VERCEL_GIT_REPO_SLUG: "testRepo", VERCEL_GIT_REPO_OWNER: "testOrg", + VERCEL_GIT_COMMIT_REF: "super-cool-branch", }, }; const expected: ProviderServiceParams = { - branch: "", + branch: "super-cool-branch", build: "", buildURL: "", commit: "testingsha", @@ -76,6 +77,7 @@ describe("Vercel Params", () => { VERCEL_GIT_COMMIT_SHA: "testingsha", VERCEL_GIT_REPO_SLUG: "testRepo", VERCEL_GIT_REPO_OWNER: "testOrg", + VERCEL_GIT_COMMIT_REF: "super-cool-branch", }, };