feat(github): add GitHub Enterprise Server support to GitHub Action - #13860
feat(github): add GitHub Enterprise Server support to GitHub Action#13860balcsida wants to merge 25 commits into
Conversation
|
Great request to allow use in Enterprise |
3e83e03 to
ed86139
Compare
ccda103 to
584ced7
Compare
584ced7 to
46ee5df
Compare
46ee5df to
37135c8
Compare
|
Are there any plans to merge this feature? It would be very helpful for GitHub Enterprise Server users. |
37135c8 to
60ed96e
Compare
60ed96e to
f743f30
Compare
f743f30 to
705f1f5
Compare
|
Thanks for working on GHES support. I reproduced the current failure with OpenCode 1.18.9 and the pinned official GitHub Action on a GHES runner. The runner provides an internal GITHUB_API_URL, but github.handler.ts constructs Octokit without a baseUrl, so the GHES token is sent to api.github.com and the run fails with 401 Bad credentials. This PR addresses that REST failure, but I noticed the GraphQL client currently receives ghUrls.apiUrl as its baseUrl. On GHES, GITHUB_API_URL normally ends in /api/v3. @octokit/graphql appends /graphql and documents the GHES baseUrl as https://host/api, so using the REST URL would target /api/v3/graphql instead of the GHES endpoint /api/graphql. GitHub Actions also provides GITHUB_GRAPHQL_URL. Could getGitHubURLs return a separate GraphQL base URL, using GITHUB_GRAPHQL_URL with the trailing /graphql removed, and fall back to serverUrl + /api for GHES? A focused request-mocking test that asserts the final REST and GraphQL URLs would also catch this distinction. I can validate an updated branch against the GHES dry-run that exposed the 401. I have omitted the private host and credentials from this report. |
What does this PR do?
Fixes #12830
The GitHub Action hardcodes
github.comURLs everywhere, so it can't run on GHES. This PR readsGITHUB_SERVER_URLandGITHUB_API_URLenv vars (set automatically by GHES runners) and uses them to derive all host-specific values — Octokit/GraphQLbaseUrl, git credential config keys, noreply emails, fork remote URLs, image attachment regexes, and the token revocation endpoint. Defaults togithub.comwhen the env vars aren't set, so nothing changes for existing users.Also adds a
parseGitRemotefunction (host-agnostic version ofparseGitHubRemote) so theinstallcommand detects GHES remotes and generates a workflow withuse_github_token: trueand write permissions pre-configured.How did you verify your code works?
bun build --no-bundlebun test test/cli/github-remote.test.tsandgithub-action.test.ts)parseGitRemotewith GHES URLs, SSH, HTTPS, various hostsgithub.comreferences that should be parameterized (only defaults, comments, and the opencode app URL which correctly stays on github.com)