Skip to content

Comments

Bugfix: tokenFromGHCLI not stripping api. from ghe.com hosts. Resolves #3188#3190

Open
clawster wants to merge 6 commits intointegrations:mainfrom
clawster:clawster/issue3188
Open

Bugfix: tokenFromGHCLI not stripping api. from ghe.com hosts. Resolves #3188#3190
clawster wants to merge 6 commits intointegrations:mainfrom
clawster:clawster/issue3188

Conversation

@clawster
Copy link

Bugfix: tokenFromGHCLI not stripping api. from ghe.com hosts. Resolves #3188


Before the change?

  • tokenFromGHCLI only mapped api.github.com -> github.com before calling gh auth token --hostname
  • For GHEC hosts (api.<slug>.ghe.com), the api. prefix was not stripped, causing the CLI lookup to fail silently
  • The provider fell back to an unauthenticated client, resulting in 401 errors on all API calls

After the change?

  • Extended hostname mapping to strip the api. prefix for GHEC hosts using the existing GHECAPIHostMatch regex
  • The provider now correctly resolves credentials from gh CLI for GHEC (*.ghe.com) instances
  • Authenticated API calls now succeed when gh auth login --hostname my-enterprise.ghe.com has been completed

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?

  • Yes
  • No

  • fix: resolve gh CLI token lookup for GHEC (.ghe.com) hosts
  • Add test cases

tokenFromGHCLI only mapped api.github.com → github.com before calling
`gh auth token --hostname`. For GHEC hosts (api.<slug>.ghe.com), the
api. prefix was not stripped, causing the CLI lookup to fail silently
and the provider to fall back to an unauthenticated client (401 errors).

Strip the api. prefix for GHEC hosts using the existing GHECAPIHostMatch
regex so the hostname matches how `gh` stores credentials.

Fixes integrations#3188
@github-actions
Copy link

👋 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! 🚀

@clawster
Copy link
Author

Replaces PR#3189 (no changes, new fork)

@stevehipwell stevehipwell added the Type: Bug Something isn't working as documented label Feb 20, 2026
@stevehipwell stevehipwell added this to the v6.12.0 Release milestone Feb 20, 2026
Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @clawster, I've added a few comments.

clawster and others added 2 commits February 20, 2026 15:11
 - move hostname modification to separate function for easier testing
 - test omdified to only test ghCLIHostFromAPIHost() without OS specific scripts
 - line ending fixed
@clawster
Copy link
Author

Thanks for the review and suggestions, code updated

Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

LGTM

@stevehipwell
Copy link
Collaborator

@clawster could you please rebase?

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.

[BUG]: tokenFromGHCLI fails to resolve token for GHEC (.ghe.com) hosts — causes silent fallback to unauthenticated client

2 participants