From 7993410b30c2912f91a8ea2b1072c69c4c1c8772 Mon Sep 17 00:00:00 2001 From: Andrew Howe Date: Tue, 12 May 2026 22:32:40 -0400 Subject: [PATCH 1/2] Add GHE support --- app/Utils/RepositoryUtils.php | 27 ++++++++++++++++++++++++- app/cdash/app/Lib/Repository/GitHub.php | 18 +++++++++++++++-- config/cdash.php | 1 + 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/Utils/RepositoryUtils.php b/app/Utils/RepositoryUtils.php index b18f0cc098..c1f5aba9e5 100644 --- a/app/Utils/RepositoryUtils.php +++ b/app/Utils/RepositoryUtils.php @@ -14,6 +14,19 @@ class RepositoryUtils { + private static function is_github_url(string $url): bool + { + if (str_contains($url, 'github.com')) { + return true; + } + $enterpriseUrl = config('cdash.github_enterprise_url'); + if ($enterpriseUrl !== null) { + $host = parse_url($enterpriseUrl, PHP_URL_HOST); + return is_string($host) && str_contains($url, $host); + } + return false; + } + /** Return the GitHub diff URL */ public static function get_github_diff_url($projecturl, $directory, $file, $revision) { @@ -146,6 +159,18 @@ 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 ($enterpriseUrl !== null) { + $host = parse_url($enterpriseUrl, PHP_URL_HOST); + if (is_string($host) && str_contains($github_url, $host)) { + // GHE API URL format + $idx = strpos($github_url, $host); + $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; + } + } /* * For a URL of the form: * ...://github.com// @@ -166,7 +191,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::is_github_url($repository['url'])) { $repo = $repository; break; } diff --git a/app/cdash/app/Lib/Repository/GitHub.php b/app/cdash/app/Lib/Repository/GitHub.php index 32383b1374..d110d356ce 100644 --- a/app/cdash/app/Lib/Repository/GitHub.php +++ b/app/cdash/app/Lib/Repository/GitHub.php @@ -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, 'machine-man-preview', $enterpriseUrl); $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 ($enterpriseUrl !== null) { + $host = parse_url($enterpriseUrl, PHP_URL_HOST); + return is_string($host) && str_contains($url, $host); + } + return false; + } + protected function getRepositoryInformation(): void { $url = str_replace('//', '', $this->project->CvsUrl ?? ''); diff --git a/config/cdash.php b/config/cdash.php index 21bbb26827..3c2115cedc 100755 --- a/config/cdash.php +++ b/config/cdash.php @@ -39,6 +39,7 @@ 'delete_old_subprojects' => env('DELETE_OLD_SUBPROJECTS', true), 'github_always_pass' => env('GITHUB_ALWAYS_PASS', false), 'github_app_id' => env('GITHUB_APP_ID', null), + 'github_enterprise_url' => env('GITHUB_ENTERPRISE_URL', null), 'github_private_key' => env('GITHUB_PRIVATE_KEY', null), 'github_webhook_secret' => env('GITHUB_WEBHOOK_SECRET', null), 'large_text_limit' => env('LARGE_TEXT_LIMIT', 0), From bd6915499ec8f12609bca3730038118abf922123 Mon Sep 17 00:00:00 2001 From: Andrew Howe Date: Tue, 12 May 2026 22:48:54 -0400 Subject: [PATCH 2/2] Remove duplicated isGitHubUrl helper and dead BASE_URI constant The GitHub class had its own private isGitHubUrl() that was identical to RepositoryUtils::is_github_url(). This consolidates to the single utility method and make it public. --- app/Utils/RepositoryUtils.php | 2 +- app/cdash/app/Lib/Repository/GitHub.php | 18 ++---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/app/Utils/RepositoryUtils.php b/app/Utils/RepositoryUtils.php index c1f5aba9e5..abb7a7c4cc 100644 --- a/app/Utils/RepositoryUtils.php +++ b/app/Utils/RepositoryUtils.php @@ -14,7 +14,7 @@ class RepositoryUtils { - private static function is_github_url(string $url): bool + public static function is_github_url(string $url): bool { if (str_contains($url, 'github.com')) { return true; diff --git a/app/cdash/app/Lib/Repository/GitHub.php b/app/cdash/app/Lib/Repository/GitHub.php index d110d356ce..597aeab862 100644 --- a/app/cdash/app/Lib/Repository/GitHub.php +++ b/app/cdash/app/Lib/Repository/GitHub.php @@ -19,6 +19,7 @@ use App\Models\BuildUpdateFile; use App\Models\PendingSubmissions; +use App\Utils\RepositoryUtils; use CDash\Database; use CDash\Model\Build; use CDash\Model\BuildUpdate; @@ -44,8 +45,6 @@ */ class GitHub implements RepositoryInterface { - public const BASE_URI = 'https://api.github.com'; - private string $installationId = ''; private string $owner = ''; private string $repo = ''; @@ -76,7 +75,7 @@ public function __construct(Project $project) $repositories = $this->project->GetRepositories(); foreach ($repositories as $repo) { - if ($this->isGitHubUrl($repo['url'])) { + if (RepositoryUtils::is_github_url($repo['url'])) { $this->installationId = $repo['username']; break; } @@ -663,19 +662,6 @@ 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 ($enterpriseUrl !== null) { - $host = parse_url($enterpriseUrl, PHP_URL_HOST); - return is_string($host) && str_contains($url, $host); - } - return false; - } - protected function getRepositoryInformation(): void { $url = str_replace('//', '', $this->project->CvsUrl ?? '');