Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating comment on new code #365

Closed
3 tasks done
tcordel opened this issue Sep 12, 2024 · 8 comments
Closed
3 tasks done

Error creating comment on new code #365

tcordel opened this issue Sep 12, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@tcordel
Copy link

tcordel commented Sep 12, 2024

Hi, i'm facing this issue, maybe it can be fixed but i'm feeling a bit lost.
Maybe you may help me :)

Prerequsities

  • 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({
      log_path = vim.fn.stdpath("cache") .. "/gitlab.nvim.log", -- Log path for the Go server
      debug = { go_request = true, go_response = true }, -- Which values to log
      reviewer_settings = {
        diffview = {
          imply_local = true, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen|
        },
      },
      connection_settings = {
        insecure = true, -- Like curl's --insecure option, ignore bad x509 certificates on connection
      },
    })

Bug Description

Failed to post comment for new code:

image

Reproduction Steps

  1. Check out the feature branch
  2. Open Neovim
  3. start a review
  4. comment on new code

Screenshots

-- REQUEST --
POST /api/v4/projects/832/merge_requests/1167/discussions HTTP/1.1
Host: srv-git
Accept: application/json
Content-Type: application/json
Private-Token: REDACTED
User-Agent: go-gitlab

{"body":"","position":{"base_sha":"71edb6a3b0b3224e394d3de04f7e09851f4a4614","head_sha":"85a3b01ce6382c64cf8ecbd605e67ea3d226d702","start_sha":"71edb6a3b0b3224e394d3de04f7e09851f4a4614","new_path":"eie-front/src/main/app/src/api/StudioResourceService.ts","old_path":"eie-front/src/main/app/src/api/StudioResourceService.ts","position_type":"text","new_line":13,"old_line":1}}

-- RESPONSE --
HTTP/1.1 400 Bad Request
Content-Length: 131
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
Date: Thu, 12 Sep 2024 06:39:38 GMT
Server: nginx
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Gitlab-Meta: {"correlation_id":"01J7JFAXXG1JM5FHEX59RGNPKN","version":"1"}
X-Request-Id: 01J7JFAXXG1JM5FHEX59RGNPKN
X-Runtime: 0.098378

{"message":"400 Bad request - Note {:note=>[\"can't be blank\"], :line_code=>[\"can't be blank\", \"must be a valid line code\"]}"}

thanks!

@harrisoncramer harrisoncramer added the bug Something isn't working label Sep 12, 2024
@harrisoncramer
Copy link
Owner

harrisoncramer commented Sep 13, 2024

Hello,

I'm not fully able to replicate your problem with what you've provided.

It seems from your issue description that you're trying to make a comment on an entirely new file, is that right? This works for me, but my payload to Gitlab looks pretty different from yours:

{
  "body": "Some comment",
  "position": {
    "base_sha": "e8a1d2dca7db01e3a2302d767e50587b3172f1cc",
    "head_sha": "e2d75ecc0dc351fc6a5f7bba04bf1d3bc2766fe2",
    "start_sha": "e8a1d2dca7db01e3a2302d767e50587b3172f1cc",
    "new_path": "new-file.txt",
    "old_path": "new-file.txt",
    "position_type": "text",
    "new_line": 1,
    "line_range": {
      "start": {
        "line_code": "2f95178383a678e9b374564a79ba273396494739_0_1",
        "type": "new"
      },
      "end": {
        "line_code": "2f95178383a678e9b374564a79ba273396494739_0_1",
        "type": "new"
      }
    }
  }
}

Specifically, your payload looks like it's missing two different pieces: The actual content of the note, and the line code.

  1. The content missing makes me think that you didn't actually type anything into the note. Gitlab doesn't allow that.
  2. I'm not sure why the line code is missing, but it may be related.
demo.mov

@harrisoncramer
Copy link
Owner

Ohhhh....

I'm seeing potentially what's happening, are you trying to make a comment on the file tree? That's not how the plugin works, when leaving comments (code-linked comments) you're supposed to leave them on the code itself, like in Gitlab, not the file tree. Is that what's happening here?

I'm able to replicate your error by doing this.

@jakubbortlik
Copy link
Collaborator

Hi. I've noticed something similar - a comment on the code was refused with the same error (invalid line code), but since it was in a real MR, I couldn't really experiment with it in order to debug this. Now when I create a comment on a new file in a testing repo, the command works as expected.

Could you, @tcordel, provide more information, such as:

  • the exact way how you create the comment (e.g., you use a default keymap or your own, or you run lua require("gitlab").create_comment().
  • What is the context in the file which this happens? Does it happen on all lines?
  • what is the exact version of gitlab.nvim you are on?

@harrisoncramer
Copy link
Owner

@jakubbortlik Please see this MR, this particular error occurs when attempting to leave a comment in the file tree or the discussion tree, which were not intended to support line-specific comments.

#369

@jakubbortlik
Copy link
Collaborator

@jakubbortlik Please see this MR, this particular error occurs when attempting to leave a comment in the file tree or the discussion tree, which were not intended to support line-specific comments.

#369

I see, that's nice. But I still think I was experiencing the problem of not being able to create a comment on added code just a few days ago (that means, on a recent version of the plugin), but I was not able at the moment to debug it.

@tcordel
Copy link
Author

tcordel commented Sep 16, 2024

Hi,

Sorry for the delay, i'm trying to investigate on my own to report efficient feedback...

I don't think i misuse shortcuts:

  • plugin was working fine till recently, but in order to answer here is a list of action i executed to reproduce the defect:
    • checkout a branch on which a MR has been initialized threw gitlab
    • open nvim
    • start a review: lua require("gitlab").review()
    • create a comment: lua require("gitlab").create_comment()
    • add content: insert mode, writing stuff, esc
    • submit note (default keymap ZZ, sorry, i'm a bit lazy to fetch for appropriate fun)

Note: On some of my project this routine works. It seems non-working for multi-modules projects...

I'll try to investigate on the plugin (adding logs) to have a better understanding.

@harrisoncramer
Copy link
Owner

I've figured out the issue and it's addressed in #378

Apologies! I'll merge this into develop/main right away, this was caused by a recent refactor to the Go codebase.

@tcordel
Copy link
Author

tcordel commented Sep 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants