1
1
import * as fs from 'fs'
2
2
import path from 'path'
3
- import { debug , info , warning } from '@actions/core'
3
+ import { debug , info } from '@actions/core'
4
4
import { isNullOrEmptyValue , validateBlackduckFailureSeverities , validateCoverityInstallDirectoryParam } from './validators'
5
5
import * as inputs from './inputs'
6
6
import { Polaris } from './input-data/polaris'
@@ -64,8 +64,7 @@ export class SynopsysToolsParameter {
64
64
serverUrl : inputs . POLARIS_SERVER_URL ,
65
65
application : { name : applicationName } ,
66
66
project : { name : projectName } ,
67
- assessment : { types : assessmentTypeArray } ,
68
- branch : { parent : { } }
67
+ assessment : { types : assessmentTypeArray }
69
68
}
70
69
}
71
70
}
@@ -74,7 +73,7 @@ export class SynopsysToolsParameter {
74
73
polData . data . polaris . triage = inputs . POLARIS_TRIAGE
75
74
}
76
75
if ( inputs . POLARIS_BRANCH_NAME ) {
77
- polData . data . polaris . branch . name = inputs . POLARIS_BRANCH_NAME
76
+ polData . data . polaris . branch = { name : inputs . POLARIS_BRANCH_NAME }
78
77
}
79
78
if ( inputs . POLARIS_TEST_SCA_TYPE ) {
80
79
polData . data . polaris . test = {
@@ -89,7 +88,12 @@ export class SynopsysToolsParameter {
89
88
/** Set Polaris PR comment inputs in case of PR context */
90
89
info ( 'Polaris PR comment is enabled' )
91
90
if ( inputs . POLARIS_PARENT_BRANCH_NAME ) {
92
- polData . data . polaris . branch . parent . name = inputs . POLARIS_PARENT_BRANCH_NAME
91
+ polData . data . polaris . branch = {
92
+ ...( inputs . POLARIS_BRANCH_NAME && { name : inputs . POLARIS_BRANCH_NAME } ) ,
93
+ parent : {
94
+ name : inputs . POLARIS_PARENT_BRANCH_NAME
95
+ }
96
+ }
93
97
}
94
98
const prCommentSeverities : string [ ] = [ ]
95
99
const inputPrCommentSeverities = inputs . POLARIS_PRCOMMENT_SEVERITIES
@@ -103,12 +107,12 @@ export class SynopsysToolsParameter {
103
107
}
104
108
polData . data . polaris . prComment = {
105
109
enabled : true ,
106
- severities : prCommentSeverities
110
+ ... ( prCommentSeverities . length > 0 && { severities : prCommentSeverities } )
107
111
}
108
112
polData . data . github = this . getGithubRepoInfo ( )
109
113
} else {
110
- /** Log warning if Polaris PR comment is enabled in case of non PR context */
111
- warning ( constants . POLARIS_PR_COMMENT_WARNING_FOR_NON_PR_SCANS )
114
+ /** Log info if Polaris PR comment is enabled in case of non PR context */
115
+ info ( constants . POLARIS_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS )
112
116
}
113
117
}
114
118
@@ -138,13 +142,19 @@ export class SynopsysToolsParameter {
138
142
polData . data . polaris . reports = {
139
143
sarif : {
140
144
create : true ,
141
- severities : sarifReportFilterSeverities ,
142
- file : {
143
- path : inputs . POLARIS_REPORTS_SARIF_FILE_PATH . trim ( )
144
- } ,
145
- issue : {
146
- types : sarifReportFilterAssessmentIssuesType
147
- } ,
145
+ ...( inputs . POLARIS_REPORTS_SARIF_SEVERITIES && {
146
+ severities : sarifReportFilterSeverities
147
+ } ) ,
148
+ ...( inputs . POLARIS_REPORTS_SARIF_FILE_PATH && {
149
+ file : {
150
+ path : inputs . POLARIS_REPORTS_SARIF_FILE_PATH . trim ( )
151
+ }
152
+ } ) ,
153
+ ...( inputs . POLARIS_REPORTS_SARIF_ISSUE_TYPES && {
154
+ issue : {
155
+ types : sarifReportFilterAssessmentIssuesType
156
+ }
157
+ } ) ,
148
158
groupSCAIssues : isBoolean ( inputs . POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES ) ? JSON . parse ( inputs . POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES ) : true
149
159
}
150
160
}
@@ -155,8 +165,8 @@ export class SynopsysToolsParameter {
155
165
}
156
166
} else {
157
167
if ( parseToBoolean ( inputs . POLARIS_REPORTS_SARIF_CREATE ) || parseToBoolean ( inputs . POLARIS_UPLOAD_SARIF_REPORT ) ) {
158
- /** Log warning if SARIF create is enabled in PR context */
159
- warning ( constants . SARIF_REPORT_WARNING_FOR_PR_SCANS )
168
+ /** Log info if SARIF create is enabled in PR context */
169
+ info ( constants . SARIF_REPORT_LOG_INFO_FOR_PR_SCANS )
160
170
}
161
171
}
162
172
@@ -195,13 +205,8 @@ export class SynopsysToolsParameter {
195
205
url : inputs . COVERITY_URL ,
196
206
project : { name : coverityProjectName } ,
197
207
stream : { name : coverityStreamName }
198
- } ,
199
- automation : { }
200
- } ,
201
- network : {
202
- airGap : inputs . ENABLE_NETWORK_AIR_GAP
203
- } ,
204
- project : { }
208
+ }
209
+ }
205
210
}
206
211
}
207
212
@@ -219,12 +224,19 @@ export class SynopsysToolsParameter {
219
224
covData . data . coverity . connect . policy = { view : inputs . COVERITY_POLICY_VIEW }
220
225
}
221
226
222
- if ( inputs . COVERITY_REPOSITORY_NAME ) {
223
- covData . data . project . repository = { name : inputs . COVERITY_REPOSITORY_NAME }
224
- }
225
-
226
- if ( inputs . COVERITY_BRANCH_NAME ) {
227
- covData . data . project . branch = { name : inputs . COVERITY_BRANCH_NAME }
227
+ if ( inputs . COVERITY_REPOSITORY_NAME || inputs . COVERITY_BRANCH_NAME ) {
228
+ covData . data . project = {
229
+ ...( inputs . COVERITY_REPOSITORY_NAME && {
230
+ repository : {
231
+ name : inputs . COVERITY_REPOSITORY_NAME
232
+ }
233
+ } ) ,
234
+ ...( inputs . COVERITY_BRANCH_NAME && {
235
+ branch : {
236
+ name : inputs . COVERITY_BRANCH_NAME
237
+ }
238
+ } )
239
+ }
228
240
}
229
241
230
242
if ( inputs . COVERITY_VERSION ) {
@@ -236,13 +248,17 @@ export class SynopsysToolsParameter {
236
248
/** Set Coverity PR comment inputs in case of PR context */
237
249
info ( 'Coverity PR comment is enabled' )
238
250
covData . data . github = this . getGithubRepoInfo ( )
239
- covData . data . coverity . automation . prcomment = true
251
+ covData . data . coverity . automation = { prcomment : true }
240
252
} else {
241
- /** Log warning if Coverity PR comment is enabled in case of non PR context */
242
- warning ( constants . COVERITY_PR_COMMENT_WARNING_FOR_NON_PR_SCANS )
253
+ /** Log info if Coverity PR comment is enabled in case of non PR context */
254
+ info ( constants . COVERITY_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS )
243
255
}
244
256
}
245
257
258
+ if ( isBoolean ( inputs . ENABLE_NETWORK_AIR_GAP ) ) {
259
+ covData . data . network = { airGap : parseToBoolean ( inputs . ENABLE_NETWORK_AIR_GAP ) }
260
+ }
261
+
246
262
const inputJson = JSON . stringify ( covData )
247
263
248
264
const stateFilePath = path . join ( this . tempDir , SynopsysToolsParameter . COVERITY_STATE_FILE_NAME )
@@ -277,11 +293,7 @@ export class SynopsysToolsParameter {
277
293
data : {
278
294
blackduck : {
279
295
url : inputs . BLACKDUCK_URL ,
280
- token : inputs . BLACKDUCK_API_TOKEN ,
281
- automation : { }
282
- } ,
283
- network : {
284
- airGap : inputs . ENABLE_NETWORK_AIR_GAP
296
+ token : inputs . BLACKDUCK_API_TOKEN
285
297
}
286
298
}
287
299
}
@@ -324,9 +336,9 @@ export class SynopsysToolsParameter {
324
336
/** Set Black Duck PR comment inputs in case of PR context */
325
337
info ( 'Black Duck PR comment is enabled' )
326
338
blackduckData . data . github = this . getGithubRepoInfo ( )
327
- blackduckData . data . blackduck . automation . prcomment = true
339
+ blackduckData . data . blackduck . automation = { prcomment : true }
328
340
} else {
329
- warning ( constants . BLACKDUCK_PR_COMMENT_WARNING_FOR_NON_PR_SCANS )
341
+ info ( constants . BLACKDUCK_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS )
330
342
}
331
343
}
332
344
if ( parseToBoolean ( inputs . BLACKDUCK_FIXPR_ENABLED ) ) {
@@ -336,7 +348,7 @@ export class SynopsysToolsParameter {
336
348
blackduckData . data . blackduck . fixpr = this . setBlackDuckFixPrInputs ( )
337
349
blackduckData . data . github = this . getGithubRepoInfo ( )
338
350
} else {
339
- warning ( constants . BLACKDUCK_FIXPR_WARNING_FOR_PR_SCANS )
351
+ info ( constants . BLACKDUCK_FIXPR_LOG_INFO_FOR_PR_SCANS )
340
352
}
341
353
}
342
354
if ( ! isPrEvent ) {
@@ -354,10 +366,14 @@ export class SynopsysToolsParameter {
354
366
blackduckData . data . blackduck . reports = {
355
367
sarif : {
356
368
create : true ,
357
- severities : sarifReportFilterSeverities ,
358
- file : {
359
- path : inputs . BLACKDUCK_REPORTS_SARIF_FILE_PATH . trim ( )
360
- } ,
369
+ ...( inputs . BLACKDUCK_REPORTS_SARIF_SEVERITIES && {
370
+ severities : sarifReportFilterSeverities
371
+ } ) ,
372
+ ...( inputs . BLACKDUCK_REPORTS_SARIF_FILE_PATH && {
373
+ file : {
374
+ path : inputs . BLACKDUCK_REPORTS_SARIF_FILE_PATH . trim ( )
375
+ }
376
+ } ) ,
361
377
groupSCAIssues : isBoolean ( inputs . BLACKDUCK_REPORTS_SARIF_GROUP_SCA_ISSUES ) ? JSON . parse ( inputs . BLACKDUCK_REPORTS_SARIF_GROUP_SCA_ISSUES ) : true
362
378
}
363
379
}
@@ -368,11 +384,15 @@ export class SynopsysToolsParameter {
368
384
}
369
385
} else {
370
386
if ( parseToBoolean ( inputs . BLACKDUCK_REPORTS_SARIF_CREATE ) || parseToBoolean ( inputs . BLACKDUCK_UPLOAD_SARIF_REPORT ) ) {
371
- /** Log warning if SARIF create/upload is enabled in PR context */
372
- warning ( constants . SARIF_REPORT_WARNING_FOR_PR_SCANS )
387
+ /** Log info if SARIF create/upload is enabled in PR context */
388
+ info ( constants . SARIF_REPORT_LOG_INFO_FOR_PR_SCANS )
373
389
}
374
390
}
375
391
392
+ if ( isBoolean ( inputs . ENABLE_NETWORK_AIR_GAP ) ) {
393
+ blackduckData . data . network = { airGap : parseToBoolean ( inputs . ENABLE_NETWORK_AIR_GAP ) }
394
+ }
395
+
376
396
const inputJson = JSON . stringify ( blackduckData )
377
397
378
398
const stateFilePath = path . join ( this . tempDir , SynopsysToolsParameter . BD_STATE_FILE_NAME )
@@ -393,6 +413,12 @@ export class SynopsysToolsParameter {
393
413
const githubServerUrl = process . env [ constants . GITHUB_ENVIRONMENT_VARIABLES . GITHUB_SERVER_URL ] || ''
394
414
const githubHostUrl = githubServerUrl === constants . GITHUB_CLOUD_URL ? '' : githubServerUrl
395
415
416
+ debug ( `Github Repository: ${ process . env [ constants . GITHUB_ENVIRONMENT_VARIABLES . GITHUB_REPOSITORY ] } ` )
417
+ debug ( `Github Ref Name: ${ process . env [ constants . GITHUB_ENVIRONMENT_VARIABLES . GITHUB_REF_NAME ] } ` )
418
+ debug ( `Github Head Ref: ${ process . env [ constants . GITHUB_ENVIRONMENT_VARIABLES . GITHUB_HEAD_REF ] } ` )
419
+ debug ( `Github Ref: ${ process . env [ constants . GITHUB_ENVIRONMENT_VARIABLES . GITHUB_REF ] } ` )
420
+ debug ( `Github Server Url: ${ process . env [ constants . GITHUB_ENVIRONMENT_VARIABLES . GITHUB_SERVER_URL ] } ` )
421
+
396
422
// pr number will be part of "refs/pull/<pr_number>/merge"
397
423
// if there is manual run without raising pr then GITHUB_REF will return refs/heads/branch_name
398
424
const githubPrNumber = githubRef !== undefined ? githubRef . split ( '/' ) [ 2 ] . trim ( ) : ''
@@ -410,6 +436,7 @@ export class SynopsysToolsParameter {
410
436
}
411
437
412
438
private setGithubData ( githubToken : string , githubRepoName : string , githubRepoOwner : string , githubBranchName : string , githubPrNumber : string , githubHostUrl : string ) : GithubData {
439
+ const isPrEvent = isPullRequestEvent ( )
413
440
const githubData : GithubData = {
414
441
user : {
415
442
token : githubToken
@@ -419,23 +446,26 @@ export class SynopsysToolsParameter {
419
446
owner : {
420
447
name : githubRepoOwner
421
448
} ,
422
- pull : { } ,
423
449
branch : {
424
450
name : githubBranchName
425
451
}
426
- } ,
427
- host : {
428
- url : githubHostUrl
429
452
}
430
453
}
431
- if ( githubPrNumber != null ) {
432
- githubData . repository . pull . number = Number ( githubPrNumber )
454
+ if ( isPrEvent && githubPrNumber != null ) {
455
+ githubData . repository . pull = {
456
+ number : Number ( githubPrNumber )
457
+ }
458
+ }
459
+ if ( githubHostUrl !== '' ) {
460
+ githubData . host = {
461
+ url : githubHostUrl
462
+ }
433
463
}
434
464
debug ( `Github repository name: ${ githubData . repository . name } ` )
435
465
debug ( `Github repository owner name: ${ githubData . repository . owner . name } ` )
436
466
debug ( `Github branch name: ${ githubData . repository . branch . name } ` )
437
467
debug ( `Github host url: ${ githubData . host ?. url } ` )
438
- debug ( `Github pull request number: ${ githubData . repository . pull . number } ` )
468
+ debug ( `Github pull request number: ${ githubData . repository . pull ? .number } ` )
439
469
return githubData
440
470
}
441
471
@@ -449,7 +479,9 @@ export class SynopsysToolsParameter {
449
479
}
450
480
const blackDuckFixPrData : BlackDuckFixPrData = { }
451
481
blackDuckFixPrData . enabled = true
452
- blackDuckFixPrData . createSinglePR = createSinglePr === true
482
+ if ( isBoolean ( inputs . BLACKDUCK_FIXPR_CREATE_SINGLE_PR ) ) {
483
+ blackDuckFixPrData . createSinglePR = parseToBoolean ( inputs . BLACKDUCK_FIXPR_CREATE_SINGLE_PR )
484
+ }
453
485
if ( inputs . BLACKDUCK_FIXPR_MAXCOUNT && ! createSinglePr ) {
454
486
blackDuckFixPrData . maxCount = Number ( inputs . BLACKDUCK_FIXPR_MAXCOUNT )
455
487
}
@@ -473,8 +505,8 @@ export class SynopsysToolsParameter {
473
505
}
474
506
}
475
507
}
476
- blackDuckFixPrData . filter = {
477
- ... ( fixPRFilterSeverities . length > 0 ? { severities : fixPRFilterSeverities } : { } )
508
+ if ( fixPRFilterSeverities . length > 0 ) {
509
+ blackDuckFixPrData . filter = { severities : fixPRFilterSeverities }
478
510
}
479
511
return blackDuckFixPrData
480
512
}
0 commit comments