Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to update code_owner_approval_required flag to Protected Branches API #870

Merged
merged 4 commits into from
Dec 9, 2022

Conversation

MikeWillCook
Copy link
Contributor

@MikeWillCook MikeWillCook commented Oct 8, 2022

Adds basic support for updating the code_owner_approval_required flag on an existing protected branch. See the GitLab API docs for intended usage.

Two notes for feedback:

  1. The HTTP "PATCH" method isn't supported in the current client so this uses the X-HTTP-Method-Override: PATCH header as a workaround. This wires it thru AbstractApi to GitLabApiClient where it's turned into a POST with the override header. Anyone recommend another way?
  2. Removed the integration test as it's a Premium or higher feature so can't be tested on the Community Edition image. (EDIT: Added this test back with handling for current version.)

Fixes #869

protected Response patch(MultivaluedMap<String, String> queryParams, URL url) {
Entity<?> empty = Entity.text("");
// use "X-HTTP-Method-Override" header on POST to override to unsupported PATCH
return (invocation(url, queryParams)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello thanks for your PR.

I did not check if it works, but I think you can use invocation(url, queryParams).method("PATCH", empty);

Can you try with my proposal ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, @jabby. In fact I tried that first (after not finding a native patch() method) and found it doesn't work with the current client, and instead returns the following exception:

org.gitlab4j.api.GitLabApiException: java.net.ProtocolException: Invalid HTTP method: PATCH

There is some discussion of other workarounds for the underlying bug, but this approach seemed sufficient and less problematic to me. I'm open to pushback on that.

Also, to help in the future and at least exercise the method, I've added a test handling the current tested version with comments on what should happen with Premium.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any other questions on this, @jabby ?

@jabby jabby merged commit f9fbd88 into gitlab4j:master Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Protected Branches API doesn't support updating code_owner_approval_required on existing protected branch
2 participants