Skip to content

choose_merge_request() fails with "Could not parse JSON request body" when called without arguments #553

@Cliffback

Description

@Cliffback

Description:

Prerequisites

  • I'm on the latest version of the plugin
  • I've installed the required dependencies
  • I've run :h gitlab.nvim.troubleshooting and followed the steps there

Setup Configuration and Environment

require("gitlab").setup()

Using .gitlab.nvim file with auth_token and gitlab_url for a self-hosted GitLab instance.

Bug Description

Calling choose_merge_request() without arguments (e.g. via the default glc keybinding) fails with:

Could not parse JSON request body: json: cannot unmarshal array into Go value of type gitlab.ListProjectMergeRequestsOptions

The cause is in lua/gitlab/state.lua line 565 - the merge_requests dependency's body function returns opts or {}. In Lua, an empty table {} with no string keys is encoded by vim.json.encode as a JSON array [], but the Go server expects a JSON object {}.

Calling with an explicit option works: :lua require("gitlab").choose_merge_request({ state = "opened" }).

Fix: Change return opts or {} to return opts or vim.empty_dict() in lua/gitlab/state.lua line 565. vim.empty_dict() ensures the value is encoded as a JSON object.

Reproduction Steps

  1. Open Neovim in a GitLab project directory with a valid .gitlab.nvim config
  2. Press glc or run :lua require("gitlab").choose_merge_request()
  3. Observe error: "Could not parse JSON request body"

Screenshots

Server log showing the issue:

-- REQUEST TO GO SERVER --
POST /merge_requests HTTP/1.1
...
[]
-- RESPONSE FROM GO SERVER --
HTTP/0.0 400 Bad Request
...
{"message":"Could not parse JSON request body","details":"json: cannot unmarshal array into Go value of type gitlab.ListProjectMergeRequestsOptions"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions