@@ -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
2145const 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