Skip to content

Commit

Permalink
fix: support tokenless (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-sentry authored Feb 4, 2025
1 parent 4e79e65 commit 44ecb3a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
24 changes: 22 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32097,6 +32097,26 @@ const isTrue = (variable) => {
lowercase === 'y' ||
lowercase === 'yes');
};
const isPullRequestFromFork = () => {
core.info(`eventName: ${context.eventName}`);
if (!['pull_request', 'pull_request_target'].includes(context.eventName)) {
return false;
}
const baseLabel = context.payload.pull_request.base.label;
const headLabel = context.payload.pull_request.head.label;
core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`);
return baseLabel.split(':')[0] !== headLabel.split(':')[0];
};
const getOverrideBranch = (token) => {
let overrideBranch = core.getInput('override_branch');
if (!overrideBranch && !token && isPullRequestFromFork()) {
core.info('==> Fork detected, tokenless uploading used');
// backwards compatibility with certain versions of the CLI that expect this
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
overrideBranch = context.payload.pull_request.head.label;
}
return overrideBranch;
};
const buildGeneralExec = () => {
const codecovYmlPath = core.getInput('codecov_yml_path');
const url = core.getInput('url');
Expand Down Expand Up @@ -32125,7 +32145,8 @@ const buildUploadExec = () => {
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
const name = core.getInput('name');
const os = core.getInput('os');
const overrideBranch = core.getInput('override_branch');
const token = core.getInput('token');
const overrideBranch = getOverrideBranch(token);
const overrideBuild = core.getInput('override_build');
const overrideBuildUrl = core.getInput('override_build_url');
const overrideCommit = core.getInput('override_commit');
Expand All @@ -32134,7 +32155,6 @@ const buildUploadExec = () => {
const rootDir = core.getInput('root_dir');
const searchDir = core.getInput('directory');
const slug = core.getInput('slug');
const token = core.getInput('token');
let uploaderVersion = core.getInput('version');
const workingDir = core.getInput('working-directory');
const uploadExecArgs = [];
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

30 changes: 27 additions & 3 deletions src/buildExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ const isTrue = (variable) => {
);
};

const isPullRequestFromFork = (): boolean => {
core.info(`eventName: ${context.eventName}`);
if (!['pull_request', 'pull_request_target'].includes(context.eventName)) {
return false;
}

const baseLabel = context.payload.pull_request.base.label;
const headLabel = context.payload.pull_request.head.label;

core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`);
return baseLabel.split(':')[0] !== headLabel.split(':')[0];
};


const getOverrideBranch = (token: string): string => {
let overrideBranch = core.getInput('override_branch');
if (!overrideBranch && !token && isPullRequestFromFork()) {
core.info('==> Fork detected, tokenless uploading used');
// backwards compatibility with certain versions of the CLI that expect this
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
overrideBranch = context.payload.pull_request.head.label;
}
return overrideBranch;
};

const buildGeneralExec = () => {
const codecovYmlPath = core.getInput('codecov_yml_path');
Expand Down Expand Up @@ -48,7 +72,8 @@ const buildUploadExec = () => {
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
const name = core.getInput('name');
const os = core.getInput('os');
const overrideBranch = core.getInput('override_branch');
const token = core.getInput('token');
const overrideBranch = getOverrideBranch(token);
const overrideBuild = core.getInput('override_build');
const overrideBuildUrl = core.getInput('override_build_url');
const overrideCommit = core.getInput('override_commit');
Expand All @@ -57,13 +82,12 @@ const buildUploadExec = () => {
const rootDir = core.getInput('root_dir');
const searchDir = core.getInput('directory');
const slug = core.getInput('slug');
const token = core.getInput('token');
let uploaderVersion = core.getInput('version');
const workingDir = core.getInput('working-directory');

const uploadExecArgs = [];
const uploadCommand = 'do-upload';
const uploadOptions:any = {};
const uploadOptions: any = {};
uploadOptions.env = Object.assign(process.env, {
GITHUB_ACTION: process.env.GITHUB_ACTION,
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
Expand Down

0 comments on commit 44ecb3a

Please sign in to comment.