xanzy / go-gitlab

GitLab Go SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returning 308 Redirect on Merge Request Update

harrisoncramer opened this issue · comments

Hello, thank you for the great library!

I'm attempting to PUT to a merge request via the UpdateMergeRequest function but am getting a 308 redirect response which I think is preventing me from making the PUT. This seems quite similar to another issue from a few years ago: #523

This request works via Curl, for instance like this:

curl --location --request PUT 'https://www.gitlab.com/api/v4/projects/45056707/merge_requests/9' \
--header 'PRIVATE-TOKEN: MY_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
    "description": "This is a new description"
}'

Is there something that I need to do to configure the client to allow it to follow these redirects? I'm initializing the client like this:

client, err := gitlab.NewClient(authToken, gitlab.WithBaseURL("https://www.gitlab.com/api/v4"), gitlab.WithCustomLogger(l))

And the call is pretty straightforward:

mergeRequestOptions := gitlab.UpdateMergeRequestOptions{
    Description: gitlab.String("Some description"),
}

_, res, err := client.UpdateMergeRequest(c.projectId, c.mergeId, &mergeRequestOptions)

EDIT: This seems to be happening because I'm using gitlab.withBaseURL when initializing the client. Is there some way for me to configure the client with a a custom base URL that doesn't cause this issue?

This is using v0.83.0

@harrisoncramer ,

This library appends /api/v4 internally for each call. So in your case, final url for api would've been https://www.gitlab.com/api/v4/api/v4/.....

Can you try with setting url to just https://www.gitlab.com instead?

You don't need to set a base URL when using gitlab.com. That is only needed when you want to use a private GitLab server.

Got it, that makes sense.

By the way, I'm building a Gitlab client for Neovim on top of this library, if anyone would like to contribute. I'll make a note in that repository's README that you should not pass in a base URL unless you are using a self-hosted instance of Gitlab.