mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
Gitlab Self-managed Support (#56)
* Update UI to ask for URL for Gitlab as provider. * Create state for each source control in factory. * Save url for SourceControl when given. * Make Gitlab dynamically use correct URL (custom or default) * Update SourceControlsTest to check for custom url when given. * Style fixes. --------- Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
This commit is contained in:
@ -17,21 +17,28 @@ class SourceControlsTest extends TestCase
|
||||
/**
|
||||
* @dataProvider data
|
||||
*/
|
||||
public function test_connect_provider(string $provider): void
|
||||
public function test_connect_provider(string $provider, ?string $customUrl): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Http::fake();
|
||||
|
||||
Livewire::test(Connect::class)
|
||||
$livewire = Livewire::test(Connect::class)
|
||||
->set('token', 'token')
|
||||
->set('name', 'profile')
|
||||
->set('provider', $provider)
|
||||
->set('provider', $provider);
|
||||
|
||||
if ($customUrl !== null) {
|
||||
$livewire->set('url', $customUrl);
|
||||
}
|
||||
|
||||
$livewire
|
||||
->call('connect')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('source_controls', [
|
||||
'provider' => $provider,
|
||||
'url' => $customUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -61,9 +68,10 @@ public function test_delete_provider(string $provider): void
|
||||
public static function data(): array
|
||||
{
|
||||
return [
|
||||
['github'],
|
||||
['gitlab'],
|
||||
['bitbucket'],
|
||||
['github', null],
|
||||
['gitlab', null],
|
||||
['gitlab', 'https://git.example.com/'],
|
||||
['bitbucket', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
86
tests/Unit/SourceControlProviders/GitlabTest.php
Normal file
86
tests/Unit/SourceControlProviders/GitlabTest.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\SourceControlProviders;
|
||||
|
||||
use App\Models\SourceControl;
|
||||
use App\SourceControlProviders\Gitlab;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GitlabTest extends TestCase
|
||||
{
|
||||
public function test_default_gitlab_url(): void
|
||||
{
|
||||
$sourceControlModel = SourceControl::factory()
|
||||
->gitlab()
|
||||
->create();
|
||||
|
||||
$gitlab = new Gitlab($sourceControlModel);
|
||||
|
||||
$this->assertSame('https://gitlab.com/api/v4', $gitlab->getApiUrl());
|
||||
}
|
||||
|
||||
public function test_default_gitlab_repo_url(): void
|
||||
{
|
||||
$repo = 'test/repo';
|
||||
$key = 'TEST_KEY';
|
||||
|
||||
$sourceControlModel = SourceControl::factory()
|
||||
->gitlab()
|
||||
->create();
|
||||
|
||||
$gitlab = new Gitlab($sourceControlModel);
|
||||
|
||||
$this->assertSame('git@gitlab.com-TEST_KEY:test/repo.git', $gitlab->fullRepoUrl($repo, $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider customUrlData
|
||||
*/
|
||||
public function test_custom_url(string $url, string $expected): void
|
||||
{
|
||||
$sourceControlModel = SourceControl::factory()
|
||||
->gitlab()
|
||||
->create(['url' => $url]);
|
||||
|
||||
$gitlab = new Gitlab($sourceControlModel);
|
||||
|
||||
$this->assertSame($expected, $gitlab->getApiUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider customRepoUrlData
|
||||
*/
|
||||
public function test_custom_full_repository_url(string $url, string $expected): void
|
||||
{
|
||||
$repo = 'test/repo';
|
||||
$key = 'TEST_KEY';
|
||||
|
||||
$sourceControlModel = SourceControl::factory()
|
||||
->gitlab()
|
||||
->create(['url' => $url]);
|
||||
|
||||
$gitlab = new Gitlab($sourceControlModel);
|
||||
|
||||
$this->assertSame($expected, $gitlab->fullRepoUrl($repo, $key));
|
||||
}
|
||||
|
||||
public static function customRepoUrlData(): array
|
||||
{
|
||||
return [
|
||||
['https://git.example.com/', 'git@git.example.com-TEST_KEY:test/repo.git'],
|
||||
['https://git.test.example.com/', 'git@git.test.example.com-TEST_KEY:test/repo.git'],
|
||||
['https://git.example.co.uk/', 'git@git.example.co.uk-TEST_KEY:test/repo.git'],
|
||||
];
|
||||
}
|
||||
|
||||
public static function customUrlData(): array
|
||||
{
|
||||
return [
|
||||
['https://git.example.com/', 'https://git.example.com/api/v4'],
|
||||
['https://git.test.example.com/', 'https://git.test.example.com/api/v4'],
|
||||
['https://git.example.co.uk/', 'https://git.example.co.uk/api/v4'],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user