Skip to content

feat: Refactor new client logic to use base url - #3510

Merged
stevehipwell merged 2 commits into
integrations:mainfrom
stevehipwell:fix-new-client-app-auth
Jul 2, 2026
Merged

stevehipwell merged 2 commits into
integrations:mainfrom
stevehipwell:fix-new-client-app-auth

Conversation

@stevehipwell

Copy link
Copy Markdown
Collaborator

Resolves #ISSUE_NUMBER


Before the change?

  • App auth using the new client would only work for github.com

After the change?

  • App auth works for all targets
  • Improved test coverage for provider meta
  • New client has been refactored

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@stevehipwell stevehipwell added this to the v6.13.0 milestone Jun 30, 2026
@stevehipwell
stevehipwell requested review from Copilot and deiga June 30, 2026 16:51
@stevehipwell stevehipwell self-assigned this Jun 30, 2026
@github-actions

Copy link
Copy Markdown

👋 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.

@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label Jun 30, 2026

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

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 Options with SourceOptions/ClientOptions and centralized REST/GraphQL option derivation; simplified cache store path construction.
  • Threaded BaseURL/IsGHES through REST/GraphQL client construction and the App installation token source; reworked provider owner/org lookup error handling.
  • Bumped go-githubauth to 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: NewAppGraphQLClient never forwards opts.BaseURL to the installation token source (unlike NewAppRESTClient), so App-authenticated GraphQL requests against GHEC/GHES/custom endpoints still fetch the installation token from api.github.com and fail. Not covered by tests because no GraphQL request is issued.
  • MEDIUM — internal/ghclient/rest.go: For GHES, WithBaseURL is applied to a base URL without the /api/v3/ suffix (verbatim), so installation-token requests hit the wrong path; WithEnterpriseURL should be used when opts.IsGHES.

Comment thread internal/ghclient/graphql.go Resolved
Comment thread internal/ghclient/rest.go Resolved

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

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Comment thread github/provider_test.go Resolved
@stevehipwell
stevehipwell force-pushed the fix-new-client-app-auth branch 4 times, most recently from dfa5c73 to ee5e4d0 Compare July 1, 2026 09:10
@stevehipwell
stevehipwell requested a review from Copilot July 1, 2026 09:11

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

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Comment thread github/provider.go Resolved

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

Copilot reviewed 24 out of 25 changed files in this pull request and generated no new comments.

@robert-crandall robert-crandall 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.

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!

@stevehipwell
stevehipwell force-pushed the fix-new-client-app-auth branch from b1f6f94 to ad448fb Compare July 2, 2026 08:50
@stevehipwell

Copy link
Copy Markdown
Collaborator Author

@deiga this is just waiting for you.

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Really nice refactor!

Comment thread github/provider.go Resolved
@stevehipwell
stevehipwell merged commit 9f2e03a into integrations:main Jul 2, 2026
11 checks passed
@stevehipwell
stevehipwell deleted the fix-new-client-app-auth branch July 2, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants