Skip to content

Commit

Permalink
[server] When GitHub (Enterprise) sends webhooks without a host heade…
Browse files Browse the repository at this point in the history
…r, fall back to the hostname from the repository URL

Fixes "Unsupported GitHub Enterprise host: undefined"
  • Loading branch information
jankeromnes committed Jun 2, 2022
1 parent 8a59838 commit 72846e8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/server/ee/src/prebuilds/github-enterprise-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ export class GitHubEnterpriseApp {
): Promise<User> {
const span = TraceContext.startSpan("GitHubEnterpriseApp.findUser", ctx);
try {
const host = req.header("X-Github-Enterprise-Host");
let host = req.header("X-Github-Enterprise-Host");
if (!host) {
// If the GitHub installation doesn't identify itself, we fall back to the hostname from the repository URL.
const repoUrl = new URL(payload.repository.url);
host = repoUrl.hostname;
}
const hostContext = this.hostContextProvider.get(host || "");
if (!host || !hostContext) {
if (!hostContext) {
throw new Error("Unsupported GitHub Enterprise host: " + host);
}
const { authProviderId } = hostContext.authProvider;
Expand Down

0 comments on commit 72846e8

Please sign in to comment.