(apiBaseURL string, httpClient *http.Client, clock quartz.Clock)
| 33 | } |
| 34 | |
| 35 | func 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. |
no test coverage detected