gitlab4j-api
gitlab4j-api copied to clipboard
Can not create new discussion with getDiscussionsApi().createMergeRequestDiscussion()
GitLab instance in question is running GitLab version 13.2 When I try to create a new discussion using this block of code:
Date createdAt = Date.from(Instant.now());
Discussion mergeRequestDiscussion = gitLabApi.getDiscussionsApi().createMergeRequestDiscussion(
gitLabProjectId,
currentMergeRequestIid,
content,
createdAt,
null,
commentPosition
);
I get this error:
org.gitlab4j.api.GitLabApiException: 400 (Bad request) "Note {:line_code=>["can't be blank", "must be a valid line code"]}" not given
The commentPosition provided is fully populated, but is very obviously incomplete.
I tried today to work with gitLabApi.getDiscussionsApi().createCommitDiscussion()
. There is the same problem as you discovered in gitLabApi.getDiscussionsApi().createMergeRequestDiscussion()
.
After some digging it seems the API is not clear on how to use it properly.
- https://docs.gitlab.com/ce/api/discussions.html#commits
- https://docs.gitlab.com/ce/api/discussions.html#merge-requests
See also the following issues: https://gitlab.com/gitlab-org/gitlab/-/issues/37518 and https://gitlab.com/gitlab-org/gitlab/-/issues/35935 for more information about flaws of the API.
I will not spend more time tonight on this. I will prioritize other part of 4.16.0 milestone first.
After reading docs and gitlab source code, I guess position[line_range]
was missing in gitLabApi.getDiscussionsApi().createMergeRequestDiscussion()
, but not sure.
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/discussions.md#create-new-merge-request-thread
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/api/discussions.rb#L57
Hope it helps!
Does anyone know how to fix it?