Skip to content

Refactor collaborator permission fetch to use unified response-body guards#8957

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-removal
Jul 8, 2026
Merged

Refactor collaborator permission fetch to use unified response-body guards#8957
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-removal

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

FetchCollaboratorPermission duplicated nil-response / nil-body checks that are already implemented in httputil.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

    • Removed manual resp == nil and resp.Body == nil checks in internal/githubhttp/collaborator.go.
    • Delegated all response/body validation to httputil.ReadResponseBody.
  • Error context normalization

    • Updated helper context from "GitHub API" to "GitHub collaborator API" so delegated errors remain operation-specific without custom guard logic.
  • Test expectation alignment

    • Updated internal/githubhttp/collaborator_test.go assertions to match the new authoritative error messages emitted by ReadResponseBody.
  • Related pattern audit

    • Reviewed internal/githubhttp/visibility.go for the same duplicate guard pattern; no equivalent pre-check duplication was found.
// before
if resp == nil {
    return nil, fmt.Errorf("failed to fetch response: nil response returned without error")
}
if resp.Body == nil {
    return nil, fmt.Errorf("failed to fetch response: response body is nil")
}
body, err := httputil.ReadResponseBody(resp, "GitHub API")

// after
body, err := httputil.ReadResponseBody(resp, "GitHub collaborator API")

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
Copilot finished work on behalf of lpcox July 8, 2026 17:14
Copilot AI requested a review from lpcox July 8, 2026 17:14
@lpcox lpcox marked this pull request as ready for review July 8, 2026 17:17
Copilot AI review requested due to automatic review settings July 8, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 == nil checks from FetchCollaboratorPermission, delegating to httputil.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

Comment thread internal/githubhttp/collaborator.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit 7dd0187 into main Jul 8, 2026
23 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-removal branch July 8, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Redundant Nil-Response Guards Before httputil.ReadResponseBody

3 participants