diff --git a/.changeset/big-news-bake.md b/.changeset/big-news-bake.md new file mode 100644 index 00000000..7ef48cd1 --- /dev/null +++ b/.changeset/big-news-bake.md @@ -0,0 +1,14 @@ +--- +"@codecov/bundler-plugin-core": minor +"@codecov/bundle-analyzer": minor +"@codecov/nextjs-webpack-plugin": minor +"@codecov/nuxt-plugin": minor +"@codecov/remix-vite-plugin": minor +"@codecov/rollup-plugin": minor +"@codecov/solidstart-plugin": minor +"@codecov/sveltekit-plugin": minor +"@codecov/vite-plugin": minor +"@codecov/webpack-plugin": minor +--- + +Remove the org branch requirement for tokenless uploads diff --git a/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts b/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts deleted file mode 100644 index e627ab2f..00000000 --- a/packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class NoUploadTokenError extends Error { - constructor(msg: string, options?: ErrorOptions) { - super(msg, options); - } -} diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts index 8bb243d7..0ed7b2ca 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -16,7 +16,6 @@ import childProcess from "child_process"; import { SPAWN_PROCESS_BUFFER_SIZE } from "../constants.ts"; import { getPreSignedURL } from "../getPreSignedURL.ts"; import { FailedFetchError } from "../../errors/FailedFetchError.ts"; -import { NoUploadTokenError } from "../../errors/NoUploadTokenError.ts"; import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts"; import { UndefinedGitServiceError } from "../../errors/UndefinedGitServiceError.ts"; import { BadOIDCServiceError } from "src/errors/BadOIDCServiceError.ts"; @@ -160,7 +159,7 @@ describe("getPreSignedURL", () => { retryCount: 0, serviceParams: { commit: "123", - branch: "owner:branch", + branch: "any-branch-format", }, }); @@ -185,7 +184,7 @@ describe("getPreSignedURL", () => { gitService: "github_enterprise", serviceParams: { commit: "123", - branch: "owner:branch", + branch: "any-branch-format", }, }); @@ -228,37 +227,6 @@ describe("getPreSignedURL", () => { describe("unsuccessful request", () => { describe("no upload token present", () => { - describe("branch is in incorrect format", () => { - it("throws an error", async () => { - const { consoleSpy } = setup({ - data: { url: "http://example.com" }, - }); - - let error; - try { - await getPreSignedURL({ - apiUrl: "http://localhost", - retryCount: 0, - gitService: "github", - serviceParams: { - commit: "123", - branch: "main", - }, - }); - } catch (e) { - error = e; - } - - expect(consoleSpy).toHaveBeenCalled(); - // for some reason, this test fails even tho it's the same values - // Expected: "No upload token found" - // Received: "No upload token found" - // Number of calls: 1 - // expect(consoleSpy).toHaveBeenCalledWith("No upload token found"); - expect(error).toBeInstanceOf(NoUploadTokenError); - }); - }); - describe("git service is not found", () => { beforeEach(() => { td.when( diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index cc26ca35..d47f7af3 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -6,7 +6,6 @@ import { type ProviderServiceParams } from "../types.ts"; import { fetchWithRetry } from "./fetchWithRetry.ts"; import { green, red } from "./logging.ts"; import { preProcessBody } from "./preProcessBody.ts"; -import { NoUploadTokenError } from "../errors/NoUploadTokenError.ts"; import { findGitService } from "./findGitService.ts"; import { UndefinedGitServiceError } from "../errors/UndefinedGitServiceError.ts"; import { FailedOIDCFetchError } from "../errors/FailedOIDCFetchError.ts"; @@ -45,24 +44,7 @@ export const getPreSignedURL = async ({ }); const requestBody: RequestBody = serviceParams; - /** - * We currently require the branch to be in the format `owner:branch` to identify that it is a - * proper tokenless upload. - * See: https://github.com/codecov/codecov-api/pull/741 - */ - if (!uploadToken && serviceParams.branch?.includes(":")) { - if (gitService) { - requestBody.git_service = gitService; - } else { - const foundGitService = findGitService(); - if (!foundGitService || foundGitService === "") { - red("Failed to find git service for tokenless upload"); - throw new UndefinedGitServiceError("No upload token provided"); - } - - requestBody.git_service = foundGitService; - } - } else if (oidc?.useGitHubOIDC && Core) { + if (oidc?.useGitHubOIDC && Core) { if (serviceParams?.service !== "github-actions") { red("OIDC is only supported for GitHub Actions"); throw new BadOIDCServiceError( @@ -89,8 +71,17 @@ export const getPreSignedURL = async ({ } else if (uploadToken) { headers.set("Authorization", `token ${uploadToken}`); } else { - red("No upload token provided"); - throw new NoUploadTokenError("No upload token provided"); + if (gitService) { + requestBody.git_service = gitService; + } else { + const foundGitService = findGitService(); + if (!foundGitService || foundGitService === "") { + red("Failed to find git service for tokenless upload"); + throw new UndefinedGitServiceError("No upload token provided"); + } + + requestBody.git_service = foundGitService; + } } let response: Response;