Fix GitHub App failures when connecting to GitHub Enterprise #4542
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes GitHub App authentication failures when connecting to GitHub Enterprise Server instances by ensuring the API endpoint includes the required
/api/v3path component.Problem
Customers using GitHub Apps with GitHub Enterprise Server were encountering 406 Not Acceptable errors during token refresh:
Root Cause
GitHub Enterprise Server requires all API endpoints to include
/api/v3in the path (docs). The issue occurred because:go-githubclient library automatically adds/api/v3viaWithEnterpriseURLs()for REST API callsghinstallationlibrary uses a separateBaseURLfield to construct token refresh URLs as{BaseURL}/app/installations/{id}/access_tokensendpoint: https://github.company.com(without/api/v3), the ghinstallation library constructed the incorrect URL. Reference: GitHub Enterprise EndpointSolution
Added
normalizeGitHubEnterpriseEndpoint()function inpkg/sources/github/connector.gothat:/api/v3before passing to connector implementationsapi.github.com) unchangedImpact Analysis:
/api/v3before adding/api/graphql)Testing
Unit Tests
normalizeGitHubEnterpriseEndpoint()Manual Testing (GitHub.com)
Verified all authentication methods work correctly with GitHub.com:
Expected Behavior for GitHub Enterprise Server
With this fix, users can now configure GitHub Enterprise endpoints in any of these formats:
Both formats will now work correctly for all authentication types, including GitHub Apps.
Checklist:
make test-community)?make lintthis requires golangci-lint)?