Skip to content

Commit 5d747ee

Browse files
Merge pull request #53 from blackduck-inc/fix-enterprise-api-url
fix: update GitHub Enterprise API URL - Add SarifData interface with optional validate property - Implement createSarifData method to set validate flag based on GitHub API URL ref: [SIGINT-2887], [SIGINT-2769]
2 parents 66ede8f + 87ba660 commit 5d747ee

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

dist/index.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ class GithubClientServiceBase {
14641464
this.repoName = this.githubRepo !== '' ? this.githubRepo.substring(this.githubRepo.indexOf('/') + 1, this.githubRepo.length).trim() : '';
14651465
this.repoOwner = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REPOSITORY_OWNER] || '';
14661466
this.githubServerUrl = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_SERVER_URL] || '';
1467-
this.githubApiURL = this.githubServerUrl === constants.GITHUB_CLOUD_URL ? constants.GITHUB_CLOUD_API_URL : this.githubServerUrl;
1467+
this.githubApiURL = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_API_URL] || '';
14681468
this.commit_sha = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_SHA] || '';
14691469
this.githubRef = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF] || '';
14701470
}
@@ -1484,12 +1484,7 @@ class GithubClientServiceBase {
14841484
const sarifContent = fs.readFileSync(sarifFilePath, 'utf8');
14851485
const compressedSarif = zlib.gzipSync(sarifContent);
14861486
const base64Sarif = compressedSarif.toString('base64');
1487-
const data = {
1488-
commit_sha: this.commit_sha,
1489-
ref: this.githubRef,
1490-
sarif: base64Sarif,
1491-
validate: true
1492-
};
1487+
const data = this.createSarifData(base64Sarif);
14931488
do {
14941489
const httpClient = new HttpClient_1.HttpClient('GithubClientServiceBase');
14951490
const httpResponse = yield httpClient.post(endpoint, JSON.stringify(data), {
@@ -1535,6 +1530,17 @@ class GithubClientServiceBase {
15351530
}
15361531
});
15371532
}
1533+
createSarifData(base64Sarif) {
1534+
const data = {
1535+
commit_sha: this.commit_sha,
1536+
ref: this.githubRef,
1537+
sarif: base64Sarif
1538+
};
1539+
if (this.githubApiURL === constants.GITHUB_CLOUD_API_URL) {
1540+
data.validate = true;
1541+
}
1542+
return data;
1543+
}
15381544
retrySleepHelper(message, retryCountLocal, retryDelay) {
15391545
return __awaiter(this, void 0, void 0, function* () {
15401546
(0, core_1.info)(message
@@ -2803,14 +2809,13 @@ function run() {
28032809
yield (0, artifacts_1.uploadSarifReportAsArtifact)(constants.POLARIS_SARIF_GENERATOR_DIRECTORY, inputs.POLARIS_REPORTS_SARIF_FILE_PATH, constants.POLARIS_SARIF_ARTIFACT_NAME);
28042810
}
28052811
if (!(0, validators_1.isNullOrEmptyValue)(inputs.GITHUB_TOKEN)) {
2812+
const gitHubClientService = yield github_client_service_factory_1.GitHubClientServiceFactory.getGitHubClientServiceInstance();
28062813
// Upload Black Duck SARIF Report to code scanning tab
28072814
if (inputs.BLACKDUCKSCA_URL && (0, utility_1.parseToBoolean)(inputs.BLACKDUCK_UPLOAD_SARIF_REPORT)) {
2808-
const gitHubClientService = yield github_client_service_factory_1.GitHubClientServiceFactory.getGitHubClientServiceInstance();
28092815
yield gitHubClientService.uploadSarifReport(constants.BLACKDUCK_SARIF_GENERATOR_DIRECTORY, inputs.BLACKDUCKSCA_REPORTS_SARIF_FILE_PATH);
28102816
}
28112817
// Upload Polaris SARIF Report to code scanning tab
28122818
if (inputs.POLARIS_SERVER_URL && (0, utility_1.parseToBoolean)(inputs.POLARIS_UPLOAD_SARIF_REPORT)) {
2813-
const gitHubClientService = yield github_client_service_factory_1.GitHubClientServiceFactory.getGitHubClientServiceInstance();
28142819
yield gitHubClientService.uploadSarifReport(constants.POLARIS_SARIF_GENERATOR_DIRECTORY, inputs.POLARIS_REPORTS_SARIF_FILE_PATH);
28152820
}
28162821
}

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.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface SarifData {
2+
commit_sha: string
3+
ref: string
4+
sarif: string
5+
validate?: boolean
6+
}

src/blackduck-security-action/service/impl/github-client-service-base.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {checkIfPathExists, getDefaultSarifReportPath, sleep} from '../../utility
66
import {debug, info} from '@actions/core'
77
import * as constants from '../../../application-constants'
88
import {GithubClientServiceInterface} from '../github-client-service-interface'
9+
import {SarifData} from '../../input-data/sarif-data'
910

1011
export class GithubClientServiceBase implements GithubClientServiceInterface {
1112
gitHubCodeScanningUrl: string
@@ -25,7 +26,7 @@ export class GithubClientServiceBase implements GithubClientServiceInterface {
2526
this.repoName = this.githubRepo !== '' ? this.githubRepo.substring(this.githubRepo.indexOf('/') + 1, this.githubRepo.length).trim() : ''
2627
this.repoOwner = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REPOSITORY_OWNER] || ''
2728
this.githubServerUrl = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_SERVER_URL] || ''
28-
this.githubApiURL = this.githubServerUrl === constants.GITHUB_CLOUD_URL ? constants.GITHUB_CLOUD_API_URL : this.githubServerUrl
29+
this.githubApiURL = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_API_URL] || ''
2930
this.commit_sha = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_SHA] || ''
3031
this.githubRef = process.env[constants.GITHUB_ENVIRONMENT_VARIABLES.GITHUB_REF] || ''
3132
}
@@ -45,12 +46,7 @@ export class GithubClientServiceBase implements GithubClientServiceInterface {
4546
const sarifContent = fs.readFileSync(sarifFilePath, 'utf8')
4647
const compressedSarif = zlib.gzipSync(sarifContent)
4748
const base64Sarif = compressedSarif.toString('base64')
48-
const data = {
49-
commit_sha: this.commit_sha,
50-
ref: this.githubRef,
51-
sarif: base64Sarif,
52-
validate: true
53-
}
49+
const data = this.createSarifData(base64Sarif)
5450
do {
5551
const httpClient = new HttpClient('GithubClientServiceBase')
5652
const httpResponse = await httpClient.post(endpoint, JSON.stringify(data), {
@@ -91,6 +87,18 @@ export class GithubClientServiceBase implements GithubClientServiceInterface {
9187
}
9288
}
9389

90+
private createSarifData(base64Sarif: string): SarifData {
91+
const data: SarifData = {
92+
commit_sha: this.commit_sha,
93+
ref: this.githubRef,
94+
sarif: base64Sarif
95+
}
96+
if (this.githubApiURL === constants.GITHUB_CLOUD_API_URL) {
97+
data.validate = true
98+
}
99+
return data
100+
}
101+
94102
private async retrySleepHelper(message: string, retryCountLocal: number, retryDelay: number): Promise<number> {
95103
info(
96104
message

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ export async function run() {
6464
await uploadSarifReportAsArtifact(constants.POLARIS_SARIF_GENERATOR_DIRECTORY, inputs.POLARIS_REPORTS_SARIF_FILE_PATH, constants.POLARIS_SARIF_ARTIFACT_NAME)
6565
}
6666
if (!isNullOrEmptyValue(inputs.GITHUB_TOKEN)) {
67+
const gitHubClientService = await GitHubClientServiceFactory.getGitHubClientServiceInstance()
6768
// Upload Black Duck SARIF Report to code scanning tab
6869
if (inputs.BLACKDUCKSCA_URL && parseToBoolean(inputs.BLACKDUCK_UPLOAD_SARIF_REPORT)) {
69-
const gitHubClientService = await GitHubClientServiceFactory.getGitHubClientServiceInstance()
7070
await gitHubClientService.uploadSarifReport(constants.BLACKDUCK_SARIF_GENERATOR_DIRECTORY, inputs.BLACKDUCKSCA_REPORTS_SARIF_FILE_PATH)
7171
}
7272
// Upload Polaris SARIF Report to code scanning tab
7373
if (inputs.POLARIS_SERVER_URL && parseToBoolean(inputs.POLARIS_UPLOAD_SARIF_REPORT)) {
74-
const gitHubClientService = await GitHubClientServiceFactory.getGitHubClientServiceInstance()
7574
await gitHubClientService.uploadSarifReport(constants.POLARIS_SARIF_GENERATOR_DIRECTORY, inputs.POLARIS_REPORTS_SARIF_FILE_PATH)
7675
}
7776
}

0 commit comments

Comments
 (0)