Skip to content

feat: Add new gh client implementation - #3448

Merged
stevehipwell merged 10 commits into
integrations:mainfrom
stevehipwell:new-gh-client
Jun 4, 2026
Merged

stevehipwell merged 10 commits into
integrations:mainfrom
stevehipwell:new-gh-client

Conversation

@stevehipwell

@stevehipwell stevehipwell commented May 26, 2026 •

Copy link
Copy Markdown
Collaborator

Warning

This is a work in progress. There is a known issue for tests on resources that rely on other resources to mutate them not passing due to internal GitHub logic. These would be fixed by adopting a test strategy where the fixtures are created outside of Terraform.

Resolves #2925
Resolves #3103
Resolves #2709
Resolves #849


Before the change?

  • Legacy client implementation

After the change?

  • New client implementation (behind legacy_client = false provider setting)
    • Safer provider configuration
    • Refreshable app token
    • Transport level response cache
      • Persistable using cache_path provider setting
    • Idiomatic retry handling
    • Idiomatic rate limit handling
    • Base support for future multi-owner pattern
    • Dropped support for gh CLI auth

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 requested a review from deiga May 26, 2026 16:53
@stevehipwell stevehipwell self-assigned this May 26, 2026
@stevehipwell stevehipwell added Type: Feature New feature or request Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR labels May 26, 2026
@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

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

This is looking quite nice!

Comment thread github/config.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/provider.go Resolved
Comment thread internal/ghclient/graphql.go Resolved
@stevehipwell

Copy link
Copy Markdown
Collaborator Author

@deiga I've addressed most of your comments.

@stevehipwell
stevehipwell requested a review from deiga May 29, 2026 09:21
@stevehipwell
stevehipwell marked this pull request as ready for review May 29, 2026 14:33
@deiga
deiga requested a review from Copilot May 30, 2026 06:34

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 introduces a new opt-in GitHub client implementation for the Terraform provider, adding transport-level caching/rate-limit handling and refreshed client construction while preserving the legacy client path by default.

Changes:

  • Adds internal/ghclient with anonymous, token, and GitHub App client sources plus shared transport/cache logic.
  • Updates provider configuration to support legacy_client and cache_path, and routes client setup through configureProviderMeta.
  • Updates tests, docs, and acceptance-test workflows to exercise the new client path.

Reviewed changes

Copilot reviewed 35 out of 36 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/ghclient/transport.go Adds composed OAuth/cache/logging/retry/rate-limit transport.
internal/ghclient/transport_test.go Covers transport cloning and retry behavior.
internal/ghclient/token.go Adds token-backed client source.
internal/ghclient/token_test.go Tests token source client accessors.
internal/ghclient/source.go Defines the shared client source interface.
internal/ghclient/rest.go Adds REST client constructors.
internal/ghclient/rest_test.go Tests REST client construction.
internal/ghclient/options.go Defines client construction options.
internal/ghclient/helpers_test.go Adds shared ghclient test helpers.
internal/ghclient/graphql.go Adds GraphQL client constructors.
internal/ghclient/graphql_test.go Tests GraphQL client construction.
internal/ghclient/const.go Adds shared client timeout.
internal/ghclient/cache.go Adds cache store creation.
internal/ghclient/cache_test.go Tests cache path/ref behavior.
internal/ghclient/app.go Adds GitHub App-backed client source and owner lookup.
internal/ghclient/app_test.go Tests app source caching and installation lookup.
internal/ghclient/anonymous.go Adds anonymous client source.
internal/ghclient/anonymous_test.go Tests anonymous source client accessors.
go.mod Adds new client/cache/rate-limit dependencies.
go.sum Adds dependency checksums.
github/provider.go Reworks provider configuration and new/legacy client setup.
github/provider_test.go Updates provider/client configuration tests.
github/data_source_github_user_external_identity.go Uses operation context for GraphQL query.
github/data_source_github_ssh_keys.go Uses operation context for REST call.
github/data_source_github_repository_test.go Adjusts repository data source acceptance precheck.
github/data_source_github_organization_teams.go Uses operation context for GraphQL/REST calls.
github/data_source_github_ip_ranges.go Uses operation context for REST call.
github/data_source_github_codespaces_user_public_key_test.go Skips app-auth mode for unsupported test.
github/data_source_github_branch_protection_rules.go Uses operation context for GraphQL query.
github/config.go Extends provider config and routes Meta through new setup.
github/config_test.go Removes relocated client meta tests.
github/acc_test.go Extends acceptance-test config for new client/app auth.
docs/index.md Documents new provider arguments and changed option behavior.
CONTRIBUTING.md Updates acceptance-test setup for new client mode.
.github/workflows/ghes-acceptance-tests.yaml Runs GHES acceptance tests with new client.
.github/workflows/dotcom-acceptance-tests.yaml Runs dotcom acceptance tests with new client.

