Skip to content

Commit

Permalink
fix: A few quick tweaks (#20)
Browse files Browse the repository at this point in the history
Update url that we fetch presigned url from, and clean up data being passed to the api in that request.
  • Loading branch information
nicholas-codecov authored Dec 6, 2023
1 parent e224faf commit 091841f
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 91 deletions.
5 changes: 0 additions & 5 deletions packages/bundler-plugin-core/src/errors/NoCommitShaError.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -145,9 +141,4 @@ export interface ProviderServiceParams {
pr: string;
service: string;
slug: string;
name?: string;
tag?: string;
parent?: string;
project?: string;
server_uri?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down
10 changes: 1 addition & 9 deletions packages/bundler-plugin-core/src/utils/getPreSignedURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ describe("Azure Pipelines CI Params", () => {
commit: "",
job: "",
pr: "",
project: "",
server_uri: "https://example.azure.com",
service: "azure_pipelines",
slug: "",
};
Expand Down Expand Up @@ -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",
};
Expand Down Expand Up @@ -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",
};
Expand Down Expand Up @@ -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",
};
Expand Down Expand Up @@ -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",
};
Expand Down Expand Up @@ -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",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/bundler-plugin-core/test-utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function createEmptyArgs(): UploadOverrides {
return {
build: undefined,
branch: undefined,
parent: undefined,
pr: undefined,
sha: undefined,
slug: undefined,
Expand Down

0 comments on commit 091841f

Please sign in to comment.