Skip to content
15 changes: 13 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ exports.BLACKDUCK_WAITFORSCAN = ((_56 = (0, core_1.getInput)(constants.BLACKDUCK
exports.BLACKDUCK_SEARCH_DEPTH = ((_57 = (0, core_1.getInput)(constants.BLACKDUCK_SEARCH_DEPTH_KEY)) === null || _57 === void 0 ? void 0 : _57.trim()) || '';
exports.BLACKDUCK_CONFIG_PATH = ((_58 = (0, core_1.getInput)(constants.BLACKDUCK_CONFIG_PATH_KEY)) === null || _58 === void 0 ? void 0 : _58.trim()) || '';
exports.BLACKDUCK_ARGS = ((_59 = (0, core_1.getInput)(constants.BLACKDUCK_ARGS_KEY)) === null || _59 === void 0 ? void 0 : _59.trim()) || '';
exports.BLACKDUCK_POLICY_BADGES_CREATE = ((_60 = (0, core_1.getInput)(constants.BLACKDUCK_POLICY_BADGES_CREATE_KEY)) === null || _60 === void 0 ? void 0 : _60.trim()) === 'true' || false;
exports.BLACKDUCK_POLICY_BADGES_CREATE = ((_60 = (0, core_1.getInput)(constants.BLACKDUCK_POLICY_BADGES_CREATE_KEY)) === null || _60 === void 0 ? void 0 : _60.trim()) || '';
exports.BLACKDUCK_POLICY_BADGES_MAX_COUNT = ((_61 = (0, core_1.getInput)(constants.BLACKDUCK_POLICY_BADGES_MAX_COUNT_KEY)) === null || _61 === void 0 ? void 0 : _61.trim()) || '';
exports.GITHUB_TOKEN = ((_62 = (0, core_1.getInput)(constants.GITHUB_TOKEN_KEY)) === null || _62 === void 0 ? void 0 : _62.trim()) || '';
exports.INCLUDE_DIAGNOSTICS = ((_63 = (0, core_1.getInput)(constants.INCLUDE_DIAGNOSTICS_KEY)) === null || _63 === void 0 ? void 0 : _63.trim()) || '';
Expand Down Expand Up @@ -2086,7 +2086,7 @@ class SynopsysToolsParameter {
(0, core_1.info)(constants.SARIF_REPORT_LOG_INFO_FOR_PR_SCANS);
}
}
if (inputs.BLACKDUCK_POLICY_BADGES_CREATE) {
if (inputs.BLACKDUCK_POLICY_BADGES_CREATE !== '' && (0, utility_1.parseToBoolean)(inputs.BLACKDUCK_POLICY_BADGES_CREATE)) {
blackduckData.data.blackduck.policy = {
badges: Object.assign({ create: true }, (Number.isInteger(parseInt(inputs.BLACKDUCK_POLICY_BADGES_MAX_COUNT)) && {
maxCount: parseInt(inputs.BLACKDUCK_POLICY_BADGES_MAX_COUNT)
Expand All @@ -2097,6 +2097,17 @@ class SynopsysToolsParameter {
blackduckData.data.github = this.getGithubRepoInfo();
}
}
else if (inputs.BLACKDUCK_POLICY_BADGES_CREATE !== '') {
blackduckData.data.blackduck.policy = {
badges: {
create: false
}
};
// Additional null check has been added to support avoid duplicate call to getGithubRepoInfo() when fix pr is enabled
if (blackduckData.data.github == null) {
blackduckData.data.github = this.getGithubRepoInfo();
}
}
if ((0, utility_1.isBoolean)(inputs.ENABLE_NETWORK_AIR_GAP)) {
blackduckData.data.network = { airGap: (0, utility_1.parseToBoolean)(inputs.ENABLE_NETWORK_AIR_GAP) };
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/synopsys-action/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const BLACKDUCK_WAITFORSCAN = getInput(constants.BLACKDUCK_WAITFORSCAN_KE
export const BLACKDUCK_SEARCH_DEPTH = getInput(constants.BLACKDUCK_SEARCH_DEPTH_KEY)?.trim() || ''
export const BLACKDUCK_CONFIG_PATH = getInput(constants.BLACKDUCK_CONFIG_PATH_KEY)?.trim() || ''
export const BLACKDUCK_ARGS = getInput(constants.BLACKDUCK_ARGS_KEY)?.trim() || ''
export const BLACKDUCK_POLICY_BADGES_CREATE = getInput(constants.BLACKDUCK_POLICY_BADGES_CREATE_KEY)?.trim() === 'true' || false
export const BLACKDUCK_POLICY_BADGES_CREATE = getInput(constants.BLACKDUCK_POLICY_BADGES_CREATE_KEY)?.trim() || ''
export const BLACKDUCK_POLICY_BADGES_MAX_COUNT = getInput(constants.BLACKDUCK_POLICY_BADGES_MAX_COUNT_KEY)?.trim() || ''
export const GITHUB_TOKEN = getInput(constants.GITHUB_TOKEN_KEY)?.trim() || ''
export const INCLUDE_DIAGNOSTICS = getInput(constants.INCLUDE_DIAGNOSTICS_KEY)?.trim() || ''
Expand Down
12 changes: 11 additions & 1 deletion src/synopsys-action/tools-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class SynopsysToolsParameter {
}
}

if (inputs.BLACKDUCK_POLICY_BADGES_CREATE) {
if (inputs.BLACKDUCK_POLICY_BADGES_CREATE !== '' && parseToBoolean(inputs.BLACKDUCK_POLICY_BADGES_CREATE)) {
blackduckData.data.blackduck.policy = {
badges: {
create: true,
Expand All @@ -464,6 +464,16 @@ export class SynopsysToolsParameter {
if (blackduckData.data.github == null) {
blackduckData.data.github = this.getGithubRepoInfo()
}
} else if (inputs.BLACKDUCK_POLICY_BADGES_CREATE !== '') {
blackduckData.data.blackduck.policy = {
badges: {
create: false
}
}
// Additional null check has been added to support avoid duplicate call to getGithubRepoInfo() when fix pr is enabled
if (blackduckData.data.github == null) {
blackduckData.data.github = this.getGithubRepoInfo()
}
}

if (isBoolean(inputs.ENABLE_NETWORK_AIR_GAP)) {
Expand Down
20 changes: 20 additions & 0 deletions test/unit/synopsys-action/tools-parameter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,26 @@ test('Test getFormattedCommandForBlackduck - badges', () => {
expect(jsonData.data.blackduck.policy.badges.maxCount).toBe(5)
})

test('Test getFormattedCommandForBlackduck - badges if false', () => {
Object.defineProperty(inputs, 'BLACKDUCK_URL', {value: 'BLACKDUCK_URL'})
Object.defineProperty(inputs, 'BLACKDUCK_API_TOKEN', {value: 'BLACKDUCK_API_TOKEN'})
Object.defineProperty(inputs, 'BLACKDUCK_INSTALL_DIRECTORY', {value: 'BLACKDUCK_INSTALL_DIRECTORY'})
Object.defineProperty(inputs, 'BLACKDUCK_SCAN_FULL', {value: 'TRUE'})
Object.defineProperty(inputs, 'BLACKDUCK_SCAN_FAILURE_SEVERITIES', {value: 'BLOCKER, CRITICAL, MAJOR'})
Object.defineProperty(inputs, 'BLACKDUCK_POLICY_BADGES_CREATE', {value: false})
process.env['GITHUB_SERVER_URL'] = 'https://custom.com'
let stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)

let resp = stp.getFormattedCommandForBlackduck()

expect(resp).not.toBeNull()
expect(resp).toContain('--stage blackduck')

const jsonString = fs.readFileSync(tempPath.concat(blackduck_input_file), 'utf-8')
const jsonData = JSON.parse(jsonString)
expect(jsonData.data.blackduck.policy.badges.create).toBe(false)
})

test('Test getFormattedCommandForBlackduck - badges failure (empty github token)', () => {
Object.defineProperty(inputs, 'GITHUB_TOKEN', {value: ''})
Object.defineProperty(inputs, 'BLACKDUCK_URL', {value: 'BLACKDUCK_URL'})
Expand Down