Skip to content

Commit

Permalink
feat(utils): use auto-link commit format (GitHub/GitLab) in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Mar 25, 2024
1 parent ce36a30 commit 2f26c6c
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 21 deletions.
5 changes: 1 addition & 4 deletions e2e/cli-e2e/tests/compare.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ describe('CLI compare', () => {
'tmp/e2e/react-todos-app/report-diff.md',
);
// commits are variable, replace SHAs with placeholders
const sanitizedMd = reportsDiffMd.replace(
/(?<=commit )`[\da-f]{7}`/g,
'`<commit-sha>`',
);
const sanitizedMd = reportsDiffMd.replace(/[\da-f]{40}/g, '`<commit-sha>`');
await expect(sanitizedMd).toMatchFileSnapshot(
'__snapshots__/compare.report-diff.md',
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code PushUp

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

## 🏷️ Categories

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code PushUp

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

## 🏷️ Categories

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code PushUp

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

## 🛡️ Audits

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code PushUp

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

## 🏷️ Categories

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code PushUp

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

## 🏷️ Categories

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Report was created by [Code PushUp](https://github.com/flowup/quality-metrics-cl

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

The following plugins were run:

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/lib/reports/__snapshots__/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ Report was created by [Code PushUp](https://github.com/flowup/quality-metrics-cl

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

The following plugins were run:

Expand Down
4 changes: 1 addition & 3 deletions packages/utils/src/lib/reports/generate-md-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ function reportToAboutSection(report: ScoredReport): string {
const date = formatDate(new Date());

const { duration, version, commit, plugins, categories } = report;
const commitInfo = commit
? `${commit.message} (${commit.hash.slice(0, 7)})`
: 'N/A';
const commitInfo = commit ? `${commit.message} (${commit.hash})` : 'N/A';
const reportMetaTable: string[][] = [
reportMetaTableHeaders,
[
Expand Down
10 changes: 3 additions & 7 deletions packages/utils/src/lib/reports/generate-md-reports-diff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuditDiff, Commit, ReportsDiff } from '@code-pushup/models';
import { AuditDiff, ReportsDiff } from '@code-pushup/models';
import { pluralize, pluralizeToken } from '../formatting';
import { objectToEntries } from '../transform';
import { Alignment, details, h1, h2, paragraphs, style, tableMd } from './md';
Expand Down Expand Up @@ -40,12 +40,8 @@ function formatDiffHeaderSection(diff: ReportsDiff): string {
]),
);

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

return paragraphs(
h1('Code PushUp'),
Expand Down

0 comments on commit 2f26c6c

Please sign in to comment.