Skip to content

fix(gh): don't send empty array as review input body - #2958

Open
ccarvalho-eng wants to merge 1 commit into
folke:mainfrom
ccarvalho-eng:fix/gh-start-review-empty-input
Open

ccarvalho-eng wants to merge 1 commit into
folke:mainfrom
ccarvalho-eng:fix/gh-start-review-empty-input

Conversation

@ccarvalho-eng

Copy link
Copy Markdown

gh_start_review and other gh actions build their --input body as a Lua table, e.g. { commit_id = item.headRefOid }. When that field is nil (for example when item.headRefOid hasn't loaded yet, since it's only populated by the PR view field set, not the list fields used for picker rows), the table collapses to an empty Lua table.

vim.json.encode({}) serializes an empty Lua table as [], since Lua has no way to distinguish an empty array from an empty object. gh api then sends [] as the request body, and GitHub rejects it with a 422 for endpoints that require a JSON object, such as POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews.

This fixes the single choke point where all gh action inputs get encoded (M.request in lua/snacks/gh/api.lua), forcing an empty input table to encode as {} via vim.empty_dict() instead of []. commit_id being absent is valid per the GitHub API — it defaults to the PR's current head commit — so this also means "start review" now works correctly even when invoked before the preview has loaded.

No behavior change for non-empty inputs.

vim.json.encode({}) serializes an empty Lua table as [], since Lua
can't distinguish an empty array from an empty object. gh api then
sends [] as the request body for actions like starting a PR review
when the input table ends up empty (e.g. gh_start_review when
item.headRefOid hasn't loaded yet), which GitHub rejects with a 422
since the endpoint requires a JSON object.

Force empty input tables to encode as {} instead, using
vim.empty_dict() as the marker.
@github-actions github-actions Bot added the size/s Small PR (<10 lines changed) label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s Small PR (<10 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant