Repository navigation
feat: Refactor new client logic to use base url - #3510
Conversation
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
There was a problem hiding this comment.
Pull request overview
These provider review instructions are being used.
This PR refactors the internal/ghclient package so that all client/source constructors are configured from a single BaseURL (plus an IsGHES flag) instead of separate pre-computed RESTAPIURL/GraphQLURL strings. The Options struct is split into a high-level SourceOptions and a derived per-client ClientOptions, the cache path handling is simplified, and the provider's configureProviderMeta owner/organization resolution is reworked with stronger error handling. The primary user-facing goal is to make GitHub App authentication work against non-github.com targets (GHEC/GHES) by threading the base URL into the installation token source. It also bumps jferrl/go-githubauth to v1.7.0 (which adds WithBaseURL) and substantially expands Test_configureProviderMeta coverage.
Changes:
- Replaced
OptionswithSourceOptions/ClientOptionsand centralized REST/GraphQL option derivation; simplified cache store path construction. - Threaded
BaseURL/IsGHESthrough REST/GraphQL client construction and the App installation token source; reworked provider owner/org lookup error handling. - Bumped
go-githubauthto v1.7.0 and broadened provider-meta unit tests with an httptest-backed table.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/ghclient/options.go | Splits Options into SourceOptions/ClientOptions with derivation helpers |
| internal/ghclient/const.go | Adds REST/GraphQL API path constants for github.com/ghe.com/GHES |
| internal/ghclient/rest.go | Builds REST URL from base URL; passes base URL to installation token source |
| internal/ghclient/graphql.go | Builds GraphQL URL from base URL (installation token source not updated — see finding) |
| internal/ghclient/token.go | Uses SourceOptions and derived client options |
| internal/ghclient/anonymous.go | Uses SourceOptions and derived client options |
| internal/ghclient/app.go | Uses SourceOptions; per-call derived options via helpers |
| internal/ghclient/cache.go | Simplifies createCacheStore to a single path argument |
| internal/ghclient/*_test.go | Updates tests to new option types; constructs sources directly |
| github/config.go | Adds IsGHES, removes per-config path fields, derives paths from IsGHES |
| github/provider.go | Adds IsGHES plumbing, owner-required check, reworked org/user lookup |
| github/provider_test.go | New table-driven httptest-backed coverage for configureProviderMeta |
| github/helpers_test.go | New mustNewURL/mustNewPEM test helpers |
| github/acc_test.go | Updates acc test config to IsGHES |
| go.mod / go.sum | Bumps jferrl/go-githubauth to v1.7.0 |
Findings
- HIGH —
internal/ghclient/graphql.go:NewAppGraphQLClientnever forwardsopts.BaseURLto the installation token source (unlikeNewAppRESTClient), so App-authenticated GraphQL requests against GHEC/GHES/custom endpoints still fetch the installation token fromapi.github.comand fail. Not covered by tests because no GraphQL request is issued. - MEDIUM —
internal/ghclient/rest.go: For GHES,WithBaseURLis applied to a base URL without the/api/v3/suffix (verbatim), so installation-token requests hit the wrong path;WithEnterpriseURLshould be used whenopts.IsGHES.
ff7e5a3 to
a767850
Compare
dfa5c73 to
ee5e4d0
Compare
ee5e4d0 to
b1f6f94
Compare
robert-crandall
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround - the getRESTURL/getGraphQLURL helpers are a clean way to handle this, and passing the resolved /api/v3/ URL into WithBaseURL fixes the GHES installation-token path. I reproduced it locally with IsGHES: true and the token request now correctly lands on /api/v3/app/installations/{id}/access_tokens. The new options tests and the extra Response == nil nil-guards are a nice touch too. Looks good to me!
Signed-off-by: Steve Hipwell <[email protected]>
b1f6f94 to
ad448fb
Compare
|
@deiga this is just waiting for you. |
Resolves #ISSUE_NUMBER
Before the change?
After the change?
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!