Comment creation fails on GitLab <= 17.7

Open Beginner friendly
#588 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
api, backend

Research direction

Start in cmd/app/comment_helpers.go at buildCommentPosition and inspect how LineRangeOptions is assembled for review comments and draft notes. Compare the serialized position with GitLab 17.7's accepted schema, then verify that comment creation no longer returns the 400 validation error.

Written by the indexing model from the issue text.

Description

Posting a review comment / draft note fails with a 400 Bad Request from the GitLab API:

{"message": {"position": ["must be a valid json schema"]}}

Environment

  • gitlab.nvim commit: 80edb27 / f05aee3 (latest)
  • GitLab version: 17.7.1 (self-hosted)

Root Cause
In commit 80edb27 (fix: get correct location data for comments efficiently), OldLine and NewLine were added to opt.LineRange.Start and opt.LineRange.End in cmd/app/comment_helpers.go:

opt.LineRange = &gitlab.LineRangeOptions{
    Start: &gitlab.LinePositionOptions{
        Type:     &positionData.LineRange.Start.Type,
        LineCode: &startFilenameSha,
        OldLine:  &startOldLine,
        NewLine:  &startNewLine,
    },
    ...
}

This causes the Go backend to serialize:

"line_range": {
  "start": {
    "line_code": "...",
    "type": "new",
    "old_line": 0,
    "new_line": 36
  }
}

GitLab's REST API validates position against app/validators/json_schemas/position.json. In GitLab $\le$ 17.7, line_range.start and line_range.end enforce "additionalProperties": false and only permit "line_code" and "type". As a result, including old_line or new_line causes schema validation to fail.

Fix
In cmd/app/comment_helpers.go, keep OldLine and NewLine nil / omitted from LinePositionOptions:

--- a/cmd/app/comment_helpers.go
+++ b/cmd/app/comment_helpers.go
@@ -83,14 +83,10 @@ func buildCommentPosition(commentWithPositionData RequestWithPosition) *gitlab.P
 	opt.LineRange = &gitlab.LineRangeOptions{
 		Start: &gitlab.LinePositionOptions{
 			Type:     &positionData.LineRange.Start.Type,
 			LineCode: &startFilenameSha,
-			OldLine:  &startOldLine,
-			NewLine:  &startNewLine,
 		},
 		End: &gitlab.LinePositionOptions{
 			Type:     &positionData.LineRange.End.Type,
 			LineCode: &endFilenameSha,
-			OldLine:  &endOldLine,
-			NewLine:  &endNewLine,
 		},
 	}
Dominant language
Lua
Stars
401
Forks
62
Avg merge
2d 19h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from harrisoncramer/gitlab.nvim

All issues in harrisoncramer/gitlab.nvim

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.