Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
14 changes: 14 additions & 0 deletions .changeset/big-news-bake.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion examples/tokenless/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default defineConfig({
codecovVitePlugin({
enableBundleAnalysis: true,
bundleName: "@codecov/example-tokenless-app",
uploadToken: process.env.TOKENLESS_UPLOAD_TOKEN,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still supporting the "tokenlessForForks"? If so, we should add a separate example for that scenario.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we are keeping tokenlessForForks live. good call - I agree there should be an example/test to show that tokenlessForForks are still valid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would platform side of things complain if we set the branch to codecov:<branch-name> for the example?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or does it have to be a username?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be hard to fudge the :

to get the branch:
first - for BA, shelter gets the commit_id from the commit field in the body of the request. The commit and repo have to exist in firestore - I'm thinking they will. If they exist, shelter uses the branch from the commit.

if shelter can't get the commit (if you found a way to break the above method), it will use the branch field in the body of the request.

and then we have an additional check just for BA uploads, that the branch (most likely from the commit) has to match the branch in the body of the request.

This might explain why the tokenless example doesn't work on shelter

apiUrl: process.env.TOKENLESS_API_URL,
gitService: "github",
debug: true,
Expand Down
5 changes: 0 additions & 5 deletions packages/bundler-plugin-core/src/errors/NoUploadTokenError.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -160,7 +159,7 @@ describe("getPreSignedURL", () => {
retryCount: 0,
serviceParams: {
commit: "123",
branch: "owner:branch",
branch: "any-branch-format",
},
});

Expand All @@ -185,7 +184,7 @@ describe("getPreSignedURL", () => {
gitService: "github_enterprise",
serviceParams: {
commit: "123",
branch: "owner:branch",
branch: "any-branch-format",
},
});

Expand Down Expand Up @@ -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(
Expand Down
33 changes: 12 additions & 21 deletions packages/bundler-plugin-core/src/utils/getPreSignedURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down
Loading