Skip to content

Commit 04455ae

Browse files
committed
feat(utils): include optional link to portal in markdown comment
1 parent 9388b49 commit 04455ae

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Code PushUp
2+
3+
🤨 Code PushUp report has both **improvements and regressions** – compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01.
4+
5+
[🕵️ See full comparison in Code PushUp portal 🔍](https://app.code-pushup.dev/portal/dunder-mifflin/website/comparison/abcdef0123456789abcdef0123456789abcdef01/0123456789abcdef0123456789abcdef01234567)
6+
7+
## 🏷️ Categories
8+
9+
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
10+
| :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: |
11+
| Bug prevention | 🟡 68 | 🟡 **63** | ![↓ −5](https://img.shields.io/badge/%E2%86%93%20%E2%88%925-red) |
12+
| Performance | 🟢 92 | 🟢 **94** | ![↑ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green) |
13+
| Code style | 🟡 54 | 🟡 **54** ||
14+
15+
## 🗃️ Groups
16+
17+
<details>
18+
<summary>👍 <strong>1</strong> group improved</summary>
19+
20+
| 🔌 Plugin | 🗃️ Group | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
21+
| :--------- | :---------- | :--------------: | :-------------: | :----------------------------------------------------------: |
22+
| Lighthouse | Performance | 🟢 92 | 🟢 **94** | ![↑ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green) |
23+
24+
1 other group is unchanged.
25+
26+
</details>
27+
28+
## 🛡️ Audits
29+
30+
<details>
31+
<summary>👍 <strong>3</strong> audits improved, 👎 <strong>1</strong> audit regressed</summary>
32+
33+
| 🔌 Plugin | 🛡️ Audit | 📏 Previous value | 📏 Current value | 🔄 Value change |
34+
| :----------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------- | :---------------: | :--------------: | :------------------------------------------------------------------------------: |
35+
| [ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin) | [Disallow unused variables](https://eslint.org/docs/latest/rules/no-unused-vars) | 🟩 passed | 🟥 **1 error** | ![↑ +∞ %](https://img.shields.io/badge/%E2%86%91%20%2B%E2%88%9E%E2%80%89%25-red) |
36+
| Lighthouse | [Largest Contentful Paint](https://developer.chrome.com/docs/lighthouse/performance/largest-contentful-paint/) | 🟨 1.5 s | 🟨 **1.4 s** | ![↓ −8 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%928%E2%80%89%25-green) |
37+
| Lighthouse | [First Contentful Paint](https://developer.chrome.com/docs/lighthouse/performance/first-contentful-paint/) | 🟨 1.2 s | 🟨 **1.1 s** | ![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green) |
38+
| Lighthouse | [Speed Index](https://developer.chrome.com/docs/lighthouse/performance/speed-index/) | 🟩 1.2 s | 🟩 **1.1 s** | ![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green) |
39+
40+
48 other audits are unchanged.
41+
42+
</details>

packages/utils/src/lib/reports/generate-md-reports-diff.integration.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,17 @@ describe('generateMdReportsDiff', () => {
5858
generateMdReportsDiff(reportsDiffAddedPluginMock()),
5959
).toMatchFileSnapshot('__snapshots__/report-diff-added.md');
6060
});
61+
62+
it('should format Markdown comment with link to portal', async () => {
63+
const report = reportsDiffAltMock();
64+
const shas = [
65+
report.commits!.before.hash,
66+
report.commits!.after.hash,
67+
] as const;
68+
const portalUrl = `https://app.code-pushup.dev/portal/dunder-mifflin/website/comparison/${shas[0]}/${shas[1]}`;
69+
70+
await expect(generateMdReportsDiff(report, portalUrl)).toMatchFileSnapshot(
71+
'__snapshots__/report-diff-with-portal-link.md',
72+
);
73+
});
6174
});

packages/utils/src/lib/reports/generate-md-reports-diff.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@ import {
2121
// to prevent exceeding Markdown comment character limit
2222
const MAX_ROWS = 100;
2323

24-
export function generateMdReportsDiff(diff: ReportsDiff): string {
24+
export function generateMdReportsDiff(
25+
diff: ReportsDiff,
26+
portalUrl?: string,
27+
): string {
2528
return new MarkdownDocument()
2629
.$concat(
27-
createDiffHeaderSection(diff),
30+
createDiffHeaderSection(diff, portalUrl),
2831
createDiffCategoriesSection(diff),
2932
createDiffGroupsSection(diff),
3033
createDiffAuditsSection(diff),
3134
)
3235
.toString();
3336
}
3437

35-
function createDiffHeaderSection(diff: ReportsDiff): MarkdownDocument {
38+
function createDiffHeaderSection(
39+
diff: ReportsDiff,
40+
portalUrl: string | undefined,
41+
): MarkdownDocument {
3642
const outcomeTexts = {
3743
positive: md`🥳 Code PushUp report has ${md.bold('improved')}`,
3844
negative: md`😟 Code PushUp report has ${md.bold('regressed')}`,
@@ -58,6 +64,10 @@ function createDiffHeaderSection(diff: ReportsDiff): MarkdownDocument {
5864
diff.commits
5965
? md`${outcomeTexts[outcome]}${styleCommits(diff.commits)}.`
6066
: outcomeTexts[outcome],
67+
)
68+
.paragraph(
69+
portalUrl &&
70+
md.link(portalUrl, '🕵️ See full comparison in Code PushUp portal 🔍'),
6171
);
6272
}
6373

0 commit comments

Comments
 (0)