Skip to content

feat: rich GitHub previews: state, highlighted code, diff stats and authors - #193

Open
DirkHoffman wants to merge 1 commit into
dev-null-sh:productionfrom
DirkHoffman:feat/github-preview-extras
Open

DirkHoffman wants to merge 1 commit into
dev-null-sh:productionfrom
DirkHoffman:feat/github-preview-extras

Conversation

@DirkHoffman

@DirkHoffman DirkHoffman commented Oct 16, 2026 •

Copy link
Copy Markdown

feat: rich GitHub previews: state, highlighted code, diff stats and authors

Builds on the link previews from #73 and the highlighting from #124: links to GitHub now get a preview from GitHub's API.

Supersedes #36. The feedback there was right: we should never call GitHub while someone is clicking through the app. So GitHub is now asked once, when the commit is created, as suggested. With production moving this fast it was cleaner to start a fresh PR than to rework #36.

1-posting-a-commit.webm
2-scrolling-the-log.webm

Examples

Pull request (owner/repo#14 or a /pull/14 link): title, open / closed / merged, author and size.
example-1-pull-request

Issue: title, open / closed and author.
example-2-issue

Lines of code (/blob/<ref>/<file>#L 50-L61): the lines themselves (at most 12), highlighted like code blocks in commits (#124).
example-3-code

Commit
(owner/repo@42faad4 or a /commit/ link): message, author and size.
example-4-commit

Release: name, released.
example-5-release

Repository: description, stars and language.
example-6-repository

Author on devnull: their name links to their devnull profile.
example-7-author-on-devnull

Unknown reference: still a link, but no card.
example-8-no-card-or-link

Not a reference: a plain owner/repo or and/or isn't linked.
example-9-not-a-link

Dark mode:
3-dark-mode

How

UpdateLinkPreview (run by the existing UnfurlLink job when the commit is created) asks App\Services\GitHubPreviews instead of fetching the page, and stores the result in a new github column on link_previews. One API call per unique link (two for an issue number that turns out to be a pull request), none while rendering, and large commits and files aren't downloaded in full. Server errors and rate limits are retried, like other link previews (#160). Code is highlighted when shown, like code blocks in commits. UpdateUserSshKeys and this share one API client (App\Services\GitHub, OAuth app auth).

Note: the state is a snapshot from when the commit was posted.

Tests cover every link type, the shorthands, code ranges and languages, escaping in highlighted code, bots, unknown references, and retrying on server errors and rate limits. Changed files have 100% coverage.

@DirkHoffman
DirkHoffman marked this pull request as ready for review October 16, 2026 10:41
@DirkHoffman
DirkHoffman force-pushed the feat/github-preview-extras branch 3 times, most recently from ca4f0b5 to bf1a463 Compare October 16, 2026 12:53
…uthors

Links to GitHub now get a preview built from GitHub's API instead of the
page's Open Graph tags, fetched once by the UnfurlLink job when the commit
is created:

- Pull requests and issues: title, open / closed / merged, author, and the
  size of a pull request (+48 -3).
- Lines of code (blob/<ref>/<path>#L10-L20): the lines themselves, at most 12,
  highlighted with the same highlighter and theme as code blocks in commits.
- Commits: message, author and size. Releases: name. Repositories:
  description, stars and language.
- Authors link to their devnull profile when they are on devnull too.

GitHub's shorthands, owner/repo#123 and owner/repo@sha, become links too.
@DirkHoffman
DirkHoffman force-pushed the feat/github-preview-extras branch from bf1a463 to b5f4c0b Compare October 16, 2026 16:47
@xHeaven

xHeaven commented Oct 18, 2026

Copy link
Copy Markdown
Member

@nunomaduro This PR touches database migrations and new services. Could you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants