harrisoncramer / harrisoncramer/gitlab.nvim

Comment creation fails on GitLab <= 17.7

Open Beginner friendly
#588 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Lua
Stars
399
Forks
62
Avg merge
2d 19h
Merged PRs (30d)
2

Description

Posting a review comment / draft note fails with a `400 Bad Request` from the GitLab API:
```json
{"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`:

```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:
```json
"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`:

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

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.