MCPcopy Index your code
hub / github.com/coder/coder / newGitHub

Function newGitHub

coderd/externalauth/gitprovider/github.go:35–70  ·  view source on GitHub ↗
(apiBaseURL string, httpClient *http.Client, clock quartz.Clock)

Source from the content-addressed store, hash-verified

33}
34
35func newGitHub(apiBaseURL string, httpClient *http.Client, clock quartz.Clock) *githubProvider {
36 if apiBaseURL == "" {
37 apiBaseURL = defaultGitHubAPIBaseURL
38 }
39 apiBaseURL = strings.TrimRight(apiBaseURL, "/")
40 if httpClient == nil {
41 httpClient = http.DefaultClient
42 }
43
44 // Derive the web base URL from the API base URL.
45 // github.com: api.github.com → github.com
46 // GHE: ghes.corp.com/api/v3 → ghes.corp.com
47 webBaseURL := deriveWebBaseURL(apiBaseURL)
48
49 // Parse the host for regex construction.
50 host := extractHost(webBaseURL)
51
52 // Escape the host for use in regex patterns.
53 escapedHost := regexp.QuoteMeta(host)
54
55 return &githubProvider{
56 apiBaseURL: apiBaseURL,
57 webBaseURL: webBaseURL,
58 httpClient: httpClient,
59 clock: clock,
60 pullRequestPathPattern: regexp.MustCompile(
61 `^https://` + escapedHost + `/([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)/pull/([0-9]+)(?:[/?#].*)?$`,
62 ),
63 repositoryHTTPSPattern: regexp.MustCompile(
64 `^https://` + escapedHost + `/([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+?)(?:\.git)?/?$`,
65 ),
66 repositorySSHPathPattern: regexp.MustCompile(
67 `^(?:ssh://)?git@` + escapedHost + `[:/]([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+?)(?:\.git)?/?$`,
68 ),
69 }
70}
71
72// deriveWebBaseURL converts a GitHub API base URL to the
73// corresponding web base URL.

Callers 1

NewFunction · 0.85

Calls 3

deriveWebBaseURLFunction · 0.85
extractHostFunction · 0.85
MustCompileMethod · 0.80

Tested by

no test coverage detected