@ascribed/review 0.1.2-next.8 → 0.2.1-next.10
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 +1 -1
- package/dist/github/marker.d.ts +0 -2
- package/dist/github/marker.js +1 -1
- package/dist/github/marker.js.map +1 -1
- package/dist/github/requests.d.ts +4 -0
- package/dist/github/requests.js +5 -1
- package/dist/github/requests.js.map +1 -1
- package/dist/marks/index.d.ts +4 -24
- package/dist/marks/index.js +73 -89
- package/dist/marks/index.js.map +1 -1
- package/dist/marks/title.d.ts +8 -0
- package/dist/marks/title.js +17 -0
- package/dist/marks/title.js.map +1 -0
- package/dist/names.d.ts +95 -0
- package/dist/names.js +99 -0
- package/dist/names.js.map +1 -0
- package/dist/overlay/index.d.ts +1 -1
- package/dist/overlay/index.js.map +1 -1
- package/dist/overlay/overlay.js +32 -22
- package/dist/overlay/overlay.js.map +1 -1
- package/dist/overlay/style.d.ts +1 -1
- package/dist/overlay/style.js +2 -1
- package/dist/overlay/style.js.map +1 -1
- package/dist/overlay/text.d.ts +0 -2
- package/dist/overlay/text.js +4 -3
- package/dist/overlay/text.js.map +1 -1
- package/dist/overlay/types.d.ts +8 -2
- package/dist/overlay/types.js.map +1 -1
- package/dist/place/anchor.d.ts +3 -7
- package/dist/place/anchor.js.map +1 -1
- package/dist/shapes.d.ts +271 -0
- package/dist/shapes.js +9 -0
- package/dist/shapes.js.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ The colors are the `--ascribe-review-*` custom properties at the top of `marks.c
|
|
|
36
36
|
|
|
37
37
|
## The static report
|
|
38
38
|
|
|
39
|
-
`src/report/` is the script of `ascribe diff --format html`'s report, which draws the list of changed pages and each page with its marks. It isn't an entry point: `pnpm --filter @ascribed/review embed` bundles it with the marks and `@ascribed/elements` into `crates/
|
|
39
|
+
`src/report/` is the script of `ascribe diff --format html`'s report, which draws the list of changed pages and each page with its marks. It isn't an entry point: `pnpm --filter @ascribed/review embed` bundles it with the marks and `@ascribed/elements` into `crates/ascribe-diff/src/html/`, where the binary embeds it, along with one stylesheet made of the element library's, `marks.css`, and `src/report/report.css`. It also writes the script's SHA-256 beside it, which the report's content security policy names as the one script allowed to run. Run it after changing any of them; `test/embedded.test.ts` fails until you do.
|
|
40
40
|
|
|
41
41
|
## `@ascribed/review/overlay`
|
|
42
42
|
|
package/dist/github/marker.d.ts
CHANGED
|
@@ -14,8 +14,6 @@ export interface MarkedSection {
|
|
|
14
14
|
* this, which reading and submitting remove.
|
|
15
15
|
*/
|
|
16
16
|
export declare const PLACEHOLDER = "<!-- ascribe:review -->";
|
|
17
|
-
/** Ends a review's summary when anchored comments follow it. */
|
|
18
|
-
export declare const SUMMARY_END = "<!-- ascribe:summary -->";
|
|
19
17
|
/** `body` without the placeholder summary. */
|
|
20
18
|
export declare function withoutPlaceholder(body: string): string;
|
|
21
19
|
/**
|
package/dist/github/marker.js
CHANGED
|
@@ -21,7 +21,7 @@ const MARKER = /<!-- ascribe:anchor (\S+)(?: build=(\S+))?( quote=text)? -->/g;
|
|
|
21
21
|
*/
|
|
22
22
|
export const PLACEHOLDER = "<!-- ascribe:review -->";
|
|
23
23
|
/** Ends a review's summary when anchored comments follow it. */
|
|
24
|
-
|
|
24
|
+
const SUMMARY_END = "<!-- ascribe:summary -->";
|
|
25
25
|
/** `body` without the placeholder summary. */
|
|
26
26
|
export function withoutPlaceholder(body) {
|
|
27
27
|
return body.split(PLACEHOLDER).join("").trim();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marker.js","sourceRoot":"","sources":["../../src/github/marker.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,mEAAmE;AACnE,EAAE;AACF,+DAA+D;AAC/D,EAAE;AACF,yEAAyE;AACzE,qDAAqD;AACrD,EAAE;AACF,mCAAmC;AACnC,EAAE;AACF,6BAA6B;AAC7B,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,iC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;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,QAA2B,EAAE,OAA2B;IACnF,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,6DAA6D;IAC7D,MAAM,IAAI,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,oBAAoB,EAAE,KAAK,MAAM,GAAG,CAAC,CAAC;IAClF,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC","sourcesContent":["// Comments GitHub can't anchor to a line go on the pull request's\n// conversation, each ending with a hidden marker naming its block:\n//\n// <!-- ascribe:anchor guides/install.md:12-14 build=site -->\n//\n// Several can share one body (a review's), one after another. A review's\n// summary goes before them, ended by another marker:\n//\n// Looks good, a few notes below.\n//\n// <!-- ascribe:summary -->\n//\n// A comment quotes its block's source, or its text as the page shows it,\n// escaped so GitHub shows it as written; the marker of one that quotes the\n// shown text ends ` quote=text`.\n\n/** One anchored comment, as written in a body. */\nexport interface MarkedSection {\n /** The block's source. */\n source: string;\n build: string | undefined;\n /** The comment, without the quote, the link line, or the marker. */\n body: string;\n /** The block's text the comment quoted, if it did. */\n quote: string | undefined;\n}\n\nconst MARKER = /<!-- ascribe:anchor (\\S+)(?: build=(\\S+))?( quote=text)? -->/g;\n\n/**\n * The summary a pending review starts with. GitHub can't edit the summary of\n * a pending review created without one, so the session's reviews start with\n * this, which reading and submitting remove.\n */\nexport const PLACEHOLDER = \"<!-- ascribe:review -->\";\n\n/** Ends a review's summary when anchored comments follow it. */\nexport const SUMMARY_END = \"<!-- ascribe:summary -->\";\n\n/** `body` without the placeholder summary. */\nexport function withoutPlaceholder(body: string): string {\n return body.split(PLACEHOLDER).join(\"\").trim();\n}\n\n/**\n * The marker for a block. Without a build (or with `\"\"`), the comment is on\n * every build's page. `shown` marks a quote of the shown text.\n */\nexport function marker(source: string, build: string | undefined, shown = false): string {\n return `<!-- ascribe:anchor ${source}${build === undefined || build === \"\" ? \"\" : ` build=${build}`}${shown ? \" quote=text\" : \"\"} -->`;\n}\n\n/** Joins a mention or reference sign to what follows, so GitHub doesn't link it. */\nconst JOINER = \"\\u2060\";\n\n/**\n * Plain text as Markdown that GitHub shows as the text: punctuation\n * escaped, `@name` and `#123` not linked, line breaks and leading spaces\n * kept.\n */\nexport function escapeText(text: string): string {\n const lines = text.split(/\\r?\\n/).map((line) => {\n const indent = /^ */.exec(line)?.[0].length ?? 0;\n const rest = line\n .slice(indent)\n .replace(/[!-/:-@[-`{-~]/g, (c) => (c === \"<\" ? \"<\" : `\\\\${c}`))\n .replace(/[@#]/g, `$&${JOINER}`);\n return \"\\u00a0\".repeat(indent) + rest;\n });\n // A backslash at the end of a line breaks it, but not before a blank line.\n return lines\n .map((line, i) => (line !== \"\" && (lines[i + 1] ?? \"\") !== \"\" ? `${line}\\\\` : line))\n .join(\"\\n\");\n}\n\n/** Text that `escapeText` wrote, as it was. */\nexport function unescapeText(text: string): string {\n return text\n .split(/\\r?\\n/)\n .map((line) => {\n const trailing = /\\\\*$/.exec(line)?.[0].length ?? 0;\n const unbroken = trailing % 2 === 1 ? line.slice(0, -1) : line;\n const indent = /^\\u00a0*/.exec(unbroken)?.[0].length ?? 0;\n return (\n \" \".repeat(indent) +\n unbroken\n .slice(indent)\n .replace(new RegExp(`([@#])${JOINER}`, \"g\"), \"$1\")\n .replace(/\\\\([!-/:-@[-`{-~])|</g, (_, c: string | undefined) => c ?? \"<\")\n );\n })\n .join(\"\\n\");\n}\n\n/**\n * Writes a section: the block's text quoted, the comment, a line linking the\n * block's lines, and the marker.\n */\nexport function formatSection(options: {\n source: string;\n build: string | undefined;\n body: string;\n quote: string | undefined;\n /** Whether `quote` is the block's text as the page shows it, rather than its source. */\n shown?: boolean;\n link: { label: string; url: string } | undefined;\n}): string {\n const parts: string[] = [];\n const shown = options.shown === true;\n if (options.quote !== undefined && options.quote.trim() !== \"\") {\n parts.push(\n (shown ? escapeText(options.quote) : options.quote)\n .split(/\\r?\\n/)\n .map((line) => (line === \"\" ? \">\" : `> ${line}`))\n .join(\"\\n\"),\n );\n }\n parts.push(options.body.trim());\n const end = marker(options.source, options.build, shown);\n parts.push(\n options.link === undefined\n ? end\n : `<sub>On [${options.link.label.replace(/[[\\]]/g, \"\\\\$&\")}](${options.link.url})</sub>\\n${end}`,\n );\n return parts.join(\"\\n\\n\");\n}\n\n/**\n * Splits a body into its summary, its marked sections, and the text after\n * the last marker (`rest`), which isn't anchored either.\n */\nexport function parseSections(text: string): {\n summary: string;\n sections: MarkedSection[];\n rest: string;\n} {\n let body = withoutPlaceholder(text);\n let summary = \"\";\n // The summary ends before the first comment, if it's there at all.\n const end = body.indexOf(SUMMARY_END);\n const first = body.search(new RegExp(MARKER.source));\n if (end >= 0 && (first < 0 || end < first)) {\n summary = body.slice(0, end).trim();\n body = body.slice(end + SUMMARY_END.length).trim();\n }\n const sections: MarkedSection[] = [];\n let start = 0;\n for (const match of body.matchAll(MARKER)) {\n const source = match[1] ?? \"\";\n const text = body.slice(start, match.index);\n start = match.index + match[0].length;\n const { body: comment, quote } = unwrap(text);\n sections.push({\n source,\n build: match[2],\n body: comment,\n quote: quote !== undefined && match[3] !== undefined ? unescapeText(quote) : quote,\n });\n }\n return { summary, sections, rest: body.slice(start).trim() };\n}\n\nfunction unwrap(text: string): { body: string; quote: string | undefined } {\n let rest = text.replace(/\\s*<sub>On \\[[^\\n]*\\]\\([^\\n)]*\\)<\\/sub>\\s*$/, \"\").trim();\n let quote: string | undefined;\n const lines = rest.split(/\\r?\\n/);\n let quoted = 0;\n while (quoted < lines.length && /^>( |$)/.test(lines[quoted] ?? \"\")) quoted++;\n if (quoted > 0 && quoted < lines.length && (lines[quoted] ?? \"\").trim() === \"\") {\n quote = lines\n .slice(0, quoted)\n .map((line) => line.replace(/^> ?/, \"\"))\n .join(\"\\n\");\n rest = lines\n .slice(quoted + 1)\n .join(\"\\n\")\n .trim();\n }\n return { body: rest, quote };\n}\n\n/**\n * Joins a summary and sections into one body: the summary first, so it\n * doesn't read as a remark on the last section.\n */\nexport function joinSections(sections: readonly string[], summary: string | undefined): string {\n const held = sections.filter((part) => part.trim() !== \"\");\n // A marker in the summary would be read as one of Ascribe's.\n const lead = (summary ?? \"\").trim().replace(/(<!--\\s*ascribe):/g, `$1${JOINER}:`);\n if (lead === \"\") return held.join(\"\\n\\n\");\n if (held.length === 0) return lead;\n return [lead, SUMMARY_END, ...held].join(\"\\n\\n\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"marker.js","sourceRoot":"","sources":["../../src/github/marker.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,mEAAmE;AACnE,EAAE;AACF,+DAA+D;AAC/D,EAAE;AACF,yEAAyE;AACzE,qDAAqD;AACrD,EAAE;AACF,mCAAmC;AACnC,EAAE;AACF,6BAA6B;AAC7B,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,iCAAiC;AAajC,MAAM,MAAM,GAAG,+DAA+D,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAErD,gEAAgE;AAChE,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAE/C,8CAA8C;AAC9C,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,MAAc,EAAE,KAAy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AAM,CAAC,CAAC;IAC1C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC","sourcesContent":["// Comments GitHub can't anchor to a line go on the pull request's\n// conversation, each ending with a hidden marker naming its block:\n//\n// <!-- ascribe:anchor guides/install.md:12-14 build=site -->\n//\n// Several can share one body (a review's), one after another. A review's\n// summary goes before them, ended by another marker:\n//\n// Looks good, a few notes below.\n//\n// <!-- ascribe:summary -->\n//\n// A comment quotes its block's source, or its text as the page shows it,\n// escaped so GitHub shows it as written; the marker of one that quotes the\n// shown text ends ` quote=text`.\n\n/** One anchored comment, as written in a body. */\nexport interface MarkedSection {\n /** The block's source. */\n source: string;\n build: string | undefined;\n /** The comment, without the quote, the link line, or the marker. */\n body: string;\n /** The block's text the comment quoted, if it did. */\n quote: string | undefined;\n}\n\nconst MARKER = /<!-- ascribe:anchor (\\S+)(?: build=(\\S+))?( quote=text)? -->/g;\n\n/**\n * The summary a pending review starts with. GitHub can't edit the summary of\n * a pending review created without one, so the session's reviews start with\n * this, which reading and submitting remove.\n */\nexport const PLACEHOLDER = \"<!-- ascribe:review -->\";\n\n/** Ends a review's summary when anchored comments follow it. */\nconst SUMMARY_END = \"<!-- ascribe:summary -->\";\n\n/** `body` without the placeholder summary. */\nexport function withoutPlaceholder(body: string): string {\n return body.split(PLACEHOLDER).join(\"\").trim();\n}\n\n/**\n * The marker for a block. Without a build (or with `\"\"`), the comment is on\n * every build's page. `shown` marks a quote of the shown text.\n */\nexport function marker(source: string, build: string | undefined, shown = false): string {\n return `<!-- ascribe:anchor ${source}${build === undefined || build === \"\" ? \"\" : ` build=${build}`}${shown ? \" quote=text\" : \"\"} -->`;\n}\n\n/** Joins a mention or reference sign to what follows, so GitHub doesn't link it. */\nconst JOINER = \"\\u2060\";\n\n/**\n * Plain text as Markdown that GitHub shows as the text: punctuation\n * escaped, `@name` and `#123` not linked, line breaks and leading spaces\n * kept.\n */\nexport function escapeText(text: string): string {\n const lines = text.split(/\\r?\\n/).map((line) => {\n const indent = /^ */.exec(line)?.[0].length ?? 0;\n const rest = line\n .slice(indent)\n .replace(/[!-/:-@[-`{-~]/g, (c) => (c === \"<\" ? \"<\" : `\\\\${c}`))\n .replace(/[@#]/g, `$&${JOINER}`);\n return \"\\u00a0\".repeat(indent) + rest;\n });\n // A backslash at the end of a line breaks it, but not before a blank line.\n return lines\n .map((line, i) => (line !== \"\" && (lines[i + 1] ?? \"\") !== \"\" ? `${line}\\\\` : line))\n .join(\"\\n\");\n}\n\n/** Text that `escapeText` wrote, as it was. */\nexport function unescapeText(text: string): string {\n return text\n .split(/\\r?\\n/)\n .map((line) => {\n const trailing = /\\\\*$/.exec(line)?.[0].length ?? 0;\n const unbroken = trailing % 2 === 1 ? line.slice(0, -1) : line;\n const indent = /^\\u00a0*/.exec(unbroken)?.[0].length ?? 0;\n return (\n \" \".repeat(indent) +\n unbroken\n .slice(indent)\n .replace(new RegExp(`([@#])${JOINER}`, \"g\"), \"$1\")\n .replace(/\\\\([!-/:-@[-`{-~])|</g, (_, c: string | undefined) => c ?? \"<\")\n );\n })\n .join(\"\\n\");\n}\n\n/**\n * Writes a section: the block's text quoted, the comment, a line linking the\n * block's lines, and the marker.\n */\nexport function formatSection(options: {\n source: string;\n build: string | undefined;\n body: string;\n quote: string | undefined;\n /** Whether `quote` is the block's text as the page shows it, rather than its source. */\n shown?: boolean;\n link: { label: string; url: string } | undefined;\n}): string {\n const parts: string[] = [];\n const shown = options.shown === true;\n if (options.quote !== undefined && options.quote.trim() !== \"\") {\n parts.push(\n (shown ? escapeText(options.quote) : options.quote)\n .split(/\\r?\\n/)\n .map((line) => (line === \"\" ? \">\" : `> ${line}`))\n .join(\"\\n\"),\n );\n }\n parts.push(options.body.trim());\n const end = marker(options.source, options.build, shown);\n parts.push(\n options.link === undefined\n ? end\n : `<sub>On [${options.link.label.replace(/[[\\]]/g, \"\\\\$&\")}](${options.link.url})</sub>\\n${end}`,\n );\n return parts.join(\"\\n\\n\");\n}\n\n/**\n * Splits a body into its summary, its marked sections, and the text after\n * the last marker (`rest`), which isn't anchored either.\n */\nexport function parseSections(text: string): {\n summary: string;\n sections: MarkedSection[];\n rest: string;\n} {\n let body = withoutPlaceholder(text);\n let summary = \"\";\n // The summary ends before the first comment, if it's there at all.\n const end = body.indexOf(SUMMARY_END);\n const first = body.search(new RegExp(MARKER.source));\n if (end >= 0 && (first < 0 || end < first)) {\n summary = body.slice(0, end).trim();\n body = body.slice(end + SUMMARY_END.length).trim();\n }\n const sections: MarkedSection[] = [];\n let start = 0;\n for (const match of body.matchAll(MARKER)) {\n const source = match[1] ?? \"\";\n const text = body.slice(start, match.index);\n start = match.index + match[0].length;\n const { body: comment, quote } = unwrap(text);\n sections.push({\n source,\n build: match[2],\n body: comment,\n quote: quote !== undefined && match[3] !== undefined ? unescapeText(quote) : quote,\n });\n }\n return { summary, sections, rest: body.slice(start).trim() };\n}\n\nfunction unwrap(text: string): { body: string; quote: string | undefined } {\n let rest = text.replace(/\\s*<sub>On \\[[^\\n]*\\]\\([^\\n)]*\\)<\\/sub>\\s*$/, \"\").trim();\n let quote: string | undefined;\n const lines = rest.split(/\\r?\\n/);\n let quoted = 0;\n while (quoted < lines.length && /^>( |$)/.test(lines[quoted] ?? \"\")) quoted++;\n if (quoted > 0 && quoted < lines.length && (lines[quoted] ?? \"\").trim() === \"\") {\n quote = lines\n .slice(0, quoted)\n .map((line) => line.replace(/^> ?/, \"\"))\n .join(\"\\n\");\n rest = lines\n .slice(quoted + 1)\n .join(\"\\n\")\n .trim();\n }\n return { body: rest, quote };\n}\n\n/**\n * Joins a summary and sections into one body: the summary first, so it\n * doesn't read as a remark on the last section.\n */\nexport function joinSections(sections: readonly string[], summary: string | undefined): string {\n const held = sections.filter((part) => part.trim() !== \"\");\n // A marker in the summary would be read as one of Ascribe's.\n const lead = (summary ?? \"\").trim().replace(/(<!--\\s*ascribe):/g, `$1${JOINER}:`);\n if (lead === \"\") return held.join(\"\\n\\n\");\n if (held.length === 0) return lead;\n return [lead, SUMMARY_END, ...held].join(\"\\n\\n\");\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PageRef } from "../place/place.js";
|
|
2
|
+
import type { FormattedPiece } from "../shapes.js";
|
|
2
3
|
import type { PullRequestInfo, ReviewSession } from "./session.js";
|
|
3
4
|
/** The overlay's requests, one per `OverlayHost` method that reads or writes threads. */
|
|
4
5
|
export type OverlayMethod = "load" | "commentTarget" | "comment" | "reply" | "allThreads" | "resolve" | "submit" | "discard";
|
|
@@ -9,6 +10,8 @@ export interface ChangedPageRef {
|
|
|
9
10
|
status: "added" | "removed" | "changed";
|
|
10
11
|
because: readonly string[];
|
|
11
12
|
title?: string | null;
|
|
13
|
+
/** The title formatted, when its field sets `inline = "code"`. */
|
|
14
|
+
formatted_title?: readonly FormattedPiece[] | null;
|
|
12
15
|
}
|
|
13
16
|
/** What answering a request needs. */
|
|
14
17
|
export interface RequestContext {
|
|
@@ -48,6 +51,7 @@ export declare function answerRequest(context: RequestContext, method: OverlayMe
|
|
|
48
51
|
export declare function pagesShowing(file: string, pages: readonly ChangedPageRef[]): {
|
|
49
52
|
path: string;
|
|
50
53
|
title: string | null;
|
|
54
|
+
formatted_title: FormattedPiece[] | null;
|
|
51
55
|
}[];
|
|
52
56
|
/**
|
|
53
57
|
* The git revision to compare with for a pull request's base: the remote
|
package/dist/github/requests.js
CHANGED
|
@@ -211,7 +211,11 @@ export function pagesShowing(file, pages) {
|
|
|
211
211
|
.filter((page) => page.status !== "removed")
|
|
212
212
|
.filter((page) => page.path === file || page.because.includes(file))
|
|
213
213
|
.sort((a, b) => Number(b.path === file) - Number(a.path === file))
|
|
214
|
-
.map((page) => ({
|
|
214
|
+
.map((page) => ({
|
|
215
|
+
path: page.path,
|
|
216
|
+
title: page.title ?? null,
|
|
217
|
+
formatted_title: page.formatted_title ? [...page.formatted_title] : null,
|
|
218
|
+
}));
|
|
215
219
|
}
|
|
216
220
|
/**
|
|
217
221
|
* The git revision to compare with for a pull request's base: the remote
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../src/github/requests.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAe,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAyB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,MAAM,CAAC,MAAM,eAAe,GAA6B;IACvD,MAAM;IACN,eAAe;IACf,SAAS;IACT,OAAO;IACP,YAAY;IACZ,SAAS;IACT,QAAQ;IACR,SAAS;CACV,CAAC;AAmCF,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAuB,EACvB,MAAqB,EACrB,MAA+B;IAE/B,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAC1B,IAAI,CAAC,IAAI;gBAAE,MAAM,IAAI,WAAW,CAAC,WAAW,EAAE,iCAAiC,CAAC,CAAC;YACjF,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YACzC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACjD,8DAA8D;YAC9D,MAAM,IAAI,GAAG,IA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's requests (`OverlayHost`) from a review session, for\n// a host that keeps GitHub to itself and passes the overlay's requests on as\n// messages: the page preview's extension, or the site preview's dev server.\n// The parameters arrive as untyped messages, so each is checked here.\nimport { anchorKey, parseSource, type Anchor } from \"../place/anchor.js\";\nimport { lineHunks, shiftLine, type Hunk, type Sides } from \"../place/lines.js\";\nimport type { PageRef, PlacedThreads } from \"../place/place.js\";\nimport { ReviewError } from \"../shared/errors.js\";\nimport { gitMaybe } from \"../shared/git.js\";\nimport { parseRemote } from \"./repository.js\";\nimport type { PullRequestInfo, ReviewEvent, ReviewSession } from \"./session.js\";\n\n/** The overlay's requests, one per `OverlayHost` method that reads or writes threads. */\nexport type OverlayMethod =\n \"load\" | \"commentTarget\" | \"comment\" | \"reply\" | \"allThreads\" | \"resolve\" | \"submit\" | \"discard\";\n\nexport const OVERLAY_METHODS: readonly OverlayMethod[] = [\n \"load\",\n \"commentTarget\",\n \"comment\",\n \"reply\",\n \"allThreads\",\n \"resolve\",\n \"submit\",\n \"discard\",\n];\n\n/** A changed page as `ascribe diff` lists it, with its title when the host knows it. */\nexport interface ChangedPageRef {\n path: string;\n status: \"added\" | \"removed\" | \"changed\";\n because: readonly string[];\n title?: string | null;\n}\n\n/** What answering a request needs. */\nexport interface RequestContext {\n session: ReviewSession;\n /** The page the overlay is on: its build and content path. */\n page: { build: string; path: string } | undefined;\n /** The page as the overlay last read it, with its anchors: comments are made on it. */\n lastPage: PageRef | undefined;\n /** The changed pages, for which pages show a thread. */\n changedPages(): Promise<readonly ChangedPageRef[]>;\n /**\n * For a host whose pages are rendered from an editor's unsaved text: a\n * file's text on disk (`saved`) and in the editor (`current`), by content\n * path, or `undefined` when they're the same. The session counts lines on\n * disk, so the page's blocks are moved to their lines there, and back.\n */\n unsaved?(path: string): Promise<{ saved: string; current: string } | undefined>;\n}\n\n/** An answer: the result, the page read (for `load`), and whether the request changed the threads. */\nexport interface Answer {\n result: unknown;\n page?: PageRef;\n changed: boolean;\n}\n\n/** Answers one of the overlay's requests. Rejects with a `ReviewError`. */\nexport async function answerRequest(\n context: RequestContext,\n method: OverlayMethod,\n params: Record<string, unknown>,\n): Promise<Answer> {\n const { session } = context;\n switch (method) {\n case \"load\": {\n const page = context.page;\n if (!page) throw new ReviewError(\"not-found\", \"There's no page to review here.\");\n const shown = anchors(params[\"anchors\"]);\n const edits = await unsavedEdits(context, shown);\n // The page's blocks at their lines on disk, and the way back.\n const back = new Map<string, Anchor>();\n for (const block of shown) {\n const saved = toSaved(edits, block, false);\n if (saved !== undefined && !back.has(anchorKey(saved))) back.set(anchorKey(saved), block);\n }\n const ref: PageRef = {\n build: page.build,\n path: page.path,\n anchors: edits.size === 0 ? shown : [...back.keys()].map((key) => fromKey(key)),\n removed: anchors(params[\"removed\"]),\n };\n const [placed, pending, viewer] = await Promise.all([\n session.threads(ref),\n session.pending(),\n session.viewer(),\n ]);\n const threads: PlacedThreads =\n edits.size === 0\n ? placed\n : {\n ...placed,\n blocks: placed.blocks.map((block) => ({\n ...block,\n anchor: back.get(anchorKey(block.anchor)) ?? block.anchor,\n })),\n };\n const pr = session.pullRequest;\n return {\n result: { pullRequest: { number: pr.number, url: pr.url }, threads, pending, viewer },\n page: ref,\n changed: false,\n };\n }\n case \"commentTarget\": {\n const shown = anchor(params[\"anchor\"]);\n const saved = toSaved(await unsavedEdits(context, [shown]), shown, true);\n if (saved === undefined)\n return { result: { kind: \"push-first\", message: UNSAVED }, changed: false };\n return { result: await session.commentTarget(saved), changed: false };\n }\n case \"allThreads\": {\n const [threads, pages] = await Promise.all([\n session.allThreads(),\n context.changedPages().catch(() => []),\n ]);\n return {\n result: threads.map((thread) => ({ thread, pages: pagesShowing(thread.path, pages) })),\n changed: false,\n };\n }\n case \"comment\": {\n const shown = anchor(params[\"anchor\"]);\n const target = toSaved(await unsavedEdits(context, [shown]), shown, true);\n if (target === undefined) throw new ReviewError(\"push-first\", UNSAVED);\n const page = context.lastPage ?? {\n build: context.page?.build ?? \"\",\n path: context.page?.path ?? \"\",\n anchors: [target],\n };\n const quote = typeof params[\"quote\"] === \"string\" ? params[\"quote\"] : undefined;\n return {\n result: await session.comment(target, text(params[\"body\"]), page, quote),\n changed: true,\n };\n }\n case \"reply\":\n return {\n result: await session.reply(\n text(params[\"threadId\"]),\n text(params[\"body\"]),\n params[\"when\"] === \"now\" ? \"now\" : \"withReview\",\n ),\n changed: true,\n };\n case \"resolve\":\n await session.resolve(text(params[\"threadId\"]), params[\"resolved\"] === true);\n return { result: null, changed: true };\n case \"submit\": {\n const body = typeof params[\"body\"] === \"string\" ? params[\"body\"] : undefined;\n await session.submit(event(params[\"event\"]), body);\n return { result: null, changed: true };\n }\n case \"discard\":\n await session.discard();\n return { result: null, changed: true };\n }\n}\n\n/** A file's unsaved edits: the line changes from the editor's text to the text on disk. */\ninterface Edit {\n hunks: Hunk[];\n sides: Sides;\n}\n\nconst UNSAVED = \"This block has changes that aren't saved. Save the file, then comment.\";\n\n/** The line changes from each shown file's text in the editor to its text on disk, where they differ. */\nasync function unsavedEdits(\n context: RequestContext,\n shown: readonly Anchor[],\n): Promise<Map<string, Edit>> {\n const edits = new Map<string, Edit>();\n if (!context.unsaved) return edits;\n const files = new Set<string>();\n for (const block of shown) {\n const range = parseSource(block.source);\n if (range) files.add(range.path);\n for (const include of block.via) {\n const at = parseInclude(include);\n if (at) files.add(at.path);\n }\n }\n for (const file of files) {\n const text = await context.unsaved(file);\n if (text === undefined) continue;\n const hunks = lineHunks(text.current, text.saved);\n if (hunks.length > 0) {\n edits.set(file, {\n hunks,\n sides: { old: text.current.split(/\\r?\\n/), new: text.saved.split(/\\r?\\n/) },\n });\n }\n }\n return edits;\n}\n\n/**\n * A block's anchor with its lines on disk. `strict` (for commenting) wants\n * every line of the block saved as it is; otherwise an edited block takes\n * the lines its text has on disk. `undefined` when nothing of it is saved.\n */\nfunction toSaved(\n edits: ReadonlyMap<string, Edit>,\n block: Anchor,\n strict: boolean,\n): Anchor | undefined {\n if (edits.size === 0) return block;\n const range = parseSource(block.source);\n if (range === undefined) return block;\n const edit = edits.get(range.path);\n let source = block.source;\n if (edit !== undefined) {\n const lines: number[] = [];\n for (let line = range.first; line <= range.last; line++) {\n const moved = shiftLine(edit.hunks, line, edit.sides);\n if (moved === undefined || moved.replaced) {\n if (strict) return undefined;\n if (moved === undefined) continue;\n }\n lines.push(moved.line);\n }\n if (lines.length === 0) return undefined;\n const colon = block.source.lastIndexOf(\":\");\n source = `${block.source.slice(0, colon)}:${Math.min(...lines)}-${Math.max(...lines)}`;\n }\n const via: string[] = [];\n for (const include of block.via) {\n const at = parseInclude(include);\n const includeEdit = at && edits.get(at.path);\n if (!at || !includeEdit) {\n via.push(include);\n continue;\n }\n const moved = shiftLine(includeEdit.hunks, at.line, includeEdit.sides);\n if (moved === undefined || (strict && moved.replaced)) return undefined;\n via.push(`${include.slice(0, include.lastIndexOf(\":\"))}:${moved.line}`);\n }\n return { source, via };\n}\n\n/** An include, `<path>:<line>`, parsed, with its path decoded. */\nfunction parseInclude(include: string): { path: string; line: number } | undefined {\n const colon = include.lastIndexOf(\":\");\n const line = Number(include.slice(colon + 1));\n if (colon <= 0 || !Number.isInteger(line) || line < 1) return undefined;\n const range = parseSource(`${include.slice(0, colon)}:1-1`);\n return range && { path: range.path, line };\n}\n\n/** The anchor `anchorKey` wrote. */\nfunction fromKey(key: string): Anchor {\n const [source = \"\", ...via] = key.split(\" \");\n return { source, via };\n}\n\n/**\n * The changed pages that show a file (a content path): the file's own page,\n * and the pages that changed through it (an include). `[]` when none does.\n */\nexport function pagesShowing(\n file: string,\n pages: readonly ChangedPageRef[],\n): { path: string; title: string | null }[] {\n return pages\n .filter((page) => page.status !== \"removed\")\n .filter((page) => page.path === file || page.because.includes(file))\n .sort((a, b) => Number(b.path === file) - Number(a.path === file))\n .map((page) => ({ path: page.path, title: page.title ?? null }));\n}\n\n/**\n * The git revision to compare with for a pull request's base: the remote\n * branch, from the remote whose URL is the pull request's repository, when\n * there is one; else the branch's name.\n */\nexport function pullRequestBase(\n remotes: readonly { name: string; repository: string | undefined }[],\n repository: string,\n baseRefName: string,\n): string {\n const remote =\n remotes.find((r) => r.repository === repository && r.name === \"upstream\") ??\n remotes.find((r) => r.repository === repository && r.name === \"origin\") ??\n remotes.find((r) => r.repository === repository);\n return remote ? `${remote.name}/${baseRefName}` : baseRefName;\n}\n\n/**\n * The git revision for the pull request's base in the checkout at `root`:\n * `origin/main` when that remote branch exists, else the branch's name.\n */\nexport async function baseRevision(root: string, pr: PullRequestInfo): Promise<string> {\n const out = (await gitMaybe(root, [\"remote\", \"-v\"]).catch(() => undefined)) ?? \"\";\n const remotes = out\n .split(\"\\n\")\n .map((line) => /^(\\S+)\\s+(\\S+)\\s+\\(fetch\\)$/.exec(line))\n .filter((match) => match !== null)\n .map((match) => {\n const repository = parseRemote(match[2] ?? \"\");\n return { name: match[1] ?? \"\", repository: repository && repoKey(repository) };\n });\n const revision = pullRequestBase(remotes, repoKey(pr.repository), pr.baseRefName);\n if (revision !== pr.baseRefName) {\n const exists = await gitMaybe(root, [\"rev-parse\", \"--verify\", \"--quiet\", revision]).catch(\n () => undefined,\n );\n if (exists !== undefined) return revision;\n }\n return pr.baseRefName;\n}\n\nfunction repoKey(repository: { host: string; owner: string; name: string }): string {\n return `${repository.host}/${repository.owner}/${repository.name}`.toLowerCase();\n}\n\nconst EVENTS: readonly ReviewEvent[] = [\"COMMENT\", \"APPROVE\", \"REQUEST_CHANGES\"];\n\nfunction event(value: unknown): ReviewEvent {\n if (EVENTS.includes(value as ReviewEvent)) return value as ReviewEvent;\n throw new ReviewError(\"refused\", `A review can't be submitted as ${String(value)}.`);\n}\n\nfunction text(value: unknown): string {\n if (typeof value !== \"string\") throw new ReviewError(\"refused\", \"The request is missing text.\");\n return value;\n}\n\nfunction anchor(value: unknown): Anchor {\n const record = value as Partial<Anchor> | null;\n if (typeof record?.source !== \"string\") {\n throw new ReviewError(\"refused\", \"The request is missing a block.\");\n }\n const via = Array.isArray(record.via) ? record.via.filter((v) => typeof v === \"string\") : [];\n return { source: record.source, via };\n}\n\nfunction anchors(value: unknown): Anchor[] {\n return Array.isArray(value) ? value.map(anchor) : [];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../src/github/requests.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAe,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAyB,MAAM,mBAAmB,CAAC;AAGhF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,MAAM,CAAC,MAAM,eAAe,GAA6B;IACvD,MAAM;IACN,eAAe;IACf,SAAS;IACT,OAAO;IACP,YAAY;IACZ,SAAS;IACT,QAAQ;IACR,SAAS;CACV,CAAC;AAqCF,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAuB,EACvB,MAAqB,EACrB,MAA+B;IAE/B,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAC1B,IAAI,CAAC,IAAI;gBAAE,MAAM,IAAI,WAAW,CAAC,WAAW,EAAE,iCAAiC,CAAC,CAAC;YACjF,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YACzC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACjD,8DAA8D;YAC9D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;YACvC,KAAK,MAAM,KAAK,IAAI,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C,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC","sourcesContent":["// Answering the overlay's requests (`OverlayHost`) from a review session, for\n// a host that keeps GitHub to itself and passes the overlay's requests on as\n// messages: the page preview's extension, or the site preview's dev server.\n// The parameters arrive as untyped messages, so each is checked here.\nimport { anchorKey, parseSource, type Anchor } from \"../place/anchor.js\";\nimport { lineHunks, shiftLine, type Hunk, type Sides } from \"../place/lines.js\";\nimport type { PageRef, PlacedThreads } from \"../place/place.js\";\nimport type { FormattedPiece } from \"../shapes.js\";\nimport { ReviewError } from \"../shared/errors.js\";\nimport { gitMaybe } from \"../shared/git.js\";\nimport { parseRemote } from \"./repository.js\";\nimport type { PullRequestInfo, ReviewEvent, ReviewSession } from \"./session.js\";\n\n/** The overlay's requests, one per `OverlayHost` method that reads or writes threads. */\nexport type OverlayMethod =\n \"load\" | \"commentTarget\" | \"comment\" | \"reply\" | \"allThreads\" | \"resolve\" | \"submit\" | \"discard\";\n\nexport const OVERLAY_METHODS: readonly OverlayMethod[] = [\n \"load\",\n \"commentTarget\",\n \"comment\",\n \"reply\",\n \"allThreads\",\n \"resolve\",\n \"submit\",\n \"discard\",\n];\n\n/** A changed page as `ascribe diff` lists it, with its title when the host knows it. */\nexport interface ChangedPageRef {\n path: string;\n status: \"added\" | \"removed\" | \"changed\";\n because: readonly string[];\n title?: string | null;\n /** The title formatted, when its field sets `inline = \"code\"`. */\n formatted_title?: readonly FormattedPiece[] | null;\n}\n\n/** What answering a request needs. */\nexport interface RequestContext {\n session: ReviewSession;\n /** The page the overlay is on: its build and content path. */\n page: { build: string; path: string } | undefined;\n /** The page as the overlay last read it, with its anchors: comments are made on it. */\n lastPage: PageRef | undefined;\n /** The changed pages, for which pages show a thread. */\n changedPages(): Promise<readonly ChangedPageRef[]>;\n /**\n * For a host whose pages are rendered from an editor's unsaved text: a\n * file's text on disk (`saved`) and in the editor (`current`), by content\n * path, or `undefined` when they're the same. The session counts lines on\n * disk, so the page's blocks are moved to their lines there, and back.\n */\n unsaved?(path: string): Promise<{ saved: string; current: string } | undefined>;\n}\n\n/** An answer: the result, the page read (for `load`), and whether the request changed the threads. */\nexport interface Answer {\n result: unknown;\n page?: PageRef;\n changed: boolean;\n}\n\n/** Answers one of the overlay's requests. Rejects with a `ReviewError`. */\nexport async function answerRequest(\n context: RequestContext,\n method: OverlayMethod,\n params: Record<string, unknown>,\n): Promise<Answer> {\n const { session } = context;\n switch (method) {\n case \"load\": {\n const page = context.page;\n if (!page) throw new ReviewError(\"not-found\", \"There's no page to review here.\");\n const shown = anchors(params[\"anchors\"]);\n const edits = await unsavedEdits(context, shown);\n // The page's blocks at their lines on disk, and the way back.\n const back = new Map<string, Anchor>();\n for (const block of shown) {\n const saved = toSaved(edits, block, false);\n if (saved !== undefined && !back.has(anchorKey(saved))) back.set(anchorKey(saved), block);\n }\n const ref: PageRef = {\n build: page.build,\n path: page.path,\n anchors: edits.size === 0 ? shown : [...back.keys()].map((key) => fromKey(key)),\n removed: anchors(params[\"removed\"]),\n };\n const [placed, pending, viewer] = await Promise.all([\n session.threads(ref),\n session.pending(),\n session.viewer(),\n ]);\n const threads: PlacedThreads =\n edits.size === 0\n ? placed\n : {\n ...placed,\n blocks: placed.blocks.map((block) => ({\n ...block,\n anchor: back.get(anchorKey(block.anchor)) ?? block.anchor,\n })),\n };\n const pr = session.pullRequest;\n return {\n result: { pullRequest: { number: pr.number, url: pr.url }, threads, pending, viewer },\n page: ref,\n changed: false,\n };\n }\n case \"commentTarget\": {\n const shown = anchor(params[\"anchor\"]);\n const saved = toSaved(await unsavedEdits(context, [shown]), shown, true);\n if (saved === undefined)\n return { result: { kind: \"push-first\", message: UNSAVED }, changed: false };\n return { result: await session.commentTarget(saved), changed: false };\n }\n case \"allThreads\": {\n const [threads, pages] = await Promise.all([\n session.allThreads(),\n context.changedPages().catch(() => []),\n ]);\n return {\n result: threads.map((thread) => ({ thread, pages: pagesShowing(thread.path, pages) })),\n changed: false,\n };\n }\n case \"comment\": {\n const shown = anchor(params[\"anchor\"]);\n const target = toSaved(await unsavedEdits(context, [shown]), shown, true);\n if (target === undefined) throw new ReviewError(\"push-first\", UNSAVED);\n const page = context.lastPage ?? {\n build: context.page?.build ?? \"\",\n path: context.page?.path ?? \"\",\n anchors: [target],\n };\n const quote = typeof params[\"quote\"] === \"string\" ? params[\"quote\"] : undefined;\n return {\n result: await session.comment(target, text(params[\"body\"]), page, quote),\n changed: true,\n };\n }\n case \"reply\":\n return {\n result: await session.reply(\n text(params[\"threadId\"]),\n text(params[\"body\"]),\n params[\"when\"] === \"now\" ? \"now\" : \"withReview\",\n ),\n changed: true,\n };\n case \"resolve\":\n await session.resolve(text(params[\"threadId\"]), params[\"resolved\"] === true);\n return { result: null, changed: true };\n case \"submit\": {\n const body = typeof params[\"body\"] === \"string\" ? params[\"body\"] : undefined;\n await session.submit(event(params[\"event\"]), body);\n return { result: null, changed: true };\n }\n case \"discard\":\n await session.discard();\n return { result: null, changed: true };\n }\n}\n\n/** A file's unsaved edits: the line changes from the editor's text to the text on disk. */\ninterface Edit {\n hunks: Hunk[];\n sides: Sides;\n}\n\nconst UNSAVED = \"This block has changes that aren't saved. Save the file, then comment.\";\n\n/** The line changes from each shown file's text in the editor to its text on disk, where they differ. */\nasync function unsavedEdits(\n context: RequestContext,\n shown: readonly Anchor[],\n): Promise<Map<string, Edit>> {\n const edits = new Map<string, Edit>();\n if (!context.unsaved) return edits;\n const files = new Set<string>();\n for (const block of shown) {\n const range = parseSource(block.source);\n if (range) files.add(range.path);\n for (const include of block.via) {\n const at = parseInclude(include);\n if (at) files.add(at.path);\n }\n }\n for (const file of files) {\n const text = await context.unsaved(file);\n if (text === undefined) continue;\n const hunks = lineHunks(text.current, text.saved);\n if (hunks.length > 0) {\n edits.set(file, {\n hunks,\n sides: { old: text.current.split(/\\r?\\n/), new: text.saved.split(/\\r?\\n/) },\n });\n }\n }\n return edits;\n}\n\n/**\n * A block's anchor with its lines on disk. `strict` (for commenting) wants\n * every line of the block saved as it is; otherwise an edited block takes\n * the lines its text has on disk. `undefined` when nothing of it is saved.\n */\nfunction toSaved(\n edits: ReadonlyMap<string, Edit>,\n block: Anchor,\n strict: boolean,\n): Anchor | undefined {\n if (edits.size === 0) return block;\n const range = parseSource(block.source);\n if (range === undefined) return block;\n const edit = edits.get(range.path);\n let source = block.source;\n if (edit !== undefined) {\n const lines: number[] = [];\n for (let line = range.first; line <= range.last; line++) {\n const moved = shiftLine(edit.hunks, line, edit.sides);\n if (moved === undefined || moved.replaced) {\n if (strict) return undefined;\n if (moved === undefined) continue;\n }\n lines.push(moved.line);\n }\n if (lines.length === 0) return undefined;\n const colon = block.source.lastIndexOf(\":\");\n source = `${block.source.slice(0, colon)}:${Math.min(...lines)}-${Math.max(...lines)}`;\n }\n const via: string[] = [];\n for (const include of block.via) {\n const at = parseInclude(include);\n const includeEdit = at && edits.get(at.path);\n if (!at || !includeEdit) {\n via.push(include);\n continue;\n }\n const moved = shiftLine(includeEdit.hunks, at.line, includeEdit.sides);\n if (moved === undefined || (strict && moved.replaced)) return undefined;\n via.push(`${include.slice(0, include.lastIndexOf(\":\"))}:${moved.line}`);\n }\n return { source, via };\n}\n\n/** An include, `<path>:<line>`, parsed, with its path decoded. */\nfunction parseInclude(include: string): { path: string; line: number } | undefined {\n const colon = include.lastIndexOf(\":\");\n const line = Number(include.slice(colon + 1));\n if (colon <= 0 || !Number.isInteger(line) || line < 1) return undefined;\n const range = parseSource(`${include.slice(0, colon)}:1-1`);\n return range && { path: range.path, line };\n}\n\n/** The anchor `anchorKey` wrote. */\nfunction fromKey(key: string): Anchor {\n const [source = \"\", ...via] = key.split(\" \");\n return { source, via };\n}\n\n/**\n * The changed pages that show a file (a content path): the file's own page,\n * and the pages that changed through it (an include). `[]` when none does.\n */\nexport function pagesShowing(\n file: string,\n pages: readonly ChangedPageRef[],\n): { path: string; title: string | null; formatted_title: FormattedPiece[] | null }[] {\n return pages\n .filter((page) => page.status !== \"removed\")\n .filter((page) => page.path === file || page.because.includes(file))\n .sort((a, b) => Number(b.path === file) - Number(a.path === file))\n .map((page) => ({\n path: page.path,\n title: page.title ?? null,\n formatted_title: page.formatted_title ? [...page.formatted_title] : null,\n }));\n}\n\n/**\n * The git revision to compare with for a pull request's base: the remote\n * branch, from the remote whose URL is the pull request's repository, when\n * there is one; else the branch's name.\n */\nexport function pullRequestBase(\n remotes: readonly { name: string; repository: string | undefined }[],\n repository: string,\n baseRefName: string,\n): string {\n const remote =\n remotes.find((r) => r.repository === repository && r.name === \"upstream\") ??\n remotes.find((r) => r.repository === repository && r.name === \"origin\") ??\n remotes.find((r) => r.repository === repository);\n return remote ? `${remote.name}/${baseRefName}` : baseRefName;\n}\n\n/**\n * The git revision for the pull request's base in the checkout at `root`:\n * `origin/main` when that remote branch exists, else the branch's name.\n */\nexport async function baseRevision(root: string, pr: PullRequestInfo): Promise<string> {\n const out = (await gitMaybe(root, [\"remote\", \"-v\"]).catch(() => undefined)) ?? \"\";\n const remotes = out\n .split(\"\\n\")\n .map((line) => /^(\\S+)\\s+(\\S+)\\s+\\(fetch\\)$/.exec(line))\n .filter((match) => match !== null)\n .map((match) => {\n const repository = parseRemote(match[2] ?? \"\");\n return { name: match[1] ?? \"\", repository: repository && repoKey(repository) };\n });\n const revision = pullRequestBase(remotes, repoKey(pr.repository), pr.baseRefName);\n if (revision !== pr.baseRefName) {\n const exists = await gitMaybe(root, [\"rev-parse\", \"--verify\", \"--quiet\", revision]).catch(\n () => undefined,\n );\n if (exists !== undefined) return revision;\n }\n return pr.baseRefName;\n}\n\nfunction repoKey(repository: { host: string; owner: string; name: string }): string {\n return `${repository.host}/${repository.owner}/${repository.name}`.toLowerCase();\n}\n\nconst EVENTS: readonly ReviewEvent[] = [\"COMMENT\", \"APPROVE\", \"REQUEST_CHANGES\"];\n\nfunction event(value: unknown): ReviewEvent {\n if (EVENTS.includes(value as ReviewEvent)) return value as ReviewEvent;\n throw new ReviewError(\"refused\", `A review can't be submitted as ${String(value)}.`);\n}\n\nfunction text(value: unknown): string {\n if (typeof value !== \"string\") throw new ReviewError(\"refused\", \"The request is missing text.\");\n return value;\n}\n\nfunction anchor(value: unknown): Anchor {\n const record = value as Partial<Anchor> | null;\n if (typeof record?.source !== \"string\") {\n throw new ReviewError(\"refused\", \"The request is missing a block.\");\n }\n const via = Array.isArray(record.via) ? record.via.filter((v) => typeof v === \"string\") : [];\n return { source: record.source, via };\n}\n\nfunction anchors(value: unknown): Anchor[] {\n return Array.isArray(value) ? value.map(anchor) : [];\n}\n"]}
|
package/dist/marks/index.d.ts
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
/** The words that differ inside a changed block of prose. */
|
|
7
|
-
export interface Words {
|
|
8
|
-
/** `[start, end)` ranges, in characters, of `now_text`. */
|
|
9
|
-
now: [number, number][];
|
|
10
|
-
/** `[start, end)` ranges, in characters, of `was_text`. */
|
|
11
|
-
was: [number, number][];
|
|
12
|
-
now_text: string;
|
|
13
|
-
was_text: string;
|
|
14
|
-
}
|
|
15
|
-
/** One block's change, as `ascribe diff --format json` writes it. */
|
|
16
|
-
export interface Change {
|
|
17
|
-
kind: "changed" | "added" | "removed" | "moved";
|
|
18
|
-
now?: Anchor;
|
|
19
|
-
was?: Anchor;
|
|
20
|
-
words?: Words;
|
|
21
|
-
after?: Anchor;
|
|
22
|
-
parent?: Anchor;
|
|
23
|
-
text?: string;
|
|
24
|
-
}
|
|
1
|
+
import type { Anchor, Change } from "../shapes.js";
|
|
2
|
+
/** A block's change, where it's written, and its words, as `ascribe diff --format json` writes them. */
|
|
3
|
+
export type { Anchor, Change, Words } from "../shapes.js";
|
|
4
|
+
export { titleNodes, type FormattedPiece, type PieceKind } from "./title.js";
|
|
25
5
|
/** What the page shows: its changes, the page as it will be, or as it was. */
|
|
26
6
|
export type Show = "changes" | "will" | "was";
|
|
27
7
|
export interface MarkOptions {
|