Refactor collaborator permission fetch to use unified response-body guards#8957
Merged
Conversation
6 tasks
Copilot
AI
changed the title
[WIP] Remove redundant nil-response guards before httputil.ReadResponseBody
Refactor collaborator permission fetch to use unified response-body guards
Jul 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors FetchCollaboratorPermission to rely on the shared httputil.ReadResponseBody helper for response/body validation and HTTP error handling, eliminating redundant caller-side guards and standardizing error messages for GitHub collaborator permission fetches.
Changes:
- Removed redundant
resp == nil/resp.Body == nilchecks fromFetchCollaboratorPermission, delegating tohttputil.ReadResponseBody. - Updated the helper context string to
"GitHub collaborator API"so returned errors are operation-specific. - Updated unit test assertions to match the new error message prefixes.
Show a summary per file
| File | Description |
|---|---|
| internal/githubhttp/collaborator.go | Removes duplicate response/body guards and switches ReadResponseBody context to collaborator-specific wording. |
| internal/githubhttp/collaborator_test.go | Aligns error-message assertions with the new context-driven ReadResponseBody error strings. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FetchCollaboratorPermissionduplicated nil-response / nil-body checks that are already implemented inhttputil.ReadResponseBody, creating dead code and divergent error paths. This change removes the redundant caller-side guards and standardizes error handling through the shared helper.Response handling cleanup
resp == nilandresp.Body == nilchecks ininternal/githubhttp/collaborator.go.httputil.ReadResponseBody.Error context normalization
"GitHub API"to"GitHub collaborator API"so delegated errors remain operation-specific without custom guard logic.Test expectation alignment
internal/githubhttp/collaborator_test.goassertions to match the new authoritative error messages emitted byReadResponseBody.Related pattern audit
internal/githubhttp/visibility.gofor the same duplicate guard pattern; no equivalent pre-check duplication was found.