feat(repo): read a raw file at a ref #86
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/repo-file-command"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
fjcould fetch a repository file's raw bytes only for two hardcoded paths (fj repo readmeand the issue-template parser), so a consumer that needs an arbitrary path at an exact commit, such as claude-run'sfetch_workflow_yaml, hand-rolledGET /api/v1/repos/{owner}/{repo}/raw/{path}?ref={commit}instead. The MCP server already exposed the general capability as itsget_raw_filetool; the CLI was the only surface missing it.Add
fj repo file <PATH>, which writes the file's bytes to stdout unchanged (no trailing newline added, so binary files and exact-byte comparisons survive a pipe) and takes--ref <commit|branch|tag>plus the standard--repo/--remote/--hostselectors. Omitting--refresolves the repository's default branch first, so both the JSON output and any error name a concrete ref rather than whatever the API happened to pick. Under--jsonthe command emitspath,ref, andcontent, and fails naming the file when the bytes are not UTF-8 rather than emitting lossy text; raw stdout stays the way to get non-UTF-8 bytes.fj_core::repo::get_raw_filenow maps the raw endpoint's404to an error naming the path, the ref, and the repo, keeping Forgejo's own text as context, because the server answers a missing file, an unresolvable ref, and an out-of-reach repository alike with a bare "not found". Any other error passes through unchanged, and every caller (the new command,repo readme, and the MCP tool) gets the mapped message.Covered by unit tests over the error mapping (missing path with a ref, without a ref, and a non-404 that must pass through), over the clap surface, and over the non-UTF-8 JSON rejection. Verified live against dev.a8n.run reading
.forgejo/workflows/check.ymlfrom the publicpandoras-box/forgejo-cliat a commit sha, a branch, a tag, and the default branch (bytes identical togit show), and from the privateniceguyit/claude-runat an explicit commit sha.#FJ-67
`fj` could fetch a repository file's raw bytes only for two hardcoded paths (`fj repo readme` and the issue-template parser), so a consumer that needs an arbitrary path at an exact commit, such as claude-run's `fetch_workflow_yaml`, hand-rolled `GET /api/v1/repos/{owner}/{repo}/raw/{path}?ref={commit}` instead. The MCP server already exposed the general capability as its `get_raw_file` tool; the CLI was the only surface missing it. Add `fj repo file <PATH>`, which writes the file's bytes to stdout unchanged (no trailing newline added, so binary files and exact-byte comparisons survive a pipe) and takes `--ref <commit|branch|tag>` plus the standard `--repo` / `--remote` / `--host` selectors. Omitting `--ref` resolves the repository's default branch first, so both the JSON output and any error name a concrete ref rather than whatever the API happened to pick. Under `--json` the command emits `path`, `ref`, and `content`, and fails naming the file when the bytes are not UTF-8 rather than emitting lossy text; raw stdout stays the way to get non-UTF-8 bytes. `fj_core::repo::get_raw_file` now maps the raw endpoint's `404` to an error naming the path, the ref, and the repo, keeping Forgejo's own text as context, because the server answers a missing file, an unresolvable ref, and an out-of-reach repository alike with a bare "not found". Any other error passes through unchanged, and every caller (the new command, `repo readme`, and the MCP tool) gets the mapped message. Covered by unit tests over the error mapping (missing path with a ref, without a ref, and a non-404 that must pass through), over the clap surface, and over the non-UTF-8 JSON rejection. Verified live against dev.a8n.run reading `.forgejo/workflows/check.yml` from the public `pandoras-box/forgejo-cli` at a commit sha, a branch, a tag, and the default branch (bytes identical to `git show`), and from the private `niceguyit/claude-run` at an explicit commit sha. #FJ-67