Preview contribution policy comments

This commit is contained in:
Gregory Schier
2026-06-30 13:54:45 -07:00
parent ff0d8c03b0
commit 5f14d90ccd
+35 -10
View File
@@ -78,19 +78,30 @@ function hasMeaningfulText(value) {
return stripComments(value || "").length > 0; return stripComments(value || "").length > 0;
} }
function checkboxState(body, label) { function normalizeCheckboxLabel(label) {
const flexibleLabel = escapeRegExp(label).replace(/\\ /g, "\\s+"); return label
const pattern = new RegExp( .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
`^\\s*[-*]\\s*\\[([ xX])\\]\\s*${flexibleLabel}\\s*$`, .replace(/`/g, "")
"im", .replace(/\s+/g, " ")
); .trim();
const match = body.match(pattern); }
if (match == null) { function checkboxState(body, label) {
return null; const expectedLabel = normalizeCheckboxLabel(label);
for (const line of body.split("\n")) {
const match = line.match(/^\s*[-*]\s*\[([ xX])\]\s*(.*?)\s*$/i);
if (match == null) {
continue;
}
if (normalizeCheckboxLabel(match[2]) === expectedLabel) {
return match[1].toLowerCase() === "x";
}
} }
return match[1].toLowerCase() === "x"; return null;
} }
function findFeedbackUrl(body) { function findFeedbackUrl(body) {
@@ -252,9 +263,18 @@ function truncateTitle(title) {
return `${title.slice(0, SUMMARY_TITLE_MAX_LENGTH - 3).trimEnd()}...`; return `${title.slice(0, SUMMARY_TITLE_MAX_LENGTH - 3).trimEnd()}...`;
} }
function escapeTableText(value) {
return escapeHtml(value).replace(/\n/g, "<br>");
}
function summarizeResult({ pr, analysis, skipped, skipReason }) { function summarizeResult({ pr, analysis, skipped, skipReason }) {
const comment =
analysis?.blockers.length > 0
? buildBlockingComment(analysis).replace(COMMENT_MARKER, "").trim()
: "None";
const summary = { const summary = {
blocked: analysis?.blockers.length > 0, blocked: analysis?.blockers.length > 0,
comment,
details: "None", details: "None",
labels: labels:
analysis?.desiredLabels.length > 0 analysis?.desiredLabels.length > 0
@@ -270,6 +290,7 @@ function summarizeResult({ pr, analysis, skipped, skipReason }) {
return { return {
...summary, ...summary,
blocked: false, blocked: false,
comment: "None",
details: escapeHtml(skipReason), details: escapeHtml(skipReason),
labels: "None", labels: "None",
status: "Skipped", status: "Skipped",
@@ -279,6 +300,7 @@ function summarizeResult({ pr, analysis, skipped, skipReason }) {
if (summary.blocked) { if (summary.blocked) {
return { return {
...summary, ...summary,
comment: escapeTableText(summary.comment),
details: escapeHtml( details: escapeHtml(
analysis.blockers.map((blocker) => blocker.message).join("; "), analysis.blockers.map((blocker) => blocker.message).join("; "),
), ),
@@ -289,6 +311,7 @@ function summarizeResult({ pr, analysis, skipped, skipReason }) {
return { return {
...summary, ...summary,
comment: "None",
labels: escapeHtml(summary.labels), labels: escapeHtml(summary.labels),
}; };
} }
@@ -584,6 +607,7 @@ async function run({ github, context, core }) {
{ data: "Status", header: true }, { data: "Status", header: true },
{ data: "Labels", header: true }, { data: "Labels", header: true },
{ data: "Details", header: true }, { data: "Details", header: true },
{ data: "Comment", header: true },
], ],
...results.map((result) => [ ...results.map((result) => [
result.summary.prLink, result.summary.prLink,
@@ -591,6 +615,7 @@ async function run({ github, context, core }) {
result.summary.status, result.summary.status,
result.summary.labels, result.summary.labels,
result.summary.details, result.summary.details,
result.summary.comment,
]), ]),
]) ])
.write(); .write();