Skip to content
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

fix: A few quick tweaks #20

Merged
merged 2 commits into from
Dec 6, 2023
Merged
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
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