Skip to content

Commit 72846e8

Browse files
committed
[server] When GitHub (Enterprise) sends webhooks without a host header, fall back to the hostname from the repository URL
Fixes "Unsupported GitHub Enterprise host: undefined"
1 parent 8a59838 commit 72846e8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

components/server/ee/src/prebuilds/github-enterprise-app.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ export class GitHubEnterpriseApp {
7777
): Promise<User> {
7878
const span = TraceContext.startSpan("GitHubEnterpriseApp.findUser", ctx);
7979
try {
80-
const host = req.header("X-Github-Enterprise-Host");
80+
let host = req.header("X-Github-Enterprise-Host");
81+
if (!host) {
82+
// If the GitHub installation doesn't identify itself, we fall back to the hostname from the repository URL.
83+
const repoUrl = new URL(payload.repository.url);
84+
host = repoUrl.hostname;
85+
}
8186
const hostContext = this.hostContextProvider.get(host || "");
82-
if (!host || !hostContext) {
87+
if (!hostContext) {
8388
throw new Error("Unsupported GitHub Enterprise host: " + host);
8489
}
8590
const { authProviderId } = hostContext.authProvider;

0 commit comments

Comments
 (0)