Skip to content

Commit

Permalink
feat: SIGINT-1836 github badges
Browse files Browse the repository at this point in the history
  • Loading branch information
lsynopsys committed Aug 16, 2024
1 parent fd2c04f commit 559c45c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
18 changes: 15 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2071,14 +2071,16 @@ class SynopsysToolsParameter {
maxCount: parseInt(inputs.BLACKDUCK_POLICY_BADGES_MAX_COUNT)
}))
};
blackduckData.data.github = this.getGithubRepoInfo();
if (blackduckData.data.github != null) {
(0, core_1.info)('entered');
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) };
}
blackduckData.data.blackduck = Object.assign({}, this.setBlackDuckArbitraryArgs(), blackduckData.data.blackduck);
const inputJson = JSON.stringify(blackduckData);
(0, core_1.info)(inputJson);
const stateFilePath = path_1.default.join(this.tempDir, SynopsysToolsParameter.BD_STATE_FILE_NAME);
fs.writeFileSync(stateFilePath, inputJson);
(0, core_1.debug)('Generated state json file at - '.concat(stateFilePath));
Expand Down Expand Up @@ -2151,7 +2153,7 @@ class SynopsysToolsParameter {
const githubToken = inputs.GITHUB_TOKEN;
const githubRepo = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REPOSITORY];
const githubRepoName = githubRepo !== undefined ? githubRepo.substring(githubRepo.indexOf('/') + 1, githubRepo.length).trim() : '';
const githubBranchName = ((0, utility_1.parseToBoolean)(inputs.POLARIS_PRCOMMENT_ENABLED) || (0, utility_1.parseToBoolean)(inputs.BLACKDUCK_POLICY_BADGES_CREATE) ? process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_HEAD_REF] : process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF_NAME]) || '';
const githubBranchName = this.getGithubBranchName();
const githubRef = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF];
const githubServerUrl = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_SERVER_URL] || '';
const githubHostUrl = githubServerUrl === constants.GITHUB_CLOUD_URL ? '' : githubServerUrl;
Expand All @@ -2173,6 +2175,16 @@ class SynopsysToolsParameter {
}
return undefined;
}
getGithubBranchName() {
let branchName = '';
if ((0, utility_1.parseToBoolean)(inputs.BLACKDUCK_POLICY_BADGES_CREATE) && (0, utility_1.parseToBoolean)(inputs.BLACKDUCK_FIXPR_ENABLED)) {
branchName = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF_NAME] || '';
}
else if ((0, utility_1.parseToBoolean)(inputs.POLARIS_PRCOMMENT_ENABLED) || (0, utility_1.parseToBoolean)(inputs.BLACKDUCK_POLICY_BADGES_CREATE)) {
branchName = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_HEAD_REF] || '';
}
return branchName;
}
setGithubData(githubToken, githubRepoName, githubRepoOwner, githubBranchName, githubPrNumber, githubHostUrl) {
var _a, _b;
const isPrEvent = (0, utility_1.isPullRequestEvent)();
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/synopsys-action/tools-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ export class SynopsysToolsParameter {
})
}
}
blackduckData.data.github = this.getGithubRepoInfo()
if (blackduckData.data.github != null) {
info('entered')
blackduckData.data.github = this.getGithubRepoInfo()
}
}

if (isBoolean(inputs.ENABLE_NETWORK_AIR_GAP)) {
Expand All @@ -458,7 +461,6 @@ export class SynopsysToolsParameter {
blackduckData.data.blackduck = Object.assign({}, this.setBlackDuckArbitraryArgs(), blackduckData.data.blackduck)

const inputJson = JSON.stringify(blackduckData)
info(inputJson)

const stateFilePath = path.join(this.tempDir, SynopsysToolsParameter.BD_STATE_FILE_NAME)
fs.writeFileSync(stateFilePath, inputJson)
Expand Down Expand Up @@ -554,7 +556,7 @@ export class SynopsysToolsParameter {
const githubToken = inputs.GITHUB_TOKEN
const githubRepo = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REPOSITORY]
const githubRepoName = githubRepo !== undefined ? githubRepo.substring(githubRepo.indexOf('/') + 1, githubRepo.length).trim() : ''
const githubBranchName = (parseToBoolean(inputs.POLARIS_PRCOMMENT_ENABLED) || parseToBoolean(inputs.BLACKDUCK_POLICY_BADGES_CREATE) ? process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_HEAD_REF] : process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF_NAME]) || ''
const githubBranchName = this.getGithubBranchName()
const githubRef = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF]
const githubServerUrl = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_SERVER_URL] || ''
const githubHostUrl = githubServerUrl === constants.GITHUB_CLOUD_URL ? '' : githubServerUrl
Expand All @@ -581,6 +583,16 @@ export class SynopsysToolsParameter {
return undefined
}

private getGithubBranchName(): string {
let branchName = ''
if (parseToBoolean(inputs.BLACKDUCK_POLICY_BADGES_CREATE) && parseToBoolean(inputs.BLACKDUCK_FIXPR_ENABLED)) {
branchName = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF_NAME] || ''
} else if (parseToBoolean(inputs.POLARIS_PRCOMMENT_ENABLED) || parseToBoolean(inputs.BLACKDUCK_POLICY_BADGES_CREATE)) {
branchName = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_HEAD_REF] || ''
}
return branchName
}

private setGithubData(githubToken: string, githubRepoName: string, githubRepoOwner: string, githubBranchName: string, githubPrNumber: string, githubHostUrl: string): GithubData {
const isPrEvent = isPullRequestEvent()
const githubData: GithubData = {
Expand Down

0 comments on commit 559c45c

Please sign in to comment.