Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lua/snacks/gh/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ function M.request(cb, opts)
cb(proc, data and data:find("%S") and proc:json() or nil)
end, {
args = args,
input = opts.input and vim.json.encode(opts.input) or nil,
-- `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, which GitHub rejects for endpoints that
-- require a JSON object (e.g. creating a PR review with no fields set).
-- Force empty input tables to encode as `{}` instead.
input = opts.input and vim.json.encode(vim.tbl_isempty(opts.input) and vim.empty_dict() or opts.input)
or nil,
on_error = opts.on_error,
})
end
Expand Down