--- title: Pull request description: A pull request's whole diff in Markdown, grouped by scope, in one block that starts closed. keywords: pull request, code review, git diff, changed files, review guide, scopes, PR evidence tagline: Every file a pull request changes, from its git diff, grouped by what each part does, folded until the reader opens it. --- ::examples :::example{label="Grouped by scope"} ````md ::pull{title="Retry failed uploads" href="https://github.com/acme/app/pull/42" open} :::scope{title="Retry"} An upload that fails tries once more before it reports the error. ```diff diff --git a/src/upload.ts b/src/upload.ts --- a/src/upload.ts +++ b/src/upload.ts @@ -10,5 +10,6 @@ export async function upload(file: File) { const body = new FormData(); body.append("file", file); - const response = await fetch(url, { method: "POST", body }); + const response = await retry(() => fetch(url, { method: "POST", body })); + if (!response.ok) throw new Error(response.statusText); return response.json(); } diff --git a/src/retry.ts b/src/retry.ts new file mode 100644 --- /dev/null +++ b/src/retry.ts @@ -0,0 +1,3 @@ +export async function retry(run: () => Promise) { + return run().catch(() => run()); +} ``` ::: :: ```` ::: :::example{label="Closed"} ````md ::pull{title="Code changes"} ```diff diff --git a/src/limits.ts b/src/limits.ts --- a/src/limits.ts +++ b/src/limits.ts @@ -1,3 +1,3 @@ // How many filters a view keeps. -export const MAX_FILTERS = 3; +export const MAX_FILTERS = 5; export const MAX_SORTS = 2; ``` :: ```` ::: :: ## Features - Paste `git diff` output as it is: every file, hunk, rename, new and deleted file comes out of it. - Each file is highlighted in its own language, with the words that changed between a removed and an added line a shade deeper, as in [Diff](/diff). - The block starts closed, a one-line card with the title and the counts, so a long change doesn't push the rest of the page down. - Open, it reads like a review guide: `:::scope` groups files by what they do together, and each scope opens with a line on why, then shows a tree of its files beside the changes. The tree sizes each file from XS to XL by the lines it changes, so the heavy ones stand out. - Lockfiles, builds, and minified files start closed and aren't highlighted. - One column of line numbers, with a bar marking each added or removed line. Every line carries its file and both line numbers in `data-` attributes, so a host can pin a comment to it. ## Usage Write `::pull` with a ` ```diff ` fence inside, holding the output of `git diff`. ::example ````md ::pull ```diff diff --git a/src/limits.ts b/src/limits.ts --- a/src/limits.ts +++ b/src/limits.ts @@ -1,2 +1,2 @@ -export const MAX_FILTERS = 3; +export const MAX_FILTERS = 5; export const MAX_SORTS = 2; ``` :: ```` :: > [!NOTE] > For a pull request, take the diff against the branch it merges into: `git diff --default-prefix origin/main...HEAD`. Wrap the fence in four backticks when the diff itself holds a fence. ### Title Use the `title` prop to name the change on the closed card. It reads "Code changes" without it. ### Link Use the `href` prop to link the pull request. The link sits beside the counts, as `#42` when the URL ends in a pull or merge request's number, and as the URL otherwise. ### Open Use the `open` prop to start the block open, for a page where the code is the point. ### Scopes Use `:::scope` to split the diff by intent, so a reviewer reads the change one intent at a time. Give each scope a `title` and a line on why its files change, then paste their part of the diff under it. With more than one scope, a row of tabs at the top links to each, with its counts, and names the scope there instead of above its summary. ::example ````md ::pull{open} :::scope{title="Limits"} Views keep five filters instead of three. ```diff diff --git a/src/limits.ts b/src/limits.ts --- a/src/limits.ts +++ b/src/limits.ts @@ -1,2 +1,2 @@ -export const MAX_FILTERS = 3; +export const MAX_FILTERS = 5; export const MAX_SORTS = 2; ``` ::: :: ```` :: Group the files the way [pulls.review](https://pulls.review) does: - A change with a single intent needs no scope: paste its diff straight into `::pull`. - One intent is one scope, even when it spans several folders or modules. - Use the fewest scopes that keep independent intents apart, usually two to five. - Tests, stories, and fixtures get a scope of their own. - Order the scopes the way a reviewer should read them: the core change first, then the changes that support it, then mechanical ones such as lockfiles, generated files, and formatting. - Each file sits in exactly one scope. - Read the intents from the final diff. Commits often mix them. - The `title` names the intent in four words or fewer, and the line under it says why the files change, in one to three sentences. ## Accessibility The block is a native `
`, and so is each file, so a keyboard opens them with Enter or Space and a screen reader hears whether each is expanded. Each file's code scrolls in its own named region, a tab stop. Each scope's tree of files is a named navigation landmark that links to each file, and the row of scopes links to each scope. A file's status letter spells out the status in its `title`, and a file's size in the tree gives its count of changed lines. ### Keyboard interactions | Key | Description | | --- | --- | | `Enter`, `Space` | Opens or closes the focused block or file. | | `Tab` | Moves to the next file, link, or code region. | | `ArrowLeft`, `ArrowRight` | Scrolls a focused code region sideways. | ## API ### Props #### `::pull` | Prop | Default | Description | | --- | --- | --- | | `title` | `Code changes` | The heading on the closed card. | | `href` | — | The pull request's URL, an `http` or `https` link shown beside the counts. | | `open` | `false` | Starts the block open. | #### `:::scope` | Prop | Default | Description | | --- | --- | --- | | `title` | — | What the scope's files do together. Required. | ### Issues The plugin adds every problem to `meta.issues`, as [Validation](/guide/validation) describes: - A `::pull` with no git diff inside. - A code block inside a `::pull` that isn't a git diff. - A `:::scope` with no title, or one outside a `::pull`. - A prop `::pull` or `:::scope` doesn't read. Each kind has its own rule in [Doctor](/doctor). ### Package `comark-diff` draws it. [Diff](/diff#package) installs it alone; add Comark's `shiki` plugin, in any order, to highlight each file. ## Theme The block uses the same tokens and variables as a [Diff](/diff#theme), set on `.cd-pull`. The block has no frame: each file is its own bordered card, and spacing separates the scopes. Added and removed lines take the green and red of [pulls.review](https://pulls.review), in its light and dark shades, as `--cd-green` and `--cd-red`; set those on `.cd-pull` to change them. Below 42rem of width, each scope's tree sits above its files instead of beside them. ### Classes and attributes | Selector | Is | | --- | --- | | `details.cd-pull` | The block | | `.cd-pull-head` | Its summary: the icon, `.cd-title`, and `.cd-meta` with the counts, the file count, and the link | | `.cd-pull-ref` | The pull request's link | | `nav.cd-scopes` | The row of links to each scope, with more than one scope | | `section.cd-scope` | A scope: `.cd-scope-head` with `.cd-scope-summary`, and `.cd-scope-title` when it's the only scope, then `.cd-scope-body` with `nav.cd-tree` and `.cd-files` | | `.cd-tree-row` | A folder in the tree, or a file's link to its changes | | `.cd-size` | A file's size in the tree, XS to XL, in `data-size` as `xs` to `xl` | | `.cd-status` | A file's letter in its head, A, M, D, or R, with the status in `data-status` | | `details.cd-pull-file` | A file, with its path in `data-path` | | `.cd-pull-file-head` | A file's summary: its `.cd-path` with `.cd-dir` and `.cd-name`, its counts, and its `.cd-status` | | `tr.cd-hunk` | Where a hunk starts, with the function git names | | `tr.cd-del`, `tr.cd-add`, `tr.cd-same` | A line, with its line numbers in `data-old` and `data-new`; `.cd-num` shows the old one on a removed line and the new one otherwise | | `.cd-chevron` | The chevron a block or file turns |