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

branch.getProtection() fails with an exception for ruleset-protected branch #2062

Open
Haarolean opened this issue Mar 16, 2025 · 0 comments
Labels

Comments

@Haarolean
Copy link
Contributor

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.

@bitwiseman bitwiseman added the bug label Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants