Skip to content

SetAPIBase/GetAPIBase in internal/github/oauth.go are dead code — no production API call in the github package ever reads the apiBase variable they control #356

Description

@Jagadeeshftw

Description

internal/github/oauth.go defines a package-level variable and exported accessor functions explicitly documented as a test seam for redirecting GitHub API calls to a mock server:

// Test helpers to override endpoints for mocking

var apiBase = "https://api.github.com"

// GetAPIBase returns the current API base URL (for tests).
func GetAPIBase() string {
	return apiBase
}

// SetAPIBase sets the API base URL (for tests).
func SetAPIBase(base string) {
	apiBase = base
}

But every actual API call in the package — GetRepo/GetRepoLanguages/GetReadme in repo.go, GetUser/GetUserEmails in api.go, CreateWebhook in webhook.go, AddIssueAssignees/RemoveIssueAssignees in assignees.go, CreateIssueComment/DeleteIssueComment/ListIssueComments in issues_comments.go/list.go, ListIssuesPage/ListPRsPage in list.go — hardcodes the literal string "https://api.github.com" directly rather than reading apiBase or calling GetAPIBase():

// internal/github/repo.go
u := "https://api.github.com/repos/" + url.PathEscape(owner) + "/" + url.PathEscape(repo)

grep-ing the entire codebase (including every test file) confirms apiBase/GetAPIBase/SetAPIBase are referenced only within oauth.go itself, where they're defined — nothing else in the repository ever calls SetAPIBase or reads GetAPIBase(). Its sibling, SetTokenEndpoint/tokenEndpoint, is genuinely wired into ExchangeCode and is used by real tests, which makes SetAPIBase especially misleading by proximity — it looks like the equivalent, working mechanism for redirecting the other ~10 API calls in the package to a mock server, but calling it silently does nothing. Any future test author who reasonably assumes github.SetAPIBase(mockServer.URL) will redirect GetRepo/GetUser/etc. calls to their httptest.Server will get a test that either makes real, uncontrolled network calls to api.github.com or hangs/fails in a confusing way, with no indication SetAPIBase was the reason.

Requirements

  • Either apiBase/GetAPIBase/SetAPIBase must actually control the base URL used by every API call in the package, or the dead accessors must be removed so they stop presenting as a working test seam.

Suggested execution

  1. Preferred: replace every hardcoded "https://api.github.com" literal across repo.go, api.go, webhook.go, assignees.go, issues_comments.go, and list.go with GetAPIBase() (or a helper that reads apiBase), so SetAPIBase actually works as documented.
  2. Add a test that calls SetAPIBase(mockServer.URL) and asserts at least one previously-hardcoded call (e.g. GetRepo) actually hits the mock server, proving the seam is now live — this test would fail against the current code.
  3. Restore apiBase to "https://api.github.com" in a test cleanup/t.Cleanup to avoid cross-test pollution, consistent with how SetTokenEndpoint is already used.

Acceptance criteria

  • SetAPIBase changes the base URL used by all GitHub REST API calls in the package, not just a subset (or none).
  • A test demonstrates SetAPIBase redirecting a real call (e.g. GetRepo) to a mock server.

Guidelines

  • Minimum 95% test coverage
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuebackendBackend / API workbugSomething isn't workingtestingTests and coverage

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions