Skip to content

Commit 2f26c6c

Browse files
committed
feat(utils): use auto-link commit format (GitHub/GitLab) in markdown
1 parent ce36a30 commit 2f26c6c

10 files changed

+12
-21
lines changed

e2e/cli-e2e/tests/compare.e2e.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ describe('CLI compare', () => {
6868
'tmp/e2e/react-todos-app/report-diff.md',
6969
);
7070
// commits are variable, replace SHAs with placeholders
71-
const sanitizedMd = reportsDiffMd.replace(
72-
/(?<=commit )`[\da-f]{7}`/g,
73-
'`<commit-sha>`',
74-
);
71+
const sanitizedMd = reportsDiffMd.replace(/[\da-f]{40}/g, '`<commit-sha>`');
7572
await expect(sanitizedMd).toMatchFileSnapshot(
7673
'__snapshots__/compare.report-diff.md',
7774
);

packages/utils/src/lib/reports/__snapshots__/report-diff-added.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code PushUp
22

3-
😟 Code PushUp report has **regressed** – compared target commit `0123456` with source commit `abcdef0`.
3+
😟 Code PushUp report has **regressed** – compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01.
44

55
## 🏷️ Categories
66

packages/utils/src/lib/reports/__snapshots__/report-diff-improved.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code PushUp
22

3-
🥳 Code PushUp report has **improved** – compared target commit `0123456` with source commit `abcdef0`.
3+
🥳 Code PushUp report has **improved** – compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01.
44

55
## 🏷️ Categories
66

packages/utils/src/lib/reports/__snapshots__/report-diff-minimal.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code PushUp
22

3-
😟 Code PushUp report has **regressed** – compared target commit `0123456` with source commit `abcdef0`.
3+
😟 Code PushUp report has **regressed** – compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01.
44

55
## 🛡️ Audits
66

packages/utils/src/lib/reports/__snapshots__/report-diff-mixed.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code PushUp
22

3-
🤨 Code PushUp report has both **improvements and regressions** – compared target commit `0123456` with source commit `abcdef0`.
3+
🤨 Code PushUp report has both **improvements and regressions** – compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01.
44

55
## 🏷️ Categories
66

packages/utils/src/lib/reports/__snapshots__/report-diff-unchanged.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code PushUp
22

3-
😐 Code PushUp report is **unchanged** – compared target commit `0123456` with source commit `abcdef0`.
3+
😐 Code PushUp report is **unchanged** – compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01.
44

55
## 🏷️ Categories
66

packages/utils/src/lib/reports/__snapshots__/report-no-categories.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ Report was created by [Code PushUp](https://github.com/flowup/quality-metrics-cl
382382

383383
|Commit|Version|Duration|Plugins|Categories|Audits|
384384
|:--|:--:|:--:|:--:|:--:|:--:|
385-
|Minor fixes (abcdef0)|`0.0.1`|1.65 s|2|0|52|
385+
|Minor fixes (abcdef0123456789abcdef0123456789abcdef01)|`0.0.1`|1.65 s|2|0|52|
386386

387387
The following plugins were run:
388388

packages/utils/src/lib/reports/__snapshots__/report.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ Report was created by [Code PushUp](https://github.com/flowup/quality-metrics-cl
446446

447447
|Commit|Version|Duration|Plugins|Categories|Audits|
448448
|:--|:--:|:--:|:--:|:--:|:--:|
449-
|Minor fixes (abcdef0)|`0.0.1`|1.65 s|2|3|52|
449+
|Minor fixes (abcdef0123456789abcdef0123456789abcdef01)|`0.0.1`|1.65 s|2|3|52|
450450

451451
The following plugins were run:
452452

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ function reportToAboutSection(report: ScoredReport): string {
235235
const date = formatDate(new Date());
236236

237237
const { duration, version, commit, plugins, categories } = report;
238-
const commitInfo = commit
239-
? `${commit.message} (${commit.hash.slice(0, 7)})`
240-
: 'N/A';
238+
const commitInfo = commit ? `${commit.message} (${commit.hash})` : 'N/A';
241239
const reportMetaTable: string[][] = [
242240
reportMetaTableHeaders,
243241
[

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuditDiff, Commit, ReportsDiff } from '@code-pushup/models';
1+
import { AuditDiff, ReportsDiff } from '@code-pushup/models';
22
import { pluralize, pluralizeToken } from '../formatting';
33
import { objectToEntries } from '../transform';
44
import { Alignment, details, h1, h2, paragraphs, style, tableMd } from './md';
@@ -40,12 +40,8 @@ function formatDiffHeaderSection(diff: ReportsDiff): string {
4040
]),
4141
);
4242

43-
const styleCommit = (commit: Commit) => style(commit.hash.slice(0, 7), ['c']);
44-
const styleCommits = (commits: NonNullable<ReportsDiff['commits']>) => {
45-
const src = styleCommit(commits.before);
46-
const tgt = styleCommit(commits.after);
47-
return `compared target commit ${tgt} with source commit ${src}`;
48-
};
43+
const styleCommits = (commits: NonNullable<ReportsDiff['commits']>) =>
44+
`compared target commit ${commits.after.hash} with source commit ${commits.before.hash}`;
4945

5046
return paragraphs(
5147
h1('Code PushUp'),

0 commit comments

Comments
 (0)