gitlab4j-api icon indicating copy to clipboard operation
gitlab4j-api copied to clipboard

Can not create new discussion with getDiscussionsApi().createMergeRequestDiscussion()

Open BuzMack opened this issue 4 years ago • 3 comments

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.

BuzMack avatar Sep 03 '20 20:09 BuzMack

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.

jabby avatar Mar 17 '21 21:03 jabby

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!

yuezhuangshi avatar Mar 18 '21 02:03 yuezhuangshi

Does anyone know how to fix it?

isliudong avatar Feb 06 '23 09:02 isliudong