Files
coolify/tests/Unit/ApplicationGitCommitLinkTest.php
T
e3d4411ff2 chore: merge main into release/v4.5 (#12192)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Furox <177975472+Furox-Art@users.noreply.github.com>
Co-authored-by: johandenhollander <johan.den.hollander@finalist.nl>
Co-authored-by: João Cruz <161638790+SrJooJ@users.noreply.github.com>
Co-authored-by: Saim Hashmi <hashmisaim037@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-18 23:43:20 +02:00

86 lines
3.6 KiB
PHP

<?php
use App\Models\Application;
it('generates commit links for direct repository remotes', function (string $repository, string $expected) {
$application = new Application;
$application->setRelation('source', null);
$application->git_repository = $repository;
expect($application->gitCommitLink('1234567890abcdef'))->toBe($expected);
})->with([
'HTTPS remote' => [
'https://github.com/coollabsio/coolify.git',
'https://github.com/coollabsio/coolify/commit/1234567890abcdef',
],
'SSH remote' => [
'git@github.com:coollabsio/coolify.git',
'https://github.com/coollabsio/coolify/commit/1234567890abcdef',
],
'SSH remote with custom username' => [
'custom-user@git.example.com:coollabsio/coolify.git',
'https://git.example.com/coollabsio/coolify/commit/1234567890abcdef',
],
'SSH remote with custom username and port' => [
'custom-user@git.example.com:2222/coollabsio/coolify.git',
'https://git.example.com/coollabsio/coolify/commit/1234567890abcdef',
],
'SSH URL' => [
'ssh://git@gitlab.com/coollabsio/coolify.git',
'https://gitlab.com/coollabsio/coolify/commit/1234567890abcdef',
],
'Bitbucket HTTPS remote' => [
'https://bitbucket.org/coollabsio/coolify.git',
'https://bitbucket.org/coollabsio/coolify/commits/1234567890abcdef',
],
]);
it('does not generate commit links from incomplete repository URLs', function (string $repository) {
$application = new Application;
$application->setRelation('source', null);
$application->git_repository = $repository;
expect($application->gitCommitLink('1234567890abcdef'))->toBeNull();
})->with([
'missing host' => 'https://',
'missing scheme' => 'github.com/coollabsio/coolify',
'git protocol' => 'git://git.example.com/coollabsio/coolify.git',
]);
it('converts ssh remotes with generic usernames into https repository links', function (string $repository, string $expectedBranch, string $expectedCommits, string $expectedWebhook) {
$application = new Application;
$application->setRelation('source', null);
$application->git_repository = $repository;
$application->git_branch = 'main';
$application->base_directory = '/';
expect($application->gitBranchLocation)->toBe($expectedBranch)
->and($application->gitCommits)->toBe($expectedCommits)
->and($application->gitWebhook)->toBe($expectedWebhook);
})->with([
'git username' => [
'git@github.com:coollabsio/coolify.git',
'https://github.com/coollabsio/coolify/tree/main/',
'https://github.com/coollabsio/coolify/commits/main',
'https://github.com/coollabsio/coolify/settings/hooks',
],
'custom username' => [
'custom-user@git.example.com:organization/repository.git',
'https://git.example.com/organization/repository/tree/main/',
'https://git.example.com/organization/repository/commits/main',
'https://git.example.com/organization/repository/settings/hooks',
],
'custom username and port' => [
'custom-user@git.example.com:2222/organization/repository.git',
'https://git.example.com/organization/repository/tree/main/',
'https://git.example.com/organization/repository/commits/main',
'https://git.example.com/organization/repository/settings/hooks',
],
'ssh scheme with port' => [
'ssh://git@gitea.example.com:2222/organization/repository.git',
'https://gitea.example.com/organization/repository/tree/main/',
'https://gitea.example.com/organization/repository/commits/main',
'https://gitea.example.com/organization/repository/settings/hooks',
],
]);