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

GHBranchProtection::RequiredReviews.getRequiredReviewers() always return 0 #890

Closed
liangzhang10748 opened this issue Jul 13, 2020 · 2 comments · Fixed by #895
Closed

GHBranchProtection::RequiredReviews.getRequiredReviewers() always return 0 #890

liangzhang10748 opened this issue Jul 13, 2020 · 2 comments · Fixed by #895

Comments

@liangzhang10748
Copy link

Describe the bug
When running the API with owner privilege, it does not seem to work properly and always return 0 regardless of what the actual required approving required is set to.

To Reproduce
Steps to reproduce the behavior:
To reproduce the problem.

  1. As a repo owner, enable Branch Protection and configure required approving required to 1 or more
  2. Use repo owner token to log in and run the following code with Owner privilege on github,

GHRepository ghrepo = github.getRepository(repo);
GHBranch ghbranch = ghrepo.getBranch(branch);
GHBranchProtection protection = ghbranch.getProtection();
RequiredReviews requiredReviews = protection.getRequiredReviews();
int reviewers = requiredReviews.getRequiredReviewers();

The call succeeded without exception, but reviewers is always 0

Expected behavior
The API should return the actual required approving review numbers as configured in github repository

Desktop (please complete the following information):

  • OS: Centos 7
  • Version: github-api v1.113

Additional context
I suspect request heading is not configured correctly when trying to retrieve this property.
According to github api branch protection documentation: https://developer.github.com/v3/repos/branches/#get-branch-protection
A special header "application/vnd.github.luke-cage-preview+json" must be used to retrieve the number of approving pull request. But request builder for GHBranchProtection does not seem to handle it.
This is an existing example on how to handled this in GHBranchProtectionBuilder :
https://github.com/hub4j/github-api/blob/6bc617c488e96ea4e8040b54754f13ec68356bbe/src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java#L355,L357

Please investigate if it can be done for GHBranchProtection as well

@bitwiseman bitwiseman added the bug label Jul 15, 2020
@bitwiseman
Copy link
Member

@liangzhang10748
It sounds like you already have done more of the investigation. Perhaps you could submit a PR with a test that fixes?

@liangzhang10748
Copy link
Author

@bitwiseman Yes. I will follow up in a couple weeks on the fix.

bitwiseman added a commit that referenced this issue Jul 17, 2020
GHBranch getProtection method to return correct number of reviewers #890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants