Skip to content

Commit ec86791

Browse files
SIGINT-1661, SIGINT-1730, SIGINT-1755 (#218)
1 parent 187fefc commit ec86791

File tree

10 files changed

+189
-143
lines changed

10 files changed

+189
-143
lines changed

dist/index.js

Lines changed: 81 additions & 67 deletions
Large diffs are not rendered by default.

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/application-constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ export const GITHUB_ENVIRONMENT_VARIABLES = {
140140
GITHUB_SHA: 'GITHUB_SHA'
141141
}
142142
export const GITHUB_TOKEN_VALIDATION_SARIF_UPLOAD_ERROR = 'Missing required GitHub token for uploading SARIF report to GitHub Advanced Security'
143-
export const SARIF_REPORT_WARNING_FOR_PR_SCANS = 'SARIF report create/upload is ignored for pull request scan'
144-
export const POLARIS_PR_COMMENT_WARNING_FOR_NON_PR_SCANS = 'Polaris PR Comment is ignored for non pull request scan'
145-
export const COVERITY_PR_COMMENT_WARNING_FOR_NON_PR_SCANS = 'Coverity PR Comment is ignored for non pull request scan'
146-
export const BLACKDUCK_PR_COMMENT_WARNING_FOR_NON_PR_SCANS = 'Black Duck PR Comment is ignored for non pull request scan'
147-
export const BLACKDUCK_FIXPR_WARNING_FOR_PR_SCANS = 'Black Duck Fix PR is ignored for pull request scan'
143+
export const SARIF_REPORT_LOG_INFO_FOR_PR_SCANS = 'SARIF report create/upload is ignored for pull request scan'
144+
export const POLARIS_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS = 'Polaris PR Comment is ignored for non pull request scan'
145+
export const COVERITY_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS = 'Coverity PR Comment is ignored for non pull request scan'
146+
export const BLACKDUCK_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS = 'Black Duck PR Comment is ignored for non pull request scan'
147+
export const BLACKDUCK_FIXPR_LOG_INFO_FOR_PR_SCANS = 'Black Duck Fix PR is ignored for pull request scan'
148148
export const MISSING_GITHUB_TOKEN_FOR_FIX_PR_AND_PR_COMMENT = 'Missing required github token for fix pull request/pull request comments'

src/synopsys-action/input-data/blackduck.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ export enum BLACKDUCK_SCAN_FAILURE_SEVERITIES {
1515
export interface Blackduck {
1616
blackduck: BlackduckData
1717
github?: GithubData
18-
network: NetworkAirGap
18+
network?: NetworkAirGap
1919
}
2020

2121
export interface BlackduckData {
2222
url: string
2323
token: string
2424
install?: {directory: string}
2525
scan?: {full?: boolean; failure?: {severities: BLACKDUCK_SCAN_FAILURE_SEVERITIES[]}}
26-
automation: AutomationData
26+
automation?: AutomationData
2727
fixpr?: BlackDuckFixPrData
2828
reports?: Reports
2929
}
@@ -44,7 +44,7 @@ export interface Repository {
4444
name: string
4545
branch: Branch
4646
owner: Owner
47-
pull: {number?: number}
47+
pull?: {number?: number}
4848
}
4949

5050
export interface AutomationData {

src/synopsys-action/input-data/coverity.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {GithubData} from './blackduck'
22

33
export interface Coverity {
44
coverity: CoverityConnect
5-
project: ProjectData
5+
project?: ProjectData
66
github?: GithubData
7-
network: NetworkAirGap
7+
network?: NetworkAirGap
88
}
99

1010
export interface ProjectData {
@@ -19,7 +19,7 @@ export interface AutomationData {
1919
export interface CoverityConnect {
2020
connect: CoverityData
2121
install?: {directory: string}
22-
automation: AutomationData
22+
automation?: AutomationData
2323
local?: boolean
2424
version?: string
2525
}

src/synopsys-action/input-data/polaris.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface PolarisData {
1212
serverUrl: string
1313
application: {name: string}
1414
project: {name: string}
15-
branch: Branch
15+
branch?: Branch
1616
assessment: {types: string[]}
1717
prComment?: PrComment
1818
test?: Test
@@ -26,7 +26,7 @@ export interface PrComment {
2626

2727
export interface Branch {
2828
name?: string
29-
parent: {name?: string}
29+
parent?: {name?: string}
3030
}
3131

3232
export interface Test {

src/synopsys-action/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {getInput} from '@actions/core'
22
import * as constants from '../application-constants'
33

44
export const SYNOPSYS_BRIDGE_INSTALL_DIRECTORY_KEY = getInput(constants.SYNOPSYS_BRIDGE_INSTALL_DIRECTORY_KEY)?.trim() || ''
5-
export const ENABLE_NETWORK_AIR_GAP = (getInput(constants.NETWORK_AIRGAP_KEY)?.trim() || getInput(constants.BRIDGE_NETWORK_AIRGAP_KEY)?.trim()) === 'true' || false
5+
export const ENABLE_NETWORK_AIR_GAP = getInput(constants.NETWORK_AIRGAP_KEY)?.trim() || getInput(constants.BRIDGE_NETWORK_AIRGAP_KEY)?.trim() || ''
66

77
//Bridge download url
88
export const BRIDGE_DOWNLOAD_URL = getInput(constants.BRIDGE_DOWNLOAD_URL_KEY)?.trim() || getInput(constants.SYNOPSYS_BRIDGE_DOWNLOAD_URL_KEY)?.trim() || ''

src/synopsys-action/tools-parameter.ts

Lines changed: 89 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs'
22
import path from 'path'
3-
import {debug, info, warning} from '@actions/core'
3+
import {debug, info} from '@actions/core'
44
import {isNullOrEmptyValue, validateBlackduckFailureSeverities, validateCoverityInstallDirectoryParam} from './validators'
55
import * as inputs from './inputs'
66
import {Polaris} from './input-data/polaris'
@@ -64,8 +64,7 @@ export class SynopsysToolsParameter {
6464
serverUrl: inputs.POLARIS_SERVER_URL,
6565
application: {name: applicationName},
6666
project: {name: projectName},
67-
assessment: {types: assessmentTypeArray},
68-
branch: {parent: {}}
67+
assessment: {types: assessmentTypeArray}
6968
}
7069
}
7170
}
@@ -74,7 +73,7 @@ export class SynopsysToolsParameter {
7473
polData.data.polaris.triage = inputs.POLARIS_TRIAGE
7574
}
7675
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}
7877
}
7978
if (inputs.POLARIS_TEST_SCA_TYPE) {
8079
polData.data.polaris.test = {
@@ -89,7 +88,12 @@ export class SynopsysToolsParameter {
8988
/** Set Polaris PR comment inputs in case of PR context */
9089
info('Polaris PR comment is enabled')
9190
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+
}
9397
}
9498
const prCommentSeverities: string[] = []
9599
const inputPrCommentSeverities = inputs.POLARIS_PRCOMMENT_SEVERITIES
@@ -103,12 +107,12 @@ export class SynopsysToolsParameter {
103107
}
104108
polData.data.polaris.prComment = {
105109
enabled: true,
106-
severities: prCommentSeverities
110+
...(prCommentSeverities.length > 0 && {severities: prCommentSeverities})
107111
}
108112
polData.data.github = this.getGithubRepoInfo()
109113
} 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)
112116
}
113117
}
114118

@@ -138,13 +142,19 @@ export class SynopsysToolsParameter {
138142
polData.data.polaris.reports = {
139143
sarif: {
140144
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+
}),
148158
groupSCAIssues: isBoolean(inputs.POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES) ? JSON.parse(inputs.POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES) : true
149159
}
150160
}
@@ -155,8 +165,8 @@ export class SynopsysToolsParameter {
155165
}
156166
} else {
157167
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)
160170
}
161171
}
162172

