Skip to content

Comment creation fails on GitLab <= 17.7 #588

Description

@oleynikandrey

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,
 		},
 	}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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