jdalrymple / gitbeaker

🦊🧪 A comprehensive and typed Gitlab SDK for Node.js, Browsers, Deno and CLI
Other
1.55k stars 295 forks source link

MergeRequestDiscussions.create Request-URI Too Large #3478

Closed JordiVanOs closed 10 months ago

JordiVanOs commented 10 months ago

Description

The following API usage results in an Request-URI Too Large error:

MergeRequestDiscussions.create(projectId, mergeRequestId, body);
// Error: Request-URI Too Large
//     at throwFailedRequestError ([...]/@gitbeaker/rest/dist/index.js:75:9)

Steps to reproduce

  1. Create a Gitlab API instance with the host set to https://gitlab.com/api and a valid API token
  2. Call MergeRequestDiscussions.create with a body of containing more than 10000 characters
  3. See error

Expected behaviour

To have not resulted in an error, since the character limit seems to be way higher than 10k (I can manually place a comment with 610k characters).

Actual behaviour

An Request-URI Too Large error

Possible fixes

The request sent to Gitlab's REST API seems to append the body as a URI parameter, instead of sending it as an actual JSON body. Rewriting my code using the fetch API fixes this issue for me:

async createMergeRequestDiscussion(projectId: string, mergeRequestId: number, body: string) {
    await fetch(path.join(this.api.url, `/projects/${projectId}/merge_requests/${mergeRequestId}/discussions`), {
        method: 'POST',
        headers: {
            'PRIVATE-TOKEN': process.env.GITLAB_TOKEN!!,
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({body})
    });
}

Checklist

jdalrymple commented 10 months ago

:rocket: Issue was released in 39.26.0 :rocket: