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

The Position model does not fully encapsulate all the information it needs or has

Open BuzMack opened this issue 5 years ago • 1 comments

The Position model used with Notes and Discussions only covers position_type of "image", does not encapsulate the additional information required for position_type "text". Details from: https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread

Fully encapsulated by Position:

position[base_sha]
position[start_sha]
position[head_sha]
position[position_type]
position[new_path]
position[new_line]
position[old_path]
position[old_line]
position[width]
position[height]
position[x]
position[y]

Missed:

position[line_range]
position[line_range][start]
position[line_range][start][line_code]
position[line_range][start][type]
position[line_range][end]
position[line_range][end][line_code]
position[line_range][end][type]

Perfect example is from DiscussionsApi which completely misses the second block noted above:

    public Discussion createMergeRequestDiscussion(Object projectIdOrPath, Integer mergeRequestIid,
            String body, Date createdAt, String positionHash, Position position) throws GitLabApiException {

        GitLabApiForm formData = new GitLabApiForm()
                .withParam("body", body, true)
                .withParam("created_at", createdAt)
                .withParam("position", positionHash);

        if (position != null) {
            formData.withParam("position[base_sha]", position.getBaseSha(), true)
                .withParam("position[start_sha]", position.getStartSha(), true)
                .withParam("position[head_sha]", position.getHeadSha(), true)
                .withParam("position[position_type]", position.getPositionType(), true)
                .withParam("position[new_path]", position.getNewPath())
                .withParam("position[new_line]", position.getNewLine())
                .withParam("position[old_path]", position.getOldPath())
                .withParam("position[old_line]", position.getOldLine())
                .withParam("position[width]", position.getWidth())
                .withParam("position[height]", position.getHeight())
                .withParam("position[x]", position.getX())
                .withParam("position[y]", position.getY());
        }

        Response response = post(Response.Status.CREATED, formData,
                "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "discussions");
        return (response.readEntity(Discussion.class));
    }

BuzMack avatar Aug 25 '20 23:08 BuzMack

Yes, this would helpful for my autograding-gitlab-action as well. Currently warnings in student assignments are highlighted in the diff at the line start position only. It would be much better if multi-line comments would be available via API as well.

uhafner avatar May 27 '25 11:05 uhafner