Script to upload PR images to Forgejo #102

Merged
crowmaki merged 1 commit from tools/pr-image-uploads into main 2026-10-08 21:47:45 +00:00
Owner

fj can't upload attachments, so PRs with UI changes had no way to include screenshots from the CLI. This adds a small script for that. It has no dependencies.

What changed

  • scripts/pr-images.mjs:
    • Uploads images to a PR's attachments (POST /repos/{repo}/issues/{n}/assets). It then points every ![alt](<file name>) link in the PR body at the uploaded file.
    • Appends images the body doesn't mention under ## Screenshots, with the file name as alt text. A second run replaces those images instead of appending duplicates.
    • Takes the host and repo from origin by default. --host and --repo override them.
    • Reads the token only from FORGEJO_TOKEN, never from fj's key store.
    • --dry-run reads the PR and prints the new body without uploading or editing anything.
  • scripts/pr-images.test.mjs: unit tests for parsing remotes and for rewriting links. bun run test now runs src and scripts.
  • docs/agents/issue-tracker.md: a new "Images in a pull request" section explains the workflow. It also says the user supplies the token.

Usage

FORGEJO_TOKEN=<token> node scripts/pr-images.mjs 101 1-edit.png 2-edited.png

Tests

  • bun run test passes: 5 tests for the script, and the full src suite.
  • I ran the script against a local mock Forgejo server. It sends one multipart upload per image, with the right file name and image/png part type, then PATCHes the body with the links replaced.
  • A --dry-run against #101 finds and would replace all four of its image links.
  • It has not yet run against the real Forgejo with a token.
`fj` can't upload attachments, so PRs with UI changes had no way to include screenshots from the CLI. This adds a small script for that. It has no dependencies. ## What changed - **`scripts/pr-images.mjs`**: - Uploads images to a PR's attachments (`POST /repos/{repo}/issues/{n}/assets`). It then points every `![alt](<file name>)` link in the PR body at the uploaded file. - Appends images the body doesn't mention under `## Screenshots`, with the file name as alt text. A second run replaces those images instead of appending duplicates. - Takes the host and repo from `origin` by default. `--host` and `--repo` override them. - Reads the token only from `FORGEJO_TOKEN`, never from `fj`'s key store. - `--dry-run` reads the PR and prints the new body without uploading or editing anything. - **`scripts/pr-images.test.mjs`**: unit tests for parsing remotes and for rewriting links. `bun run test` now runs `src` and `scripts`. - **`docs/agents/issue-tracker.md`**: a new "Images in a pull request" section explains the workflow. It also says the user supplies the token. ## Usage ```bash FORGEJO_TOKEN=<token> node scripts/pr-images.mjs 101 1-edit.png 2-edited.png ``` ## Tests - `bun run test` passes: 5 tests for the script, and the full `src` suite. - I ran the script against a local mock Forgejo server. It sends one multipart upload per image, with the right file name and `image/png` part type, then PATCHes the body with the links replaced. - A `--dry-run` against #101 finds and would replace all four of its image links. - It has not yet run against the real Forgejo with a token.
fj cannot upload attachments. scripts/pr-images.mjs uploads images to a
PR's attachments and points the body's bare file-name image links at
them, appending any the body does not mention. The token comes from
FORGEJO_TOKEN.
crowmaki deleted branch tools/pr-image-uploads 2026-10-08 21:47:45 +00:00
Sign in to join this conversation.
No description provided.