-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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.