Comment creation fails on GitLab <= 17.7
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
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.nvimcommit: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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from harrisoncramer/gitlab.nvim
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
harrisoncramer/gitlab.nvim#585 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 46/100
harrisoncramer/gitlab.nvim#583 · 1 comment ·
-
feature request
Difficulty 4/5 3-5 days Newbie friendliness 35/100
harrisoncramer/gitlab.nvim#516 · 1 comment ·
-
feature request
harrisoncramer/gitlab.nvim#515 · 2 comments · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
harrisoncramer/gitlab.nvim#507 · 1 comment ·
All issues in harrisoncramer/gitlab.nvim
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
api7/lua-resty-saml#62 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
nvim-tree/nvim-tree.lua#3357 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
codymikol/multiverse.nvim#320 ·
-
Data Correction tbc
Difficulty 2/5 1-3 hours Newbie friendliness 68/100