Skip to content

Commit

Permalink
SCT-141 Changes PR report
Browse files Browse the repository at this point in the history
  • Loading branch information
francostramana committed Feb 28, 2024
1 parent 33cd66b commit f4e5a37
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
34 changes: 16 additions & 18 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createCommentOnPR, isPullRequest } from './utils/github.utils';
import { CopyleftPolicyCheck } from './policies/copyleft-policy-check';

Check warning on line 2 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'CopyleftPolicyCheck' is defined but never used

Check warning on line 2 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'CopyleftPolicyCheck' is defined but never used
import { generateJobSummary, generateSummary } from './services/report.service';
import { generateJobSummary, generatePRSummary } from './services/report.service';
import * as core from '@actions/core';
import * as inputs from './app.input';
import * as outputs from './app.output';
Expand Down Expand Up @@ -35,7 +35,7 @@ export async function run(): Promise<void> {

if (isPullRequest()) {
// create reports
const report = generateSummary(scan);
const report = generatePRSummary(scan, policies);
await createCommentOnPR(report);
}

Expand Down
32 changes: 15 additions & 17 deletions src/services/report.service.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import { ScannerResults } from './result.interfaces';
import { License, getLicenses } from './result.service';
import { License, getComponents, getLicenses } from './result.service';
import * as core from '@actions/core';
import { CONCLUSION, PolicyCheck } from '../policies/policy-check';
import { generateTable } from '../utils/markdown.utils';
export function getLicensesTable(licenses: License[]): string {
let markdownTable = '| License | Copyleft | URL |\n';
markdownTable += '| ------- | -------- | --- |\n';
import { context } from '@actions/github';

licenses.forEach(license => {
const copyleftIcon = license.copyleft ? ':x:' : ' ';
markdownTable += `| ${license.spdxid} | ${copyleftIcon} | ${license.url || ''} |\n`;
});

return markdownTable;
}

export function generateSummary(scannerResults: ScannerResults): string {
export function generatePRSummary(scannerResults: ScannerResults, policies: PolicyCheck[]): string {
const components = getComponents(scannerResults);
const licenses = getLicenses(scannerResults);
const licensesReport = getLicensesTable(licenses);

const polCount = {
total: policies.length,
success: policies.filter(p => p.conclusion === CONCLUSION.Success).length,
fail: policies.filter(p => p.conclusion !== CONCLUSION.Success).length
};

const content = `
## SCANOSS Summary :rocket:
### Licenses detected: ${licenses.length}
### SCANOSS SCAN Completed :rocket:
- **Components detected:** ${components.length}
- **Licenses detected:** ${licenses.length}
- **Policies:** ${polCount.fail ? `:x: ${polCount.fail} fail` : ''} ${polCount.success ? `:white_check_mark: ${polCount.success} pass` : ''} (${polCount.total} total)
${licensesReport}
View more details on [SCANOSS Action Summary](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})
`;

return content;
Expand Down

0 comments on commit f4e5a37

Please sign in to comment.