github-api
github-api copied to clipboard
`branch.getProtection()` fails with an exception for ruleset-protected branch
Describe the bug
If a branch (GHBranch) is protected via rulesets rather than classic (deprecated?) branch protection rules, GHBranch#isProtected() returns true, but GHBranch#getProtection desintegrates with the following exception:
org.kohsuke.github.GHFileNotFoundException: https://api.github.com/repos/ZooPets/kapybro-demo-dev/branches/main/protection {"message":"Branch not protected","documentation_url":"https://docs.github.com/rest/branches/branch-protection#get-branch-protection","status":"404"}
at org.kohsuke.github.GitHubClient.interpretApiError(GitHubClient.java:661) ~[github-api-unbridged-1.318.jar:na]
at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:480) ~[github-api-unbridged-1.318.jar:na]
at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:427) ~[github-api-unbridged-1.318.jar:na]
at org.kohsuke.github.Requester.fetch(Requester.java:85) ~[github-api-unbridged-1.318.jar:na]
at org.kohsuke.github.GHBranch.getProtection(GHBranch.java:112) ~[github-api-unbridged-1.318.jar:na]
//omitted
Caused by: java.io.FileNotFoundException: https://api.github.com/repos/ZooPets/kapybro-demo-dev/branches/main/protection
at org.kohsuke.github.GitHubConnectorResponseErrorHandler$1.onError(GitHubConnectorResponseErrorHandler.java:60) ~[github-api-unbridged-1.318.jar:na]
at org.kohsuke.github.GitHubClient.detectKnownErrors(GitHubClient.java:504) ~[github-api-unbridged-1.318.jar:na]
at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:464) ~[github-api-unbridged-1.318.jar:na]
... 179 common frames omitted
Most likely, GHBranch#isProtected() will be true for both protection methods, so we need a way to tell them apart without conflating two different methods and later calling wrong endpoints.
Perhaps a temp solution could be introduced until #1811 is implemented.