Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const blocked = {
gates: [
gate("approvals", "failed", "Needs 1 approval"),
gate("findings", "failed", "Unresolved findings: 1 without a severity"),
// CI is reported as its own runs; the gate that rolls them up is not shown again.
// CI runs replace a passing checks gate; a non-passing blocking gate is still reported.
gate("checks", "failed", "lint is failing"),
gate("up_to_date", "passed"),
gate("base_checks", "pending"),
Expand Down
26 changes: 26 additions & 0 deletions packages/source-control-entire/src/server/entireTrailBody.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@ describe("trailBodyMarkdown", () => {
expect(unrenderedContent({ text_snapshot: "Plain" })).toBeNull();
});

it.each(["inline", "fenced", "later paragraph"])(
"preserves literal self-link markers in %s content",
(kind) => {
const literal = "<!-- entire-trail-link-start --> example <!-- entire-trail-link-end -->";
const markdown =
kind === "inline"
? `\`${literal}\``
: kind === "fenced"
? `\`\`\`\n${literal}\n\`\`\``
: `Example\n\n${literal}`;
const content =
kind === "inline"
? [paragraph(text(literal, [{ type: "code" }]))]
: kind === "fenced"
? [{ type: "codeBlock", content: [text(literal)] }]
: [paragraph(text("Example")), paragraph(text(literal))];
for (const document of [
{ text_snapshot: markdown },
{ text_snapshot: "", content_json: { type: "doc", content } },
]) {
expect(trailBodyMarkdown(document)).toBe(markdown);
expect(unrenderedContent(document)).toBeNull();
}
},
);

it("falls back to the snapshot without the trail self-link", () => {
expect(
trailBodyMarkdown({
Expand Down
8 changes: 6 additions & 2 deletions packages/source-control-entire/src/server/entireTrailBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ProseMirrorNode {

/** Entire's self-link at the top of a trail body is noise inside the trail itself. */
const TRAIL_LINK =
/<!--\s*entire-trail-link-start\s*-->[\s\S]*?<!--\s*entire-trail-link-end\s*-->/gu;
/^\s*<!--\s*entire-trail-link-start\s*-->[\s\S]*?<!--\s*entire-trail-link-end\s*-->/u;

const isNode = (value: unknown): value is ProseMirrorNode =>
typeof value === "object" && value !== null && !Array.isArray(value);
Expand All @@ -43,7 +43,11 @@ const longestBacktickRun = (text: string) =>
* stays as typed, as does `_` inside a word; a partner in a neighbouring node is not looked for.
*/
function escapeText(text: string): string {
const paired = (char: string) => text.split(char).length > 2;
const counts = new Map<string, number>();
for (const char of text.match(/[`*~_]/gu) ?? []) {
counts.set(char, (counts.get(char) ?? 0) + 1);
}
const paired = (char: string) => (counts.get(char) ?? 0) > 1;
return text
.replace(/\\(?=[!-/:-@[-`{-~])/gu, "\\\\")
.replace(/[`*~]/gu, (char) => (paired(char) ? `\\${char}` : char))
Expand Down
27 changes: 27 additions & 0 deletions packages/source-control-entire/src/server/entireTrailJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,32 @@ describe("entireTrailJson", () => {
),
[],
);
for (const status of ["failed", "error", "pending", "passed"]) {
const gated = decodeDetail({
...Fixtures.detail,
mergeability: {
...Fixtures.detail.mergeability,
gates: [{ gate_type: "checks", gate_key: "checks", status, blocking: true }],
checks: {
...Fixtures.detail.mergeability.checks,
runs: [Fixtures.detail.mergeability.checks.runs[0]],
},
},
});
const expected =
status === "failed" || status === "error"
? "failing"
: status === "passed"
? "passing"
: "pending";
const gatedChecks = Json.toChecks(gated, "gh/acme/web");
assert.strictEqual(Json.toChecksState(gatedChecks), expected);
assert.strictEqual(Json.toSummaryChecksState(gated, "gh/acme/web"), expected);
assert.strictEqual(
gatedChecks.some((check) => check.name === "Entire: checks"),
status !== "passed",
);
}
assert.strictEqual(Json.headSha(detail), Fixtures.HEAD_SHA);
const permissions = Json.toViewerPermissions(detail, "gh/acme/web");
assert.deepStrictEqual(permissions.actions, ["draft", "close", "merge"]);
Expand Down Expand Up @@ -270,6 +296,7 @@ describe("entireTrailJson", () => {
checks.map((check) => [check.name, check.status, check.description]),
[
["Entire: findings", "failure", "Unresolved findings: 1 without a severity"],
["Entire: checks", "failure", "lint is failing"],
["build", "success", "Buildkite"],
["lint", "pending", null],
["Entire: up_to_date", "success", null],
Expand Down
3 changes: 2 additions & 1 deletion packages/source-control-entire/src/server/entireTrailJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ function gateChecks(
return blockingGates(detail)
.filter(
(gate) =>
gate.gate_type !== "approvals" && (gate.gate_type !== "checks" || !runsRead(detail)),
gate.gate_type !== "approvals" &&
(gate.gate_type !== "checks" || !runsRead(detail) || gate.status !== "passed"),
)
.map((gate) => ({
name: `Entire: ${gate.gate_key}`,
Expand Down
Loading