Skip to content

Commit

Permalink
feat(utils): skip unchanged categories and projects in report-diff.md
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Aug 16, 2024
1 parent 3cf7b11 commit c834cfa
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@

</details>

## 💼 Project `backoffice` – unchanged 😐
---

[🕵️ See full comparison in Code PushUp portal 🔍](https://app.code-pushup.dev/portal/dunder-mifflin/backoffice/comparison/abcdef0123456789abcdef0123456789abcdef01/0123456789abcdef0123456789abcdef01234567)

| 🏷️ Category | ⭐ Score |
| :------------- | :-----: |
| Performance | 🟢 92 |
| Bug prevention | 🟡 68 |
| Code style | 🟡 54 |
1 other project is unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
| :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: |
| Bug prevention | 🟡 68 | 🟡 **63** | ![↓ −5](https://img.shields.io/badge/%E2%86%93%20%E2%88%925-red) |
| Performance | 🟢 92 | 🟢 **94** | ![↑ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green) |
| Code style | 🟡 54 | 🟡 **54** ||

1 other category is unchanged.

<details>
<summary>👍 <strong>1</strong> group improved, 👍 <strong>3</strong> audits improved, 👎 <strong>1</strong> audit regressed</summary>
Expand All @@ -73,24 +74,17 @@

</details>

## 💼 Project `marketing` – unchanged 😐

| 🏷️ Category | ⭐ Score |
| :------------- | :-----: |
| Performance | 🟢 92 |
| Bug prevention | 🟡 68 |
| Code style | 🟡 54 |

## 💼 Project `docs` – regressed 😟

| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
| :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: |
| Bug prevention | 🟡 68 | 🟡 **63** | ![↓ −5](https://img.shields.io/badge/%E2%86%93%20%E2%88%925-red) |
| Performance | _n/a (\*)_ | 🟢 **94** | _n/a (\*)_ |
| Code style | 🟡 54 | 🟡 **54** ||

_(\*) New category._

1 other category is unchanged.

<details>
<summary>👎 <strong>1</strong> audit regressed</summary>

Expand All @@ -107,3 +101,7 @@ All of 1 group is unchanged.
49 other audits are unchanged.

</details>

---

1 other project is unchanged.
70 changes: 52 additions & 18 deletions packages/utils/src/lib/reports/generate-md-reports-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,38 @@ export type ProjectDiff = {
diff: ReportsDiff;
};

export type ProjectDiffWithOutcome = ProjectDiff & {
outcome: DiffOutcome;
};

export function generateMdReportsDiffForMonorepo(
projects: ProjectDiff[],
): string {
// TODO: sort projects (most changed, alphabetical)
// TODO: abbreviate or filter out unchanged projects?
const projectsWithOutcomes = projects.map(
(project): ProjectDiffWithOutcome => ({
...project,
outcome: mergeDiffOutcomes(
changesToDiffOutcomes(getDiffChanges(project.diff)),
),
}),
);
const unchanged = projectsWithOutcomes.filter(
({ outcome }) => outcome === 'unchanged',
);
const changed = projectsWithOutcomes.filter(
project => !unchanged.includes(project),
);

return new MarkdownDocument()
.$concat(
createDiffHeaderSection(projects.map(({ diff }) => diff)),
...projects.map(createDiffProjectSection),
...changed.map(createDiffProjectSection),
)
.$if(unchanged.length > 0, doc =>
doc
.rule()
.paragraph(summarizeUnchanged('project', { unchanged, changed })),
)
.toString();
}
Expand Down Expand Up @@ -84,34 +107,38 @@ function createDiffHeaderSection(
.paragraph(formatPortalLink(portalUrl));
}

function createDiffProjectSection(project: ProjectDiff): MarkdownDocument {
function createDiffProjectSection(
project: ProjectDiffWithOutcome,
): MarkdownDocument {
const outcomeTexts = {
positive: 'improved 🥳',
negative: 'regressed 😟',
mixed: 'mixed 🤨',
unchanged: 'unchanged 😐',
};
const outcome = mergeDiffOutcomes(
changesToDiffOutcomes(getDiffChanges(project.diff)),
);
const outcomeText = outcomeTexts[project.outcome];

return new MarkdownDocument()
.heading(
HIERARCHY.level_2,
md`💼 Project ${md.code(project.name)}${outcomeTexts[outcome]}`,
md`💼 Project ${md.code(project.name)}${outcomeText}`,
)
.paragraph(formatPortalLink(project.portalUrl))
.$concat(
createDiffCategoriesSection(project.diff, { skipHeading: true }),
createDiffCategoriesSection(project.diff, {
skipHeading: true,
skipUnchanged: true,
}),
createDiffDetailsSection(project.diff, HIERARCHY.level_3),
);
}

function createDiffCategoriesSection(
diff: ReportsDiff,
options: { skipHeading: boolean } = { skipHeading: false },
options?: { skipHeading?: boolean; skipUnchanged?: boolean },
): MarkdownDocument | null {
const { changed, unchanged, added } = diff.categories;
const { skipHeading, skipUnchanged } = options ?? {};

const categoriesCount = changed.length + unchanged.length + added.length;
const hasChanges = unchanged.length < categoriesCount;
Expand Down Expand Up @@ -145,21 +172,28 @@ function createDiffCategoriesSection(
formatScoreWithColor(category.score),
md.italic('n/a (\\*)'),
]),
...unchanged.map(category => [
formatTitle(category),
formatScoreWithColor(category.score, { skipBold: true }),
formatScoreWithColor(category.score),
'–',
]),
...(skipUnchanged
? []
: unchanged.map(category => [
formatTitle(category),
formatScoreWithColor(category.score, { skipBold: true }),
formatScoreWithColor(category.score),
'–',
])),
];

return new MarkdownDocument()
.heading(HIERARCHY.level_2, !options.skipHeading && '🏷️ Categories')
.heading(HIERARCHY.level_2, !skipHeading && '🏷️ Categories')
.table(
hasChanges ? columns : columns.slice(0, 2),
rows.map(row => (hasChanges ? row : row.slice(0, 2))),
)
.paragraph(added.length > 0 && md.italic('(\\*) New category.'));
.paragraph(added.length > 0 && md.italic('(\\*) New category.'))
.paragraph(
skipUnchanged &&
unchanged.length > 0 &&
summarizeUnchanged('category', { changed, unchanged }),
);
}

function createDiffDetailsSection(
Expand Down Expand Up @@ -270,7 +304,7 @@ function createGroupsOrAuditsDetails<T extends 'group' | 'audit'>(
}

function summarizeUnchanged(
token: 'category' | 'group' | 'audit',
token: string,
{ changed, unchanged }: { changed: unknown[]; unchanged: unknown[] },
): string {
return [
Expand Down

0 comments on commit c834cfa

Please sign in to comment.