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: support tokenless #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading