Skip to content

Commit 2af1d9e

Browse files
committed
fix(pr-comment): improve PR comment rendering
Fixes: - Remove 'No contracts configured' message when lint passes - Decode JSON Pointers for readable paths (/v1/media instead of ~1v1~1media) - Add paths to patch changes (were missing) - Improve changeset section with clearer messaging and status icons - Change path display from backticks to parentheses for cleaner look Before: - New path added: /v1/media `/paths/~1v1~1media` After: - New path added: /v1/media (/paths/v1/media)
1 parent 9b1225e commit 2af1d9e

3 files changed

Lines changed: 37 additions & 21 deletions

File tree

dist/index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83159,6 +83159,11 @@ async function pushWithRetry(maxAttempts) {
8315983159
__name(pushWithRetry, "pushWithRetry");
8316083160

8316183161
// src/render/pr-comment.ts
83162+
function decodeJsonPointer2(pointer) {
83163+
if (!pointer) return "";
83164+
return pointer.replace(/~1/g, "/").replace(/~0/g, "~");
83165+
}
83166+
__name(decodeJsonPointer2, "decodeJsonPointer");
8316283167
function renderPRComment(data) {
8316383168
const sections = [];
8316483169
sections.push("## Contract Check Results\n");
@@ -83179,9 +83184,6 @@ function renderLintSection(results) {
8317983184
const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
8318083185
const totalWarnings = results.reduce((sum, r) => sum + r.warnings.length, 0);
8318183186
if (totalErrors === 0 && totalWarnings === 0) {
83182-
if (results.length === 0) {
83183-
return "### Lint\n\nNo contracts configured.\n";
83184-
}
8318583187
return "### Lint\n\nAll contracts pass validation.\n";
8318683188
}
8318783189
let md = `### ${totalErrors > 0 ? "Lint" : "Lint"}
@@ -83237,31 +83239,35 @@ function renderDiffSection(results) {
8323783239
if (breaking.length > 0) {
8323883240
md += "**Breaking Changes:**\n";
8323983241
for (const c of breaking) {
83240-
md += `- ${c.message} \`${c.path}\`
83242+
const path4 = c.path ? ` (${decodeJsonPointer2(c.path)})` : "";
83243+
md += `- ${c.message}${path4}
8324183244
`;
8324283245
}
8324383246
md += "\n";
8324483247
}
8324583248
if (nonBreaking.length > 0) {
8324683249
md += "**Non-breaking Changes:**\n";
8324783250
for (const c of nonBreaking) {
83248-
md += `- ${c.message} \`${c.path}\`
83251+
const path4 = c.path ? ` (${decodeJsonPointer2(c.path)})` : "";
83252+
md += `- ${c.message}${path4}
8324983253
`;
8325083254
}
8325183255
md += "\n";
8325283256
}
8325383257
if (patch.length > 0) {
8325483258
md += "**Patch Changes:**\n";
8325583259
for (const c of patch) {
83256-
md += `- ${c.message}
83260+
const path4 = c.path ? ` (${decodeJsonPointer2(c.path)})` : "";
83261+
md += `- ${c.message}${path4}
8325783262
`;
8325883263
}
8325983264
md += "\n";
8326083265
}
8326183266
if (unknown.length > 0) {
8326283267
md += "**Needs Review:**\n";
8326383268
for (const c of unknown) {
83264-
md += `- ${c.message} \`${c.path}\`
83269+
const path4 = c.path ? ` (${decodeJsonPointer2(c.path)})` : "";
83270+
md += `- ${c.message}${path4}
8326583271
`;
8326683272
}
8326783273
md += "\n";
@@ -83273,12 +83279,12 @@ function renderDiffSection(results) {
8327383279
__name(renderDiffSection, "renderDiffSection");
8327483280
function renderChangesetSection(hasChangeset, created) {
8327583281
if (created) {
83276-
return "### Changeset\n\nA changeset was automatically generated and committed to this PR. Review it and edit if needed.\n";
83282+
return "### Changeset\n\n\u2705 A changeset was automatically generated and committed to this PR.\n\nReview the changeset file in `.contractual/changesets/` and edit if needed before merging.\n";
8327783283
}
8327883284
if (hasChangeset) {
83279-
return "### Changeset\n\nChangeset found in this PR.\n";
83285+
return "### Changeset\n\n\u2705 Changeset found in this PR.\n\nThe changeset will be consumed when this PR is merged, and a Version PR will be created automatically.\n";
8328083286
}
83281-
return "### Changeset\n\nNo changeset found. If this PR changes contracts, a changeset will be auto-generated on the next push.\n";
83287+
return "### Changeset\n\n\u26A0\uFE0F No changeset found.\n\nIf this PR changes contracts, a changeset will be auto-generated on the next push.\n";
8328283288
}
8328383289
__name(renderChangesetSection, "renderChangesetSection");
8328483290
function renderAISection(explanation) {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/render/pr-comment.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import type { LintResult, DiffResult, Change } from '@contractual/cli';
22
import type { PRCommentData } from '../types.js';
33

4+
/**
5+
* Decode JSON Pointer to readable path
6+
* Converts ~1 to / and ~0 to ~
7+
*/
8+
function decodeJsonPointer(pointer: string): string {
9+
if (!pointer) return '';
10+
return pointer.replace(/~1/g, '/').replace(/~0/g, '~');
11+
}
12+
413
/**
514
* Render the full PR comment from lint and diff results.
615
*/
@@ -38,9 +47,6 @@ function renderLintSection(results: LintResult[]): string {
3847
const totalWarnings = results.reduce((sum, r) => sum + r.warnings.length, 0);
3948

4049
if (totalErrors === 0 && totalWarnings === 0) {
41-
if (results.length === 0) {
42-
return '### Lint\n\nNo contracts configured.\n';
43-
}
4450
return '### Lint\n\nAll contracts pass validation.\n';
4551
}
4652

@@ -107,28 +113,32 @@ function renderDiffSection(results: DiffResult[]): string {
107113
if (breaking.length > 0) {
108114
md += '**Breaking Changes:**\n';
109115
for (const c of breaking) {
110-
md += `- ${c.message} \`${c.path}\`\n`;
116+
const path = c.path ? ` (${decodeJsonPointer(c.path)})` : '';
117+
md += `- ${c.message}${path}\n`;
111118
}
112119
md += '\n';
113120
}
114121
if (nonBreaking.length > 0) {
115122
md += '**Non-breaking Changes:**\n';
116123
for (const c of nonBreaking) {
117-
md += `- ${c.message} \`${c.path}\`\n`;
124+
const path = c.path ? ` (${decodeJsonPointer(c.path)})` : '';
125+
md += `- ${c.message}${path}\n`;
118126
}
119127
md += '\n';
120128
}
121129
if (patch.length > 0) {
122130
md += '**Patch Changes:**\n';
123131
for (const c of patch) {
124-
md += `- ${c.message}\n`;
132+
const path = c.path ? ` (${decodeJsonPointer(c.path)})` : '';
133+
md += `- ${c.message}${path}\n`;
125134
}
126135
md += '\n';
127136
}
128137
if (unknown.length > 0) {
129138
md += '**Needs Review:**\n';
130139
for (const c of unknown) {
131-
md += `- ${c.message} \`${c.path}\`\n`;
140+
const path = c.path ? ` (${decodeJsonPointer(c.path)})` : '';
141+
md += `- ${c.message}${path}\n`;
132142
}
133143
md += '\n';
134144
}
@@ -144,12 +154,12 @@ function renderDiffSection(results: DiffResult[]): string {
144154
*/
145155
function renderChangesetSection(hasChangeset: boolean, created: boolean): string {
146156
if (created) {
147-
return '### Changeset\n\nA changeset was automatically generated and committed to this PR. Review it and edit if needed.\n';
157+
return '### Changeset\n\n✅ A changeset was automatically generated and committed to this PR.\n\nReview the changeset file in `.contractual/changesets/` and edit if needed before merging.\n';
148158
}
149159
if (hasChangeset) {
150-
return '### Changeset\n\nChangeset found in this PR.\n';
160+
return '### Changeset\n\n✅ Changeset found in this PR.\n\nThe changeset will be consumed when this PR is merged, and a Version PR will be created automatically.\n';
151161
}
152-
return '### Changeset\n\nNo changeset found. If this PR changes contracts, a changeset will be auto-generated on the next push.\n';
162+
return '### Changeset\n\n⚠️ No changeset found.\n\nIf this PR changes contracts, a changeset will be auto-generated on the next push.\n';
153163
}
154164

155165
/**

0 commit comments

Comments
 (0)