Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion app/Utils/RepositoryUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@

class RepositoryUtils
{
public 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)
{
Expand Down Expand Up @@ -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/<user>/<repo>
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions app/cdash/app/Lib/Repository/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = '';
Expand Down Expand Up @@ -76,7 +75,7 @@ public function __construct(Project $project)

$repositories = $this->project->GetRepositories();
foreach ($repositories as $repo) {
if (str_contains($repo['url'], 'github.com')) {
if (RepositoryUtils::is_github_url($repo['url'])) {
$this->installationId = $repo['username'];
break;
}
Expand All @@ -93,7 +92,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);
}

Expand Down
1 change: 1 addition & 0 deletions config/cdash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading