Repository navigation
Description
When calling the GitHub API endpoint https://api.github.com/repos/OWNER/REPO/branches/BRANCH/protection/required_signatures (documentation), if the branch does not have any protection rules, the GitHub API will reply with a HTTP 404 Not Found code and the following body:
{
"message": "Branch not protected",
"documentation_url": "https://docs.github.com/rest/branches/branch-protection#get-commit-signature-protection"
}
Other functions in go-github that may receive this kind of response usually manage it the following way:
Lines 1347 to 1349 in 96726d8
| if isBranchNotProtected(err) { | |
| err = ErrBranchNotProtected | |
| } |
However, GetSignaturesProtectedBranch does not:
Lines 1405 to 1409 in 96726d8
| resp, err := s.client.Do(ctx, req, p) | |
| if err != nil { | |
| return nil, resp, err | |
| } | |
I think this function should have the same behaviour, allowing callers to handle this case the same way as when calling say GetBranchProtection. Note that function isBranchNotProtected sounds like it would work without changes:
Lines 2033 to 2036 in 96726d8
| func isBranchNotProtected(err error) bool { | |
| errorResponse, ok := err.(*ErrorResponse) | |
| return ok && errorResponse.Message == githubBranchNotProtected | |
| } |
Line 17 in 96726d8
| const githubBranchNotProtected string = "Branch not protected" |
I am happy to provide a Pull Request (should be trivial) for this.
Activity
gmlewis commentedon Jun 28, 2023
@cedricvanrompay-datadog - may I first say that this is one of the best issue messages I have ever read?
It is clear, to the point, and provides all the details needed with examples and a pointer to the problem.
Well done, and thank you very much!
Absolutely, I agree, and the issue is yours. Thanks again!
Not-Dhananjay-Mishra commentedon Jan 4, 2026
@gmlewis Is this issue available? I'd like to work on it.
gmlewis commentedon Jan 4, 2026
Yes, I think we can safely say now that this issue is yours. Thank you, @Not-Dhananjay-Mishra!