@@ -195,13 +205,8 @@ export class SynopsysToolsParameter {
195205
url: inputs.COVERITY_URL,
196206
project: {name: coverityProjectName},
197207
stream: {name: coverityStreamName}
198-
},
199-
automation: {}
200-
},
201-
network: {
202-
airGap: inputs.ENABLE_NETWORK_AIR_GAP
203-
},
204-
project: {}
208+
}
209+
}
205210
}
206211
}
207212

@@ -219,12 +224,19 @@ export class SynopsysToolsParameter {
219224
covData.data.coverity.connect.policy = {view: inputs.COVERITY_POLICY_VIEW}
220225
}
221226

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+
}
228240
}
229241

230242
if (inputs.COVERITY_VERSION) {
@@ -236,13 +248,17 @@ export class SynopsysToolsParameter {
236248
/** Set Coverity PR comment inputs in case of PR context */
237249
info('Coverity PR comment is enabled')
238250
covData.data.github = this.getGithubRepoInfo()
239-
covData.data.coverity.automation.prcomment = true
251+
covData.data.coverity.automation = {prcomment: true}
240252
} 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)
243255
}
244256
}
245257

258+
if (isBoolean(inputs.ENABLE_NETWORK_AIR_GAP)) {
259+
covData.data.network = {airGap: parseToBoolean(inputs.ENABLE_NETWORK_AIR_GAP)}
260+
}
261+
246262
const inputJson = JSON.stringify(covData)
247263

