Skip to content

feat: fetch images and other attachments from issues and PRs - #121

Merged
c-vigo merged 3 commits into
devfrom
feature/2-sync-attachments
Jul 16, 2026
Merged

c-vigo merged 3 commits into
devfrom
feature/2-sync-attachments

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in sync-attachments input (default false) that downloads attachments (images, videos, files) referenced in issue/PR bodies and comments to <output-dir>/attachments/<uuid>.<ext> and rewrites body URLs to relative paths, so the synced markdown tree is complete offline.

Closes #2 — see the spike results for the investigation behind the mechanism.

How it works

  • Bodies are fetched with the application/vnd.github.full+json media type, so each response carries body_html alongside the raw markdown.
  • In body_html, GitHub has already rewritten every attachment (modern user-attachments/assets/<uuid> and legacy user-images URLs alike) to a pre-signed JWT URL on private-user-images.githubusercontent.com that downloads with plain HTTP — uniformly for public and private repos. The JWT is valid ~5 min, so downloads happen inside the per-item sync loop.
  • Attachments are stored once per asset UUID (free dedup across issues/comments, no path-traversal from attacker-controlled names); both ![...](url) and <img src> forms are rewritten to ../attachments/<uuid>.<ext>.
  • Signed/expiring URLs are never written to disk, so hasContentChanged idempotency is preserved.
  • Failed downloads warn and keep the original URL; the sync never fails on an attachment.
  • Downloaded files are added to modified-files; format-command now receives only markdown files.
  • Non-image file attachments (user-attachments/files/...) are downloaded directly, which works on public repos and may fail on private ones (no signed URL is emitted for them) — documented in the README.

Testing

  • 17 new unit tests (TDD: red commit → green commit) covering extraction, rewrite of all three URL shapes, dedup, skip-if-exists, force-update, failure policy, and run() wiring; 138/138 total pass.
  • End-to-end: ran the built dist/index.js against Bug: bright settings, icons in top bar not visible qx#136 (real attachment) — PNG downloaded byte-identical to a manual fetch, body rewritten to the relative path, and a second run is fully idempotent (no re-download, no rewrite).
  • just precommit, just verify-dist, lint, and tsc all green.

Refs: #2

c-vigo added 3 commits July 16, 2026 18:01
Fetch bodies with the full media type, harvest the short-lived signed
URLs GitHub emits in body_html, download each referenced attachment to
<output-dir>/attachments/<uuid>.<ext>, and rewrite issue/PR/comment
bodies to relative paths so the synced tree is complete offline.
Failed downloads keep the original URL and only warn.

Refs: #2
@c-vigo
c-vigo merged commit bc3f15a into dev Jul 16, 2026
22 checks passed
@c-vigo
c-vigo deleted the feature/2-sync-attachments branch July 16, 2026 16:12
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.

1 participant