Skip to content

Commit 44ecb3a

Browse files
fix: support tokenless (#106)
1 parent 4e79e65 commit 44ecb3a

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

dist/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32097,6 +32097,26 @@ const isTrue = (variable) => {
3209732097
lowercase === 'y' ||
3209832098
lowercase === 'yes');
3209932099
};
32100+
const isPullRequestFromFork = () => {
32101+
core.info(`eventName: ${context.eventName}`);
32102+
if (!['pull_request', 'pull_request_target'].includes(context.eventName)) {
32103+
return false;
32104+
}
32105+
const baseLabel = context.payload.pull_request.base.label;
32106+
const headLabel = context.payload.pull_request.head.label;
32107+
core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`);
32108+
return baseLabel.split(':')[0] !== headLabel.split(':')[0];
32109+
};
32110+
const getOverrideBranch = (token) => {
32111+
let overrideBranch = core.getInput('override_branch');
32112+
if (!overrideBranch && !token && isPullRequestFromFork()) {
32113+
core.info('==> Fork detected, tokenless uploading used');
32114+
// backwards compatibility with certain versions of the CLI that expect this
32115+
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
32116+
overrideBranch = context.payload.pull_request.head.label;
32117+
}
32118+
return overrideBranch;
32119+
};
3210032120
const buildGeneralExec = () => {
3210132121
const codecovYmlPath = core.getInput('codecov_yml_path');
3210232122
const url = core.getInput('url');
@@ -32125,7 +32145,8 @@ const buildUploadExec = () => {
3212532145
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
3212632146
const name = core.getInput('name');
3212732147
const os = core.getInput('os');
32128-
const overrideBranch = core.getInput('override_branch');
32148+
const token = core.getInput('token');
32149+
const overrideBranch = getOverrideBranch(token);
3212932150
const overrideBuild = core.getInput('override_build');
3213032151
const overrideBuildUrl = core.getInput('override_build_url');
3213132152
const overrideCommit = core.getInput('override_commit');
@@ -32134,7 +32155,6 @@ const buildUploadExec = () => {
3213432155
const rootDir = core.getInput('root_dir');
3213532156
const searchDir = core.getInput('directory');
3213632157
const slug = core.getInput('slug');
32137-
const token = core.getInput('token');
3213832158
let uploaderVersion = core.getInput('version');
3213932159
const workingDir = core.getInput('working-directory');
3214032160
const uploadExecArgs = [];

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/buildExec.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ const isTrue = (variable) => {
1717
);
1818
};
1919

20+
const isPullRequestFromFork = (): boolean => {
21+
core.info(`eventName: ${context.eventName}`);
22+
if (!['pull_request', 'pull_request_target'].includes(context.eventName)) {
23+
return false;
24+
}
25+
26+
const baseLabel = context.payload.pull_request.base.label;
27+
const headLabel = context.payload.pull_request.head.label;
28+
29+
core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`);
30+
return baseLabel.split(':')[0] !== headLabel.split(':')[0];
31+
};
32+
33+
34+
const getOverrideBranch = (token: string): string => {
35+
let overrideBranch = core.getInput('override_branch');
36+
if (!overrideBranch && !token && isPullRequestFromFork()) {
37+
core.info('==> Fork detected, tokenless uploading used');
38+
// backwards compatibility with certain versions of the CLI that expect this
39+
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
40+
overrideBranch = context.payload.pull_request.head.label;
41+
}
42+
return overrideBranch;
43+
};
2044

2145
const buildGeneralExec = () => {
2246
const codecovYmlPath = core.getInput('codecov_yml_path');
@@ -48,7 +72,8 @@ const buildUploadExec = () => {
4872
const handleNoReportsFound = isTrue(core.getInput('handle_no_reports_found'));
4973
const name = core.getInput('name');
5074
const os = core.getInput('os');
51-
const overrideBranch = core.getInput('override_branch');
75+
const token = core.getInput('token');
76+
const overrideBranch = getOverrideBranch(token);
5277
const overrideBuild = core.getInput('override_build');
5378
const overrideBuildUrl = core.getInput('override_build_url');
5479
const overrideCommit = core.getInput('override_commit');
@@ -57,13 +82,12 @@ const buildUploadExec = () => {
5782
const rootDir = core.getInput('root_dir');
5883
const searchDir = core.getInput('directory');
5984
const slug = core.getInput('slug');
60-
const token = core.getInput('token');
6185
let uploaderVersion = core.getInput('version');
6286
const workingDir = core.getInput('working-directory');
6387

6488
const uploadExecArgs = [];
6589
const uploadCommand = 'do-upload';
66-
const uploadOptions:any = {};
90+
const uploadOptions: any = {};
6791
uploadOptions.env = Object.assign(process.env, {
6892
GITHUB_ACTION: process.env.GITHUB_ACTION,
6993
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,

0 commit comments

Comments
 (0)