Skip to content

Commit

Permalink
🐛 Fix dependency summary
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Apr 25, 2024
1 parent e185f83 commit 5faa8fe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion common/qodana.ts
Expand Up @@ -13,7 +13,7 @@ export const QODANA_REPORT_URL_NAME = 'qodana.cloud'
export const QODANA_OPEN_IN_IDE_NAME = 'open-in-ide.json'

export const QODANA_LICENSES_MD = 'thirdPartySoftwareList.md'
export const QODANA_LICENSES_JSON = 'thirdPartySoftwareList.json'
export const QODANA_LICENSES_JSON = 'third-party-libraries.json'
export const EXECUTABLE = 'qodana'
export const VERSION = version

Expand Down
4 changes: 3 additions & 1 deletion scan/__tests__/main.test.ts
Expand Up @@ -45,6 +45,7 @@ test('test typical summary output', () => {
'Qodana for JS',
annotationsDefaultFixture().reverse(), // reversed for testing the correct sorting in output
'',
0,
'There is no licenses information available',
'https://example.com/report',
true
Expand All @@ -57,6 +58,7 @@ test('test empty summary output', () => {
'Qodana for JS',
outputEmptyFixture(),
'',
0,
'',
'',
false
Expand Down Expand Up @@ -264,7 +266,7 @@ export function markdownSummaryFixture(): string {
💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ [View the detailed Qodana report](https://example.com/report)
<details>
<summary>Dependencies licenses</summary>
<summary>Detected 0 dependencies</summary>
There is no licenses information available
</details>
Expand Down
17 changes: 12 additions & 5 deletions scan/dist/index.js
Expand Up @@ -24462,7 +24462,7 @@ var init_qodana = __esm({
QODANA_REPORT_URL_NAME = "qodana.cloud";
QODANA_OPEN_IN_IDE_NAME = "open-in-ide.json";
QODANA_LICENSES_MD = "thirdPartySoftwareList.md";
QODANA_LICENSES_JSON = "thirdPartySoftwareList.json";
QODANA_LICENSES_JSON = "third-party-libraries.json";
EXECUTABLE = "qodana";
VERSION = version2;
COVERAGE_THRESHOLD = 50;
Expand Down Expand Up @@ -125870,7 +125870,7 @@ var require_output = __commonJS({
});
};
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.prFixesBody = exports2.getProblemPlural = exports2.getSummary = exports2.publishOutput = exports2.getReportURL = exports2.getCoverageStats = exports2.COMMIT_EMAIL = exports2.COMMIT_USER = void 0;
exports2.prFixesBody = exports2.getDepencencyPlural = exports2.getProblemPlural = exports2.getSummary = exports2.publishOutput = exports2.getReportURL = exports2.getCoverageStats = exports2.COMMIT_EMAIL = exports2.COMMIT_USER = void 0;
var core2 = __importStar3(require_core());
var fs2 = __importStar3(require("fs"));
var qodana_12 = (init_qodana(), __toCommonJS(qodana_exports));
Expand Down Expand Up @@ -125965,16 +125965,18 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`;
const reportUrl = getReportURL(resultsDir);
const coverageInfo = getCoverageStats((0, qodana_12.getCoverageFromSarif)(`${resultsDir}/${qodana_12.QODANA_SHORT_SARIF_NAME}`), qodana_12.COVERAGE_THRESHOLD);
let licensesInfo = "";
let packages = 0;
const licensesJson = `${resultsDir}/projectStructure/${qodana_12.QODANA_LICENSES_JSON}`;
if (fs2.existsSync(licensesJson)) {
const licenses = JSON.parse(fs2.readFileSync(licensesJson, { encoding: "utf8" }));
if (licenses.length > 0) {
packages = licenses.length;
licensesInfo = fs2.readFileSync(`${resultsDir}/projectStructure/${qodana_12.QODANA_LICENSES_MD}`, { encoding: "utf8" });
}
}
const annotations = (_a = problems.annotations) !== null && _a !== void 0 ? _a : [];
const toolName = (_b = problems.title.split("found by ")[1]) !== null && _b !== void 0 ? _b : QODANA_CHECK_NAME;
problems.summary = getSummary(toolName, annotations, coverageInfo, licensesInfo, reportUrl, isPrMode);
problems.summary = getSummary(toolName, annotations, coverageInfo, packages, licensesInfo, reportUrl, isPrMode);
yield Promise.all([
(0, utils_12.putReaction)(utils_12.ANALYSIS_FINISHED_REACTION, utils_12.ANALYSIS_STARTED_REACTION),
(0, utils_12.postResultsToPRComments)(toolName, problems.summary, postComment),
Expand Down Expand Up @@ -126011,11 +126013,11 @@ ${body}
return Array.from(problems.entries()).sort((a, b) => b[1] - a[1]).map(([title, count]) => `| \`${title}\` | ${level} | ${count} |`).join("\n");
}
__name(getRowsByLevel, "getRowsByLevel");
function getSummary(toolName, annotations, coverageInfo, licensesInfo, reportUrl, prMode) {
function getSummary(toolName, annotations, coverageInfo, packages, licensesInfo, reportUrl, prMode) {
const contactBlock = wrapToToggleBlock("Contact Qodana team", SUMMARY_MISC);
let licensesBlock = "";
if (licensesInfo !== "") {
licensesBlock = wrapToToggleBlock("Dependencies licenses", licensesInfo);
licensesBlock = wrapToToggleBlock(`Detected ${packages} ${getDepencencyPlural(packages)}`, licensesInfo);
}
let prModeBlock = "";
if (prMode) {
Expand Down Expand Up @@ -126066,6 +126068,11 @@ ${body}
}
__name(getProblemPlural, "getProblemPlural");
exports2.getProblemPlural = getProblemPlural;
function getDepencencyPlural(count) {
return `dependenc${count !== 1 ? "ies" : "y"}`;
}
__name(getDepencencyPlural, "getDepencencyPlural");
exports2.getDepencencyPlural = getDepencencyPlural;
function prFixesBody(jobUrl) {
return ` \u{1F590} Hey there!

Expand Down
19 changes: 18 additions & 1 deletion scan/src/output.ts
Expand Up @@ -138,12 +138,14 @@ export async function publishOutput(
COVERAGE_THRESHOLD
)
let licensesInfo = ''
let packages = 0
const licensesJson = `${resultsDir}/projectStructure/${QODANA_LICENSES_JSON}`
if (fs.existsSync(licensesJson)) {
const licenses = JSON.parse(
fs.readFileSync(licensesJson, {encoding: 'utf8'})
)
if (licenses.length > 0) {
packages = licenses.length
licensesInfo = fs.readFileSync(
`${resultsDir}/projectStructure/${QODANA_LICENSES_MD}`,
{encoding: 'utf8'}
Expand All @@ -157,6 +159,7 @@ export async function publishOutput(
toolName,
annotations,
coverageInfo,
packages,
licensesInfo,
reportUrl,
isPrMode
Expand Down Expand Up @@ -222,6 +225,7 @@ function getRowsByLevel(annotations: Annotation[], level: string): string {
* @param toolName The name of the tool to generate the summary from.
* @param annotations The annotations to generate the summary from.
* @param coverageInfo The coverage is a Markdown text to generate the summary from.
* @param packages The number of dependencies in the analyzed project.
* @param licensesInfo The licenses a Markdown text to generate the summary from.
* @param reportUrl The URL to the Qodana report.
* @param prMode Whether the analysis was run in the pull request mode.
Expand All @@ -230,14 +234,18 @@ export function getSummary(
toolName: string,
annotations: Annotation[],
coverageInfo: string,
packages: number,
licensesInfo: string,
reportUrl: string,
prMode: boolean
): string {
const contactBlock = wrapToToggleBlock('Contact Qodana team', SUMMARY_MISC)
let licensesBlock = ''
if (licensesInfo !== '') {
licensesBlock = wrapToToggleBlock('Dependencies licenses', licensesInfo)
licensesBlock = wrapToToggleBlock(
`Detected ${packages} ${getDepencencyPlural(packages)}`,
licensesInfo
)
}
let prModeBlock = ''
if (prMode) {
Expand Down Expand Up @@ -308,6 +316,15 @@ export function getProblemPlural(count: number): string {
return `new problem${count !== 1 ? 's' : ''}`
}

/**
* Generates a plural form of the word "dependency" depending on the given count.
* @param count A number representing the count of dependencies
* @returns A formatted string with the correct plural form of "dependency"
*/
export function getDepencencyPlural(count: number): string {
return `dependenc${count !== 1 ? 'ies' : 'y'}`
}

/*
* The pull request with quick-fixes body template.
*/
Expand Down
2 changes: 1 addition & 1 deletion vsts/QodanaScan/index.js
Expand Up @@ -223,7 +223,7 @@ var init_qodana = __esm({
QODANA_REPORT_URL_NAME = "qodana.cloud";
QODANA_OPEN_IN_IDE_NAME = "open-in-ide.json";
QODANA_LICENSES_MD = "thirdPartySoftwareList.md";
QODANA_LICENSES_JSON = "thirdPartySoftwareList.json";
QODANA_LICENSES_JSON = "third-party-libraries.json";
EXECUTABLE = "qodana";
VERSION = version;
COVERAGE_THRESHOLD = 50;
Expand Down

0 comments on commit 5faa8fe

Please sign in to comment.