Add ticket-driven branch creation flow
This commit is contained in:
@@ -58,6 +58,7 @@ class GiteaProviderTest extends TestCase
|
||||
'name' => 'kanbangit',
|
||||
'full_name' => 'nico/kanbangit',
|
||||
'html_url' => 'https://git.example.test/nico/kanbangit',
|
||||
'default_branch' => 'main',
|
||||
'owner' => [
|
||||
'login' => 'nico',
|
||||
],
|
||||
@@ -75,6 +76,7 @@ class GiteaProviderTest extends TestCase
|
||||
$this->assertContainsOnlyInstancesOf(GitRepository::class, $repositories);
|
||||
$this->assertSame('501', $repositories[0]->providerRepositoryId);
|
||||
$this->assertSame('nico/kanbangit', $repositories[0]->fullName);
|
||||
$this->assertSame('main', $repositories[0]->defaultBranch);
|
||||
$this->assertFalse($repositories[0]->isPrivate);
|
||||
|
||||
Http::assertSent(function ($request): bool {
|
||||
@@ -83,6 +85,41 @@ class GiteaProviderTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the provider can fetch a single repository with its default branch.
|
||||
*/
|
||||
public function test_provider_can_fetch_a_single_repository(): void
|
||||
{
|
||||
Http::preventStrayRequests();
|
||||
Http::fake([
|
||||
'https://git.example.test/api/v1/repos/core-team/kanbangit' => Http::response([
|
||||
'id' => 501,
|
||||
'name' => 'kanbangit',
|
||||
'full_name' => 'core-team/kanbangit',
|
||||
'html_url' => 'https://git.example.test/core-team/kanbangit',
|
||||
'default_branch' => 'main',
|
||||
'owner' => [
|
||||
'login' => 'core-team',
|
||||
],
|
||||
'private' => true,
|
||||
]),
|
||||
]);
|
||||
|
||||
$repository = app(GiteaProviderClient::class)->getRepository(
|
||||
'https://git.example.test',
|
||||
'repo-token',
|
||||
'core-team',
|
||||
'kanbangit',
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(GitRepository::class, $repository);
|
||||
$this->assertSame('501', $repository->providerRepositoryId);
|
||||
$this->assertSame('core-team', $repository->owner);
|
||||
$this->assertSame('kanbangit', $repository->name);
|
||||
$this->assertSame('main', $repository->defaultBranch);
|
||||
$this->assertTrue($repository->isPrivate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the provider lists branches for a specific repository.
|
||||
*/
|
||||
@@ -119,6 +156,38 @@ class GiteaProviderTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the provider can create branches from a base reference.
|
||||
*/
|
||||
public function test_provider_can_create_a_repository_branch(): void
|
||||
{
|
||||
Http::preventStrayRequests();
|
||||
Http::fake([
|
||||
'https://git.example.test/api/v1/repos/core-team/kanbangit/branches' => Http::response([
|
||||
'name' => 'core-1-login-form',
|
||||
], 201),
|
||||
]);
|
||||
|
||||
$branch = app(GiteaProviderClient::class)->createBranch(
|
||||
'https://git.example.test',
|
||||
'branch-token',
|
||||
'core-team',
|
||||
'kanbangit',
|
||||
'core-1-login-form',
|
||||
'main',
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(GitBranch::class, $branch);
|
||||
$this->assertSame('core-1-login-form', $branch->name);
|
||||
|
||||
Http::assertSent(function ($request): bool {
|
||||
return $request->url() === 'https://git.example.test/api/v1/repos/core-team/kanbangit/branches'
|
||||
&& $request['new_branch_name'] === 'core-1-login-form'
|
||||
&& $request['old_ref_name'] === 'main'
|
||||
&& $request->hasHeader('Authorization', 'token branch-token');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the provider lists pull requests for a specific repository.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Git;
|
||||
|
||||
use App\Actions\Git\TicketKeyReferenceMatcher;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TicketKeyReferenceMatcherTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure a reference must start with the exact ticket key.
|
||||
*/
|
||||
public function test_matcher_accepts_exact_ticket_key_prefixes(): void
|
||||
{
|
||||
$matcher = app(TicketKeyReferenceMatcher::class);
|
||||
|
||||
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1-login-form'));
|
||||
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1/fix-oauth'));
|
||||
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1_hotfix'));
|
||||
$this->assertTrue($matcher->matches('CORE-1', 'CORE-1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure similar ticket keys are not treated as matches.
|
||||
*/
|
||||
public function test_matcher_rejects_other_ticket_prefixes(): void
|
||||
{
|
||||
$matcher = app(TicketKeyReferenceMatcher::class);
|
||||
|
||||
$this->assertFalse($matcher->matches('CORE-1', 'CORE-10-login-form'));
|
||||
$this->assertFalse($matcher->matches('CORE-1', 'MY-CORE-1-login-form'));
|
||||
$this->assertFalse($matcher->matches('CORE-1', 'core-1-login-form'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user