@@ -17,6 +17,30 @@ const isTrue = (variable) => {
17
17
) ;
18
18
} ;
19
19
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
+ } ;
20
44
21
45
const buildGeneralExec = ( ) => {
22
46
const codecovYmlPath = core . getInput ( 'codecov_yml_path' ) ;
@@ -48,7 +72,8 @@ const buildUploadExec = () => {
48
72
const handleNoReportsFound = isTrue ( core . getInput ( 'handle_no_reports_found' ) ) ;
49
73
const name = core . getInput ( 'name' ) ;
50
74
const os = core . getInput ( 'os' ) ;
51
- const overrideBranch = core . getInput ( 'override_branch' ) ;
75
+ const token = core . getInput ( 'token' ) ;
76
+ const overrideBranch = getOverrideBranch ( token ) ;
52
77
const overrideBuild = core . getInput ( 'override_build' ) ;
53
78
const overrideBuildUrl = core . getInput ( 'override_build_url' ) ;
54
79
const overrideCommit = core . getInput ( 'override_commit' ) ;
@@ -57,13 +82,12 @@ const buildUploadExec = () => {
57
82
const rootDir = core . getInput ( 'root_dir' ) ;
58
83
const searchDir = core . getInput ( 'directory' ) ;
59
84
const slug = core . getInput ( 'slug' ) ;
60
- const token = core . getInput ( 'token' ) ;
61
85
let uploaderVersion = core . getInput ( 'version' ) ;
62
86
const workingDir = core . getInput ( 'working-directory' ) ;
63
87
64
88
const uploadExecArgs = [ ] ;
65
89
const uploadCommand = 'do-upload' ;
66
- const uploadOptions :any = { } ;
90
+ const uploadOptions : any = { } ;
67
91
uploadOptions . env = Object . assign ( process . env , {
68
92
GITHUB_ACTION : process . env . GITHUB_ACTION ,
69
93
GITHUB_RUN_ID : process . env . GITHUB_RUN_ID ,
0 commit comments