--- title: "ADR 0003: Detecting a GitHub host when validating a Repository URL" --- * Status: accepted, probe under review * Code: [`pkg/webhook/validation.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/webhook/validation.go), `validateRepositoryURL`, `isGitHubInstance` ## Context GitHub has no subgroups: `https://github.com/org/repo/extra` is not a repository. GitLab, Bitbucket and Gitea do have subgroups, so the same shape is valid there and must not be rejected. The admission webhook validates a `Repository` in isolation. It has the URL and, optionally, `spec.gitProvider.type`. It has no provider client, no API call budget, and no knowledge of hosts it has never seen. A GitHub Enterprise host is not `github.com`, so the hostname alone cannot answer the question. ## Decision `isGitHubInstance` resolves in a fixed order, cheapest first: 1. `spec.gitProvider.type == "github"` — the user told us, trust it. 2. host is `github.com`. 3. `HEAD` the root URL with a 1 second timeout and look for `github.com` in the `Server` response header, which is what a GHE instance reports. The path-segment rule (exactly two segments) applies only when one of those says GitHub. ## Consequences * Creating a `Repository` against an unknown host performs one outbound HTTP request from the admission path. A slow or unreachable host costs up to one second of admission latency per request. * The probe fails open: a timeout, a TLS error or a header the instance does not send all mean "not GitHub", so a GHE URL with a subgroup is accepted. Validation is permissive rather than wrong-in-the-other-direction, which is the useful failure mode here. * Results are not cached, so repeated applies to the same host repeat the request. * A probe in the admission path is a network dependency in a code path that should be offline. Removing it means either requiring `spec.gitProvider.type`, or accepting a looser URL check for GHE. See the follow-up issue filed with this record.