small refactoring

Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
Signed-off-by: web-next-automation <web-platform@doordash.com>
This commit is contained in:
aramissennyeydd
2024-03-02 18:44:06 -05:00
committed by web-next-automation
parent 9341347dc1
commit f4aebb8e88
2 changed files with 26 additions and 56 deletions
@@ -23,6 +23,12 @@ import {
import { paths as cliPaths } from '../../../../lib/paths';
import { YAML_SCHEMA_PATH } from '../../../../lib/openapi/constants';
function cleanUpApiName(e: { apiName: string }) {
e.apiName = e.apiName
.replace(cliPaths.targetDir, '')
.replace(YAML_SCHEMA_PATH, '');
}
export async function command(opts: OptionValues) {
let packages = await PackageGraph.listTargetPackages();
@@ -84,30 +90,10 @@ export async function command(opts: OptionValues) {
});
}
outputs.completed.forEach(
e =>
(e.apiName = e.apiName
.replace(cliPaths.targetDir, '')
.replace(YAML_SCHEMA_PATH, '')),
);
outputs.failed.forEach(
e =>
(e.apiName = e.apiName
.replace(cliPaths.targetDir, '')
.replace(YAML_SCHEMA_PATH, '')),
);
outputs.noop.forEach(
e =>
(e.apiName = e.apiName
.replace(cliPaths.targetDir, '')
.replace(YAML_SCHEMA_PATH, '')),
);
outputs.warning?.forEach(
e =>
(e.apiName = e.apiName
.replace(cliPaths.targetDir, '')
.replace(YAML_SCHEMA_PATH, '')),
);
outputs.completed.forEach(cleanUpApiName);
outputs.failed.forEach(cleanUpApiName);
outputs.noop.forEach(cleanUpApiName);
outputs.warning?.forEach(cleanUpApiName);
const { stdout: currentSha } = await exec('git', ['rev-parse', 'HEAD']);
console.log(
@@ -132,6 +132,14 @@ const getBreakagesRow = (breakage: CiRunDetails['completed'][number]) => {
)}`;
};
const addSummaryLine = (items: any[] | number | undefined, label: string) => {
const length = Array.isArray(items) ? items.length : items;
if (!length) return '';
let text = length === 1 ? `1 API` : `${length} APIs`;
text += ` had ${label}`;
return text;
};
export const generateCompareSummaryMarkdown = (
commit: { sha: string },
results: CiRunDetails,
@@ -161,38 +169,14 @@ export const generateCompareSummaryMarkdown = (
results.completed.length - breakages.length;
return `### Summary for commit (${commit.sha})
${
results.noop.length > 0
? `${
results.noop.length === 1 ? '1 API' : `${results.noop.length} APIs`
} had no changes.`
: ''
}
${
breakages.length > 0
? `${
breakages.length === 1 ? '1 API' : `${breakages.length} APIs`
} had breaking changes.`
: ''
}
${
successfullyCompletedCount > 0
? `${
successfullyCompletedCount === 1
? '1 API'
: `${successfullyCompletedCount} APIs`
} had non-breaking changes.`
: ''
}
${
results.warning && results.warning.length > 0
? `${
results.warning.length === 1
? '1 API'
: `${results.warning.length} APIs`
} had warnings.`
: ''
}
${addSummaryLine(results.noop, 'no changes')}
${addSummaryLine(breakages.length, 'breaking changes')}
${addSummaryLine(successfullyCompletedCount, 'non-breaking changes')}
${addSummaryLine(results.warning, 'warnings')}
${
results.completed.length > 0
? `### APIs with Changes