From 091841fa94a1f0536fd6ceb169aa10d761a70f1c Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 6 Dec 2023 15:32:06 -0400 Subject: [PATCH] fix: A few quick tweaks (#20) Update url that we fetch presigned url from, and clean up data being passed to the api in that request. --- .../src/errors/NoCommitShaError.ts | 5 --- packages/bundler-plugin-core/src/types.ts | 9 ----- .../utils/__tests__/getPreSignedURL.test.ts | 38 +++---------------- .../src/utils/getPreSignedURL.ts | 10 +---- .../src/utils/providers/AzurePipelines.ts | 12 ------ .../src/utils/providers/Woodpecker.ts | 6 --- .../__tests__/AzurePipelines.test.ts | 12 ------ .../providers/__tests__/CircleCI.test.ts | 1 - .../__tests__/CloudflarePages.test.ts | 1 - .../utils/providers/__tests__/Netlify.test.ts | 1 - .../utils/providers/__tests__/Render.test.ts | 1 - .../utils/providers/__tests__/Vercel.test.ts | 1 - .../bundler-plugin-core/test-utils/helpers.ts | 1 - 13 files changed, 7 insertions(+), 91 deletions(-) delete mode 100644 packages/bundler-plugin-core/src/errors/NoCommitShaError.ts diff --git a/packages/bundler-plugin-core/src/errors/NoCommitShaError.ts b/packages/bundler-plugin-core/src/errors/NoCommitShaError.ts deleted file mode 100644 index 3c5f6151..00000000 --- a/packages/bundler-plugin-core/src/errors/NoCommitShaError.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class NoCommitShaError extends Error { - constructor(msg: string) { - super(msg); - } -} diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index af13418c..a369977e 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -106,16 +106,12 @@ export interface UploadOverrides { branch?: string; /** Specify the build number manually. */ build?: string; - /** The commit SHA of the parent for which you are uploading coverage. */ - parent?: string; /** Specify the pull request number manually. */ pr?: string; /** Specify the commit SHA manually. */ sha?: string; /** Specify the slug manually. */ slug?: string; - /** Specify the tag manually. */ - tag?: string; /** Change the upload host (Enterprise use). */ url?: string; } @@ -145,9 +141,4 @@ export interface ProviderServiceParams { pr: string; service: string; slug: string; - name?: string; - tag?: string; - parent?: string; - project?: string; - server_uri?: string; } 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 fa8553c0..041b601e 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts @@ -5,7 +5,6 @@ import { getPreSignedURL } from "../getPreSignedURL.ts"; import { FailedFetchError } from "../../errors/FailedFetchError.ts"; import { NoUploadTokenError } from "../../errors/NoUploadTokenError.ts"; import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts"; -import { NoCommitShaError } from "../../errors/NoCommitShaError.ts"; const server = setupServer(); @@ -35,15 +34,12 @@ describe("getPreSignedURL", () => { consoleSpy = jest.spyOn(console, "log").mockImplementation(() => null); server.use( - http.post( - "http://localhost/upload/service/commits/:commitSha/bundle_analysis", - ({}) => { - if (sendError) { - return HttpResponse.error(); - } - return HttpResponse.json(data, { status }); - }, - ), + http.post("http://localhost/upload/bundle_analysis/v1", ({}) => { + if (sendError) { + return HttpResponse.error(); + } + return HttpResponse.json(data, { status }); + }), ); return { @@ -143,28 +139,6 @@ describe("getPreSignedURL", () => { }); }); - describe("no commit sha found", () => { - it("throws an error", async () => { - const { consoleSpy } = setup({ - data: { url: "http://example.com" }, - }); - - let error; - try { - await getPreSignedURL({ - apiURL: "http://localhost", - globalUploadToken: "global-upload-token", - serviceParams: {}, - }); - } catch (e) { - error = e; - } - - expect(consoleSpy).toHaveBeenCalled(); - expect(error).toBeInstanceOf(NoCommitShaError); - }); - }); - describe("return body does not match schema", () => { it("throws an error", async () => { const { consoleSpy } = setup({ diff --git a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts index 96d2c3fc..633fc020 100644 --- a/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts +++ b/packages/bundler-plugin-core/src/utils/getPreSignedURL.ts @@ -8,7 +8,6 @@ import { DEFAULT_RETRY_COUNT } from "./constants.ts"; import { fetchWithRetry } from "./fetchWithRetry.ts"; import { green, red, yellow } from "./logging.ts"; import { preProcessBody } from "./preProcessBody.ts"; -import { NoCommitShaError } from "../errors/NoCommitShaError.ts"; interface GetPreSignedURLArgs { apiURL: string; @@ -35,14 +34,7 @@ export const getPreSignedURL = async ({ throw new NoUploadTokenError("No upload token found"); } - const commitSha = serviceParams?.commit; - - if (!commitSha) { - red("No commit found"); - throw new NoCommitShaError("No commit found"); - } - - const url = `${apiURL}/upload/service/commits/${commitSha}/bundle_analysis`; + const url = `${apiURL}/upload/bundle_analysis/v1`; let response: Response; try { diff --git a/packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts b/packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts index 38a32238..7f48caf1 100644 --- a/packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts +++ b/packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts @@ -82,16 +82,6 @@ function _getSHA(inputs: ProviderUtilInputs): string { return commit ?? ""; } -function _getProject(inputs: ProviderUtilInputs): string { - const { envs } = inputs; - return envs?.SYSTEM_TEAMPROJECT ?? ""; -} - -function _getServerURI(inputs: ProviderUtilInputs): string { - const { envs } = inputs; - return envs?.SYSTEM_TEAMFOUNDATIONSERVERURI ?? ""; -} - function _getSlug(inputs: ProviderUtilInputs): string { const { args, envs } = inputs; @@ -114,8 +104,6 @@ export async function getServiceParams( commit: _getSHA(inputs), job: _getJob(inputs.envs), pr: _getPR(inputs), - project: _getProject(inputs), - server_uri: _getServerURI(inputs), service: _getService(), slug: _getSlug(inputs), }; diff --git a/packages/bundler-plugin-core/src/utils/providers/Woodpecker.ts b/packages/bundler-plugin-core/src/utils/providers/Woodpecker.ts index c360998e..bafacfab 100644 --- a/packages/bundler-plugin-core/src/utils/providers/Woodpecker.ts +++ b/packages/bundler-plugin-core/src/utils/providers/Woodpecker.ts @@ -51,11 +51,6 @@ function _getSHA(inputs: ProviderUtilInputs): string { return args?.sha ?? envs?.CI_COMMIT_SHA ?? ""; } -function _getTag(inputs: ProviderUtilInputs): string { - const { args, envs } = inputs; - return args?.tag ?? envs?.CI_COMMIT_TAG ?? ""; -} - function _getSlug(inputs: ProviderUtilInputs): string { const { args, envs } = inputs; if (args?.slug && args?.slug !== "") return args?.slug; @@ -71,7 +66,6 @@ export async function getServiceParams( build: _getBuild(inputs), buildURL: _getBuildURL(inputs), commit: _getSHA(inputs), - tag: _getTag(inputs), pr: _getPR(inputs), job: _getJob(inputs), service: _getService(), diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/AzurePipelines.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/AzurePipelines.test.ts index 1eaa283b..f40f79ee 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/AzurePipelines.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/AzurePipelines.test.ts @@ -46,8 +46,6 @@ describe("Azure Pipelines CI Params", () => { commit: "", job: "", pr: "", - project: "", - server_uri: "https://example.azure.com", service: "azure_pipelines", slug: "", }; @@ -84,8 +82,6 @@ describe("Azure Pipelines CI Params", () => { commit: "testingsha", job: "2", pr: "3", - project: "testOrg", - server_uri: "https://example.azure.com", service: "azure_pipelines", slug: "testOrg/testRepo", }; @@ -119,8 +115,6 @@ describe("Azure Pipelines CI Params", () => { commit: "testingsha", job: "2", pr: "3", - project: "testOrg", - server_uri: "https://example.azure.com", service: "azure_pipelines", slug: "testOrg/testRepo", }; @@ -152,8 +146,6 @@ describe("Azure Pipelines CI Params", () => { commit: "testingsha", job: "2", pr: "", - project: "testOrg", - server_uri: "https://example.azure.com", service: "azure_pipelines", slug: "testOrg/testRepo", }; @@ -192,8 +184,6 @@ describe("Azure Pipelines CI Params", () => { commit: "testingmergecommitsha2345678901234567890", job: "2", pr: "3", - project: "testOrg", - server_uri: "https://example.azure.com", service: "azure_pipelines", slug: "testOrg/testRepo", }; @@ -233,8 +223,6 @@ describe("Azure Pipelines CI Params", () => { commit: "testsha", job: "", pr: "2", - project: "", - server_uri: "https://example.azure.com", service: "azure_pipelines", slug: "testOrg/otherTestRepo", }; diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/CircleCI.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/CircleCI.test.ts index 27d90b03..46e79fdc 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/CircleCI.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/CircleCI.test.ts @@ -101,7 +101,6 @@ describe("CircleCI Params", () => { args: { branch: "main", build: "2", - parent: "parent-build-sha", pr: "1", sha: "cool-commit-sha", slug: "testOrg/testRepo", diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/CloudflarePages.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/CloudflarePages.test.ts index deadda87..f3d3480c 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/CloudflarePages.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/CloudflarePages.test.ts @@ -66,7 +66,6 @@ describe("CloudflarePages Params", () => { args: { branch: "main", build: "2", - parent: "parent-build-sha", pr: "1", sha: "cool-commit-sha", slug: "testOrg/testRepo", diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/Netlify.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/Netlify.test.ts index ac5702bd..52cee5c6 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/Netlify.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/Netlify.test.ts @@ -67,7 +67,6 @@ describe("Netlify Params", () => { args: { branch: "main", build: "2", - parent: "parent-build-sha", pr: "1", sha: "cool-commit-sha", slug: "testOrg/testRepo", diff --git a/packages/bundler-plugin-core/src/utils/providers/__tests__/Render.test.ts b/packages/bundler-plugin-core/src/utils/providers/__tests__/Render.test.ts index 2898bad3..12eee9be 100644 --- a/packages/bundler-plugin-core/src/utils/providers/__tests__/Render.test.ts +++ b/packages/bundler-plugin-core/src/utils/providers/__tests__/Render.test.ts @@ -67,7 +67,6 @@ describe("Render Params", () => { args: { branch: "main", build: "2", - parent: "parent-build-sha", pr: "1", sha: "cool-commit-sha", slug: "testOrg/testRepo", 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 7730de0c..e28e73fa 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 @@ -66,7 +66,6 @@ describe("Vercel Params", () => { args: { branch: "main", build: "2", - parent: "parent-build-sha", pr: "1", sha: "cool-commit-sha", slug: "testOrg/testRepo", diff --git a/packages/bundler-plugin-core/test-utils/helpers.ts b/packages/bundler-plugin-core/test-utils/helpers.ts index cd34e375..b4c3341b 100644 --- a/packages/bundler-plugin-core/test-utils/helpers.ts +++ b/packages/bundler-plugin-core/test-utils/helpers.ts @@ -28,7 +28,6 @@ export function createEmptyArgs(): UploadOverrides { return { build: undefined, branch: undefined, - parent: undefined, pr: undefined, sha: undefined, slug: undefined,