Comment thread github/provider.go Resolved
Comment thread internal/ghclient/cache.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/acc_test.go Resolved
Comment thread github/provider.go Resolved

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

Partial review

Comment thread github/config.go Resolved
Comment thread github/provider.go Resolved
Comment thread github/provider.go Resolved
Comment thread internal/ghclient/anonymous_test.go Resolved
Comment thread internal/ghclient/anonymous_test.go Resolved
Comment thread internal/ghclient/app_test.go Resolved
Comment thread internal/ghclient/app_test.go Resolved
Comment thread internal/ghclient/app_test.go Resolved
Comment thread internal/ghclient/token_test.go Resolved
Comment thread internal/ghclient/token_test.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 35 out of 36 changed files in this pull request and generated 5 comments.

Comment thread github/provider.go Resolved
Comment thread github/provider_test.go Resolved
Comment thread github/provider_test.go Resolved
Comment thread github/provider_test.go Resolved
Comment thread internal/ghclient/cache.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 35 out of 36 changed files in this pull request and generated 2 comments.

Comment thread github/provider.go Resolved
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 35 out of 36 changed files in this pull request and generated 1 comment.

Comment thread internal/ghclient/transport.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 35 out of 36 changed files in this pull request and generated no new comments.

@stevehipwell
stevehipwell enabled auto-merge (squash) June 4, 2026 08:05
@stevehipwell
stevehipwell merged commit e286cb0 into integrations:main Jun 4, 2026
10 checks passed
@stevehipwell
stevehipwell deleted the new-gh-client branch June 4, 2026 08:10
@kishaningithub

Copy link
Copy Markdown

Where does this disable go-github's annoying rate limit check before hitting the transport layer?

@stevehipwell

Copy link
Copy Markdown
Collaborator Author

If you enable the new (experimental) client by setting legacy_client to false it disables the native go-github rate limit check a well as the legacy provider rate limit implementation. It then uses an instance of gofri/go-github-ratelimit per client. It also adds bored-engineer/github-conditional-http-transport to transparently handle unchanged resources at the transport layer instead of adding complexity into each resource method.

austenstone pushed a commit to austenstone/terraform-provider-github that referenced this pull request Jun 9, 2026
* feat: Add new gh client implementation

Signed-off-by: Steve Hipwell <[email protected]>

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

* fixup! feat: Add new gh client implementation

---------

Signed-off-by: Steve Hipwell <[email protected]>
garnertb added a commit to garnertb/terraform-provider-github that referenced this pull request Aug 18, 2026
The doc asserted the original innermost oauth2 placement gave token
freshness "by accident" and cited the newTransport doc comment as
evidence the ordering was unintended. Neither survives checking.

The doc comment lists layers in construction order (oauth2, ghct,
logging, retry), which matches the code exactly. Construction order is
the reverse of execution order, but the comment never claims an
execution order, so it is evidence of neither intent nor accident.

Replace both with the one substantive datum from history: oauth2 and
ghct were introduced in the same commit (e286cb0, integrations#3448) with ghct
placed directly outside oauth2, so the cache could never see
Authorization and the feature was non-functional from the commit that
added it. State plainly that intent is not knowable from the repository
and that the new ordering is chosen to satisfy both properties
explicitly rather than to rely on either having been intended.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 1d014064-b027-4d89-9e5b-e1f9781bc039
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR

Projects

None yet

5 participants