Add ticket branch discovery by ticket key
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Tests\Feature\Git;
|
||||
|
||||
use App\Actions\Git\Data\GitAuthenticatedUser;
|
||||
use App\Actions\Git\Data\GitBranch;
|
||||
use App\Actions\Git\Data\GitRepository;
|
||||
use App\Actions\Git\Gitea\GiteaProviderClient;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -80,4 +81,40 @@ class GiteaProviderTest extends TestCase
|
||||
&& $request->hasHeader('Authorization', 'token repo-token');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the provider lists branches for a specific repository.
|
||||
*/
|
||||
public function test_provider_can_list_repository_branches(): void
|
||||
{
|
||||
Http::preventStrayRequests();
|
||||
Http::fake([
|
||||
'https://git.example.test/api/v1/repos/core-team/kanbangit/branches*' => Http::response([
|
||||
[
|
||||
'name' => 'CORE-1-login-form',
|
||||
],
|
||||
[
|
||||
'name' => 'main',
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
$branches = app(GiteaProviderClient::class)->listBranches(
|
||||
'https://git.example.test',
|
||||
'branch-token',
|
||||
'core-team',
|
||||
'kanbangit',
|
||||
);
|
||||
|
||||
$this->assertCount(2, $branches);
|
||||
$this->assertContainsOnlyInstancesOf(GitBranch::class, $branches);
|
||||
$this->assertSame('CORE-1-login-form', $branches[0]->name);
|
||||
|
||||
Http::assertSent(function ($request): bool {
|
||||
return str_starts_with(
|
||||
$request->url(),
|
||||
'https://git.example.test/api/v1/repos/core-team/kanbangit/branches',
|
||||
) && $request->hasHeader('Authorization', 'token branch-token');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Projects;
|
||||
use App\Actions\ProjectPermissions\ProjectPermissionService;
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Models\Project;
|
||||
use App\Models\RepositoryConnection;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketFieldValue;
|
||||
@@ -13,7 +14,9 @@ use App\Models\TicketLinkType;
|
||||
use App\Models\TicketPriority;
|
||||
use App\Models\TicketWorklogEntry;
|
||||
use App\Models\User;
|
||||
use App\Models\UserGitConnection;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -97,10 +100,85 @@ class ProjectTicketControllerTest extends TestCase
|
||||
->where('ticket.worklog_entries.0.actor.name', $viewer->name)
|
||||
->where('linkedTickets.0.linked_ticket.ticket_key', 'CORE-2')
|
||||
->where('linkedTickets.0.ticket_link_type.label', 'Relates to')
|
||||
->where('repositoryBranches', [])
|
||||
->where('canEditTicket', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure ticket details expose matching branches and inaccessible repository links.
|
||||
*/
|
||||
public function test_ticket_details_include_matching_branches_and_inaccessible_repository_links(): void
|
||||
{
|
||||
Http::preventStrayRequests();
|
||||
Http::fake([
|
||||
'https://git.example.test/api/v1/repos/core-team/kanbangit/branches*' => Http::response([
|
||||
['name' => 'CORE-1-login-form'],
|
||||
['name' => 'CORE-1/fix-oauth'],
|
||||
['name' => 'CORE-10-should-not-match'],
|
||||
['name' => 'main'],
|
||||
]),
|
||||
]);
|
||||
|
||||
$viewer = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(InitializeProjectTicketMetadata::class)->handle($project);
|
||||
|
||||
$priority = TicketPriority::factory()->for($project)->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$ticket = Ticket::factory()->create([
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'CORE-1',
|
||||
'ticket_priority_id' => $priority->id,
|
||||
'ticket_type_id' => $project->ticketTypes()->firstOrFail()->id,
|
||||
'title' => 'Branch detail test',
|
||||
]);
|
||||
|
||||
RepositoryConnection::factory()->for($project)->create([
|
||||
'base_url' => 'https://git.example.test',
|
||||
'owner_name' => 'core-team',
|
||||
'provider_repository_id' => '501',
|
||||
'repository_full_name' => 'core-team/kanbangit',
|
||||
'repository_name' => 'kanbangit',
|
||||
'repository_url' => 'https://git.example.test/core-team/kanbangit',
|
||||
]);
|
||||
RepositoryConnection::factory()->for($project)->create([
|
||||
'base_url' => 'https://git.other.test',
|
||||
'owner_name' => 'other-team',
|
||||
'provider_repository_id' => '902',
|
||||
'repository_full_name' => 'other-team/mobile',
|
||||
'repository_name' => 'mobile',
|
||||
'repository_url' => 'https://git.other.test/other-team/mobile',
|
||||
]);
|
||||
|
||||
UserGitConnection::factory()->for($viewer)->create([
|
||||
'base_url' => 'https://git.example.test',
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $viewer, ['view']);
|
||||
|
||||
$this->actingAs($viewer)
|
||||
->get(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('projects/Ticket')
|
||||
->where('repositoryBranches.0.repository_connection.repository_full_name', 'core-team/kanbangit')
|
||||
->has('repositoryBranches.0.branches', 2)
|
||||
->where('repositoryBranches.0.branches.0.name', 'CORE-1-login-form')
|
||||
->where('repositoryBranches.0.branches.1.name', 'CORE-1/fix-oauth')
|
||||
->where('repositoryBranches.1.repository_connection.repository_full_name', 'other-team/mobile')
|
||||
->where('repositoryBranches.1.repository_connection.has_personal_access', false)
|
||||
->where('repositoryBranches.1.branches', []),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure updating ticket details requires the project edit permission.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user