fix(gh): don't send empty array as review input body - #2958
Open
ccarvalho-eng wants to merge 1 commit into
Open
ccarvalho-eng wants to merge 1 commit into
ccarvalho-eng wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gh_start_reviewand other gh actions build their--inputbody as a Lua table, e.g.{ commit_id = item.headRefOid }. When that field is nil (for example whenitem.headRefOidhasn't loaded yet, since it's only populated by the PRviewfield set, not thelistfields 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 apithen sends[]as the request body, and GitHub rejects it with a 422 for endpoints that require a JSON object, such asPOST /repos/{owner}/{repo}/pulls/{pull_number}/reviews.This fixes the single choke point where all gh action inputs get encoded (
M.requestinlua/snacks/gh/api.lua), forcing an empty input table to encode as{}viavim.empty_dict()instead of[].commit_idbeing 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.