pr-evidence 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/evidenceComment.js +54 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Your coding agent tests a branch in a real browser and posts each criterion it checked, with the screenshots that prove it, on its pull request.
|
|
4
4
|
|
|
5
|
-
[](https://github.com/debrine/pr-evidence-demo/pull/1)
|
|
6
6
|
|
|
7
7
|
This comment was posted from a real run on [a demo pull request](https://github.com/debrine/pr-evidence-demo/pull/1) that fixes a double-clicked Save adding a note twice.
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ This comment was posted from a real run on [a demo pull request](https://github.
|
|
|
15
15
|
|
|
16
16
|
<!-- TRANSCRIPT: replace with 10-15 lines trimmed from the showcase run -->
|
|
17
17
|
|
|
18
|
-
Each criterion gets its own section, with its note and
|
|
18
|
+
Each criterion gets its own numbered section, with its note and screenshot thumbnails. Passed criteria are collapsed. If a criterion fails, the comment says "Failed", marks that criterion "❌ Fail" and shows its section open. The tool only reports. It never changes the code under test.
|
|
19
19
|
|
|
20
20
|
## Quickstart
|
|
21
21
|
|
package/dist/evidenceComment.js
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
export const commentMarker = "<!-- pr-evidence -->";
|
|
2
2
|
const npmPackageUrl = "https://www.npmjs.com/package/pr-evidence";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Every screenshot shows at this height, so an open criterion fits on about one screen. GitHub turns
|
|
5
|
+
* a height with no width into a maximum height that keeps the aspect ratio, and links each image to
|
|
6
|
+
* its full size.
|
|
7
|
+
*/
|
|
8
|
+
const thumbnailHeight = 240;
|
|
9
|
+
/** Stops untrusted text being read as HTML. `&` goes first so the other entities stay intact. */
|
|
10
|
+
function escapeHtml(text) {
|
|
11
|
+
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Makes untrusted text safe for one line of Markdown, such as a heading or a `<summary>`. It uses
|
|
15
|
+
* no backslash escapes, because GitHub shows those literally inside `<summary>`.
|
|
16
|
+
*/
|
|
4
17
|
function escapeInline(text) {
|
|
5
|
-
return text
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.replace(/\s*\n\s*/g, " ");
|
|
18
|
+
return escapeHtml(text).replace(/\s*\n\s*/g, " ");
|
|
19
|
+
}
|
|
20
|
+
/** Makes untrusted text safe inside a double-quoted HTML attribute. */
|
|
21
|
+
function escapeAttribute(text) {
|
|
22
|
+
return escapeHtml(text).replaceAll('"', """);
|
|
11
23
|
}
|
|
12
24
|
/** Encodes a branch name as one URL path segment that is also safe in a Markdown link destination. */
|
|
13
25
|
function encodeBranchForLink(branch) {
|
|
14
26
|
return encodeURIComponent(branch).replaceAll("(", "%28").replaceAll(")", "%29");
|
|
15
27
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
28
|
+
function thumbnail(fileName, url) {
|
|
29
|
+
const source = escapeAttribute(url);
|
|
30
|
+
return `<img src="${source}" height="${thumbnailHeight}" alt="${escapeAttribute(fileName)}">`;
|
|
31
|
+
}
|
|
32
|
+
/** One line of thumbnails, so they sit side by side and wrap to the comment's width. */
|
|
33
|
+
function thumbnailRow(fileNames, screenshotUrls) {
|
|
34
|
+
return fileNames.map((fileName) => thumbnail(fileName, screenshotUrls.get(fileName))).join(" ");
|
|
18
35
|
}
|
|
19
36
|
function renderSummary(input) {
|
|
20
37
|
const { repository, record, outcome } = input;
|
|
21
38
|
const repositoryUrl = `https://${repository.host}/${repository.owner}/${repository.name}`;
|
|
39
|
+
const passedCount = outcome.criteria.filter((criterion) => criterion.result === "pass").length;
|
|
40
|
+
const failedCount = outcome.criteria.length - passedCount;
|
|
22
41
|
const lines = [
|
|
23
42
|
`## PR evidence: ${outcome.result === "pass" ? "Passed" : "Failed"}`,
|
|
24
43
|
"",
|
|
25
44
|
`- **Tested commit:** [${record.sha}](${repositoryUrl}/commit/${record.sha})`,
|
|
26
45
|
`- **Ticket:** ${outcome.ticket === null ? "No ticket" : escapeInline(outcome.ticket)}`,
|
|
46
|
+
`- **Criteria:** ${passedCount} passed, ${failedCount} failed`,
|
|
27
47
|
];
|
|
28
48
|
if (record.branch !== null) {
|
|
29
49
|
lines.push(`- **Later changes:** [compare with the branch](${repositoryUrl}/compare/${record.sha}...${encodeBranchForLink(record.branch)})`);
|
|
@@ -36,34 +56,25 @@ function renderSummary(input) {
|
|
|
36
56
|
}
|
|
37
57
|
return lines;
|
|
38
58
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return [
|
|
44
|
-
"",
|
|
45
|
-
"| Result | Criterion |",
|
|
46
|
-
"| --- | --- |",
|
|
47
|
-
...outcome.criteria.map((criterion) => `| ${resultLabel(criterion)} | ${escapeInline(criterion.description)} |`),
|
|
48
|
-
];
|
|
59
|
+
/** The number, icon and word together, so the result reads anywhere the emoji does not render. */
|
|
60
|
+
function criterionTitle(criterion, criterionNumber) {
|
|
61
|
+
const result = criterion.result === "pass" ? "✅ Pass" : "❌ Fail";
|
|
62
|
+
return `${criterionNumber}. ${result}: ${escapeInline(criterion.description)}`;
|
|
49
63
|
}
|
|
50
64
|
function renderProof(criterion, screenshotUrls) {
|
|
51
65
|
const note = criterion.note ? ["", escapeInline(criterion.note)] : [];
|
|
52
|
-
const
|
|
53
|
-
?
|
|
54
|
-
: criterion.screenshots
|
|
55
|
-
|
|
56
|
-
image(fileName, screenshotUrls.get(fileName)),
|
|
57
|
-
]);
|
|
58
|
-
return [...note, ...images];
|
|
66
|
+
const screenshots = criterion.screenshots.length === 0
|
|
67
|
+
? "No screenshots"
|
|
68
|
+
: thumbnailRow(criterion.screenshots, screenshotUrls);
|
|
69
|
+
return [...note, "", screenshots];
|
|
59
70
|
}
|
|
60
71
|
/** Failures are expanded so the proof to act on is visible; passes stay one click away. */
|
|
61
|
-
function renderCriterionSection(criterion, screenshotUrls) {
|
|
62
|
-
const title =
|
|
72
|
+
function renderCriterionSection(criterion, criterionNumber, screenshotUrls) {
|
|
73
|
+
const title = criterionTitle(criterion, criterionNumber);
|
|
63
74
|
const proof = renderProof(criterion, screenshotUrls);
|
|
64
75
|
return criterion.result === "fail"
|
|
65
|
-
? [
|
|
66
|
-
: ["
|
|
76
|
+
? [`### ${title}`, ...proof]
|
|
77
|
+
: ["<details>", `<summary>${title}</summary>`, ...proof, "", "</details>"];
|
|
67
78
|
}
|
|
68
79
|
/** Screenshots no criterion cites, such as setup steps, kept out of the way. */
|
|
69
80
|
function renderOtherScreenshots({ outcome, screenshotUrls }) {
|
|
@@ -73,14 +84,13 @@ function renderOtherScreenshots({ outcome, screenshotUrls }) {
|
|
|
73
84
|
return [];
|
|
74
85
|
}
|
|
75
86
|
return [
|
|
76
|
-
"",
|
|
77
87
|
"<details>",
|
|
78
88
|
`<summary>Other screenshots (${others.length})</summary>`,
|
|
79
89
|
...others.flatMap((fileName) => [
|
|
80
90
|
"",
|
|
81
91
|
`**${escapeInline(fileName)}**`,
|
|
82
92
|
"",
|
|
83
|
-
|
|
93
|
+
thumbnail(fileName, screenshotUrls.get(fileName)),
|
|
84
94
|
]),
|
|
85
95
|
"",
|
|
86
96
|
"</details>",
|
|
@@ -88,21 +98,23 @@ function renderOtherScreenshots({ outcome, screenshotUrls }) {
|
|
|
88
98
|
}
|
|
89
99
|
/** A small plug so reviewers who like the comment can find the tool. */
|
|
90
100
|
function renderFooter() {
|
|
91
|
-
return [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
return [`<sub>Want to try it yourself? Check out [pr-evidence on npm](${npmPackageUrl}).</sub>`];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Puts a rule between sections, so many criteria never blur together, and leaves out empty ones.
|
|
105
|
+
* The blank line before each rule stops it turning the line above into a heading.
|
|
106
|
+
*/
|
|
107
|
+
function joinWithRules(sections) {
|
|
108
|
+
return sections
|
|
109
|
+
.filter((section) => section.length > 0)
|
|
110
|
+
.flatMap((section, index) => [...(index === 0 ? [] : ["", "---"]), "", ...section]);
|
|
97
111
|
}
|
|
98
112
|
export function renderEvidenceComment(input) {
|
|
113
|
+
const criterionSections = input.outcome.criteria.map((criterion, index) => renderCriterionSection(criterion, index + 1, input.screenshotUrls));
|
|
99
114
|
return [
|
|
100
115
|
commentMarker,
|
|
101
116
|
...renderSummary(input),
|
|
102
|
-
...
|
|
103
|
-
...input.outcome.criteria.flatMap((criterion) => renderCriterionSection(criterion, input.screenshotUrls)),
|
|
104
|
-
...renderOtherScreenshots(input),
|
|
105
|
-
...renderFooter(),
|
|
117
|
+
...joinWithRules([...criterionSections, renderOtherScreenshots(input), renderFooter()]),
|
|
106
118
|
"",
|
|
107
119
|
].join("\n");
|
|
108
120
|
}
|