248264
const stateFilePath = path.join(this.tempDir, SynopsysToolsParameter.COVERITY_STATE_FILE_NAME)
@@ -277,11 +293,7 @@ export class SynopsysToolsParameter {
277293
data: {
278294
blackduck: {
279295
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
285297
}
286298
}
287299
}
@@ -324,9 +336,9 @@ export class SynopsysToolsParameter {
324336
/** Set Black Duck PR comment inputs in case of PR context */
325337
info('Black Duck PR comment is enabled')
326338
blackduckData.data.github = this.getGithubRepoInfo()
327-
blackduckData.data.blackduck.automation.prcomment = true
339+
blackduckData.data.blackduck.automation = {prcomment: true}
328340
} else {
329-
warning(constants.BLACKDUCK_PR_COMMENT_WARNING_FOR_NON_PR_SCANS)
341+
info(constants.BLACKDUCK_PR_COMMENT_LOG_INFO_FOR_NON_PR_SCANS)
330342
}
331343
}
332344
if (parseToBoolean(inputs.BLACKDUCK_FIXPR_ENABLED)) {
@@ -336,7 +348,7 @@ export class SynopsysToolsParameter {
336348
blackduckData.data.blackduck.fixpr = this.setBlackDuckFixPrInputs()
337349
blackduckData.data.github = this.getGithubRepoInfo()
338350
} else {
339-
warning(constants.BLACKDUCK_FIXPR_WARNING_FOR_PR_SCANS)
351+
info(constants.BLACKDUCK_FIXPR_LOG_INFO_FOR_PR_SCANS)
340352
}
341353
}
342354
if (!isPrEvent) {
@@ -354,10 +366,14 @@ export class SynopsysToolsParameter {
354366
blackduckData.data.blackduck.reports = {
355367
sarif: {
356368
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+
}),
361377
groupSCAIssues: isBoolean(inputs.BLACKDUCK_REPORTS_SARIF_GROUP_SCA_ISSUES) ? JSON.parse(inputs.BLACKDUCK_REPORTS_SARIF_GROUP_SCA_ISSUES) : true
362378
}
363379
}
@@ -368,11 +384,15 @@ export class SynopsysToolsParameter {
368384
}
369385
} else {
370386
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)
373389
}
374390
}
375391

392+
if (isBoolean(inputs.ENABLE_NETWORK_AIR_GAP)) {
393+
blackduckData.data.network = {airGap: parseToBoolean(inputs.ENABLE_NETWORK_AIR_GAP)}
394+
}
395+
376396
const inputJson = JSON.stringify(blackduckData)
377397

378398
const stateFilePath = path.join(this.tempDir, SynopsysToolsParameter.BD_STATE_FILE_NAME)
@@ -393,6 +413,12 @@ export class SynopsysToolsParameter {
393413
const githubServerUrl = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_SERVER_URL] || ''
394414
const githubHostUrl = githubServerUrl === constants.GITHUB_CLOUD_URL ? '' : githubServerUrl
395415

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+
396422
// pr number will be part of "refs/pull/<pr_number>/merge"
397423
// if there is manual run without raising pr then GITHUB_REF will return refs/heads/branch_name
398424
const githubPrNumber = githubRef !== undefined ? githubRef.split('/')[2].trim() : ''
@@ -410,6 +436,7 @@ export class SynopsysToolsParameter {
410436
}
411437

412438
private setGithubData(githubToken: string, githubRepoName: string, githubRepoOwner: string, githubBranchName: string, githubPrNumber: string, githubHostUrl: string): GithubData {
439+
const isPrEvent = isPullRequestEvent()
413440
const githubData: GithubData = {
414441
user: {
415442
token: githubToken
@@ -419,23 +446,26 @@ export class SynopsysToolsParameter {
419446
owner: {
420447
name: githubRepoOwner
421448
},
422-
pull: {},
423449
branch: {
424450
name: githubBranchName
425451
}
426-
},
427-
host: {
428-
url: githubHostUrl
429452
}
430453
}
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+
}
433463
}
434464
debug(`Github repository name: ${githubData.repository.name}`)
435465
debug(`Github repository owner name: ${githubData.repository.owner.name}`)
436466
debug(`Github branch name: ${githubData.repository.branch.name}`)
437467
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}`)
439469
return githubData
440470
}
441471

@@ -449,7 +479,9 @@ export class SynopsysToolsParameter {
449479
}
450480
const blackDuckFixPrData: BlackDuckFixPrData = {}
451481
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+
}
453485
if (inputs.BLACKDUCK_FIXPR_MAXCOUNT && !createSinglePr) {
454486
blackDuckFixPrData.maxCount = Number(inputs.BLACKDUCK_FIXPR_MAXCOUNT)
455487
}
@@ -473,8 +505,8 @@ export class SynopsysToolsParameter {
473505
}
474506
}
475507
}
476-
blackDuckFixPrData.filter = {
477-
...(fixPRFilterSeverities.length > 0 ? {severities: fixPRFilterSeverities} : {})
508+
if (fixPRFilterSeverities.length > 0) {
509+
blackDuckFixPrData.filter = {severities: fixPRFilterSeverities}
478510
}
479511
return blackDuckFixPrData
480512
}

0 commit comments

Comments
 (0)