-
Notifications
You must be signed in to change notification settings - Fork 83
Add GitHub Enterprise support #3720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,19 @@ | |||||
|
|
||||||
| class RepositoryUtils | ||||||
| { | ||||||
| private static function isGitHubUrl(string $url): bool | ||||||
| { | ||||||
| if (str_contains($url, 'github.com')) { | ||||||
| return true; | ||||||
| } | ||||||
| $enterpriseUrl = config('cdash.github_enterprise_url'); | ||||||
| if (is_string($enterpriseUrl)) { | ||||||
| $host = parse_url($enterpriseUrl, PHP_URL_HOST); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use Laravel's Apply throughout.
Suggested change
|
||||||
| return is_string($host) && str_contains($url, $host); | ||||||
| } | ||||||
| return false; | ||||||
| } | ||||||
|
Comment on lines
+17
to
+28
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a duplicate of |
||||||
|
|
||||||
| /** Return the GitHub diff URL */ | ||||||
| public static function get_github_diff_url($projecturl, $directory, $file, $revision) | ||||||
| { | ||||||
|
|
@@ -146,6 +159,20 @@ public static function post_pull_request_comment($projectid, $pull_request, $com | |||||
| /** Convert GitHub repository viewer URL into corresponding API URL. */ | ||||||
| public static function get_github_api_url($github_url): string | ||||||
| { | ||||||
| $enterpriseUrl = config('cdash.github_enterprise_url'); | ||||||
| if (is_string($enterpriseUrl)) { | ||||||
| $host = parse_url($enterpriseUrl, PHP_URL_HOST); | ||||||
| if (is_string($host)) { | ||||||
| $idx = strpos($github_url, $host); | ||||||
| if ($idx !== false) { | ||||||
| // For GHE, ...://<host>/<user>/<repo> becomes ...://<host>/api/v3/repos/<user>/<repo> | ||||||
| $idx2 = $idx + strlen($host) + 1; | ||||||
| $api_url = substr($github_url, 0, $idx) . $host . '/api/v3/repos/'; | ||||||
| $api_url .= substr($github_url, $idx2); | ||||||
| return $api_url; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
Comment on lines
+162
to
+175
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few questions/comments:
|
||||||
| /* | ||||||
| * For a URL of the form: | ||||||
| * ...://github.com/<user>/<repo> | ||||||
|
|
@@ -166,7 +193,7 @@ public static function post_github_pull_request_comment(Project $project, $pull_ | |||||
| $repo = null; | ||||||
| $repositories = $project->GetRepositories(); | ||||||
| foreach ($repositories as $repository) { | ||||||
| if (str_contains($repository['url'], 'github.com')) { | ||||||
| if (self::isGitHubUrl($repository['url'])) { | ||||||
| $repo = $repository; | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ public function __construct(Project $project) | |
|
|
||
| $repositories = $this->project->GetRepositories(); | ||
| foreach ($repositories as $repo) { | ||
| if (str_contains($repo['url'], 'github.com')) { | ||
| if ($this->isGitHubUrl($repo['url'])) { | ||
| $this->installationId = $repo['username']; | ||
| break; | ||
| } | ||
|
|
@@ -93,7 +93,8 @@ public function setApiClient(GitHubClient $client): void | |
| protected function initializeApiClient(): void | ||
| { | ||
| $builder = new GitHubBuilder(); | ||
| $apiClient = new GitHubClient($builder, 'machine-man-preview'); | ||
| $enterpriseUrl = config('cdash.github_enterprise_url'); | ||
| $apiClient = new GitHubClient($builder, null, is_string($enterpriseUrl) ? $enterpriseUrl : null); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should treat an empty string like a null here. |
||
| $this->setApiClient($apiClient); | ||
| } | ||
|
|
||
|
|
@@ -662,6 +663,19 @@ public function getRepository(): string | |
| return $this->repo; | ||
| } | ||
|
|
||
| private function isGitHubUrl(string $url): bool | ||
| { | ||
| if (str_contains($url, 'github.com')) { | ||
| return true; | ||
| } | ||
| $enterpriseUrl = config('cdash.github_enterprise_url'); | ||
| if (is_string($enterpriseUrl)) { | ||
| $host = parse_url($enterpriseUrl, PHP_URL_HOST); | ||
| return is_string($host) && str_contains($url, $host); | ||
| } | ||
|
Comment on lines
+671
to
+675
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're referencing the config value multiple times in this file. It would be better to factor that out into a method which returns the enterprise URL or null. |
||
| return false; | ||
| } | ||
|
|
||
| protected function getRepositoryInformation(): void | ||
| { | ||
| $url = str_replace('//', '', $this->project->CvsUrl ?? ''); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,7 +84,11 @@ public static function createOrUpdateCheck($sha): void | |
| $project = new Project(); | ||
| $project->Id = $projectid; | ||
| $project->Fill(); | ||
| $repositoryInterface = self::getRepositoryInterface($project); | ||
| try { | ||
| $repositoryInterface = self::getRepositoryInterface($project); | ||
| } catch (Exception $e) { | ||
| return; | ||
| } | ||
|
Comment on lines
-87
to
+91
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? This will destroy all exceptions within |
||
| $repositoryInterface->createCheck($sha); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the thought process here?