Skip to content

Commit 260692e

Browse files
committed
feat(utils): move project status from heading to paragraph in report-diff.md
1 parent fcbb09f commit 260692e

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-with-portal.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
🥳 Code PushUp report has **improved** – compared target commit 0123456789abcdef0123456789abcdef01234567 with source commit abcdef0123456789abcdef0123456789abcdef01.
44

5-
## 💼 Project `frontoffice` – improved 🥳
5+
## 💼 Project `frontoffice`
6+
7+
🥳 Code PushUp report has **improved**.
68

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

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

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

5-
## 💼 Project `console` – improved 🥳
5+
## 💼 Project `console`
6+
7+
🥳 Code PushUp report has **improved**.
68

79
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
810
| :------------------------------------------------------------------------ | :--------------: | :-------------: | :------------------------------------------------------------: |
@@ -41,7 +43,9 @@
4143

4244
</details>
4345

44-
## 💼 Project `admin` – mixed 🤨
46+
## 💼 Project `admin`
47+
48+
🤨 Code PushUp report has both **improvements and regressions**.
4549

4650
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
4751
| :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: |
@@ -74,7 +78,9 @@
7478

7579
</details>
7680

77-
## 💼 Project `docs` – regressed 😟
81+
## 💼 Project `docs`
82+
83+
😟 Code PushUp report has **regressed**.
7884

7985
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
8086
| :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: |

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

+21
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ function countDiffOutcomes(
152152
};
153153
}
154154

155+
export function formatReportOutcome(
156+
outcome: DiffOutcome,
157+
commits?: ReportsDiff['commits'],
158+
): InlineText {
159+
const outcomeTexts = {
160+
positive: md`🥳 Code PushUp report has ${md.bold('improved')}`,
161+
negative: md`😟 Code PushUp report has ${md.bold('regressed')}`,
162+
mixed: md`🤨 Code PushUp report has both ${md.bold(
163+
'improvements and regressions',
164+
)}`,
165+
unchanged: md`😐 Code PushUp report is ${md.bold('unchanged')}`,
166+
};
167+
168+
if (commits) {
169+
const commitsText = `compared target commit ${commits.after.hash} with source commit ${commits.before.hash}`;
170+
return md`${outcomeTexts[outcome]}${commitsText}.`;
171+
}
172+
173+
return md`${outcomeTexts[outcome]}.`;
174+
}
175+
155176
export function compareDiffsBy<T extends 'categories' | 'groups' | 'audits'>(
156177
type: T,
157178
a: ReportsDiff,

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

+6-30
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
compareDiffsBy,
1414
createGroupsOrAuditsDetails,
1515
formatPortalLink,
16+
formatReportOutcome,
1617
formatTitle,
1718
getDiffChanges,
1819
mergeDiffOutcomes,
@@ -94,49 +95,24 @@ function createDiffHeaderSection(
9495
diff: ReportsDiff | ReportsDiff[],
9596
portalUrl?: string,
9697
): MarkdownDocument {
97-
const outcomeTexts = {
98-
positive: md`🥳 Code PushUp report has ${md.bold('improved')}`,
99-
negative: md`😟 Code PushUp report has ${md.bold('regressed')}`,
100-
mixed: md`🤨 Code PushUp report has both ${md.bold(
101-
'improvements and regressions',
102-
)}`,
103-
unchanged: md`😐 Code PushUp report is ${md.bold('unchanged')}`,
104-
};
10598
const outcome = mergeDiffOutcomes(
10699
changesToDiffOutcomes(toArray(diff).flatMap(getDiffChanges)),
107100
);
108-
109-
const commits = Array.isArray(diff) ? diff[0]?.commits : diff.commits; // TODO: what if array contains different commit pairs?
110-
const commitsText =
111-
commits &&
112-
`compared target commit ${commits.after.hash} with source commit ${commits.before.hash}`;
101+
// TODO: what if array contains different commit pairs?
102+
const commits = Array.isArray(diff) ? diff[0]?.commits : diff.commits;
113103

114104
return new MarkdownDocument()
115105
.heading(HIERARCHY.level_1, 'Code PushUp')
116-
.paragraph(
117-
commitsText
118-
? md`${outcomeTexts[outcome]}${commitsText}.`
119-
: outcomeTexts[outcome],
120-
)
106+
.paragraph(formatReportOutcome(outcome, commits))
121107
.paragraph(formatPortalLink(portalUrl));
122108
}
123109

124110
function createDiffProjectSection(
125111
project: ProjectDiffWithOutcome,
126112
): MarkdownDocument {
127-
const outcomeTexts = {
128-
positive: 'improved 🥳',
129-
negative: 'regressed 😟',
130-
mixed: 'mixed 🤨',
131-
unchanged: 'unchanged 😐',
132-
};
133-
const outcomeText = outcomeTexts[project.outcome];
134-
135113
return new MarkdownDocument()
136-
.heading(
137-
HIERARCHY.level_2,
138-
md`💼 Project ${md.code(project.name)}${outcomeText}`,
139-
)
114+
.heading(HIERARCHY.level_2, md`💼 Project ${md.code(project.name)}`)
115+
.paragraph(formatReportOutcome(project.outcome))
140116
.paragraph(formatPortalLink(project.portalUrl))
141117
.$concat(
142118
createDiffCategoriesSection(project.diff, {

0 commit comments

Comments
 (0)