Add ticket branch discovery by ticket key
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Actions\Git\Gitea;
|
||||
|
||||
use App\Actions\Git\Contracts\GitProviderClient;
|
||||
use App\Actions\Git\Data\GitAuthenticatedUser;
|
||||
use App\Actions\Git\Data\GitBranch;
|
||||
use App\Actions\Git\Data\GitRepository;
|
||||
use App\Actions\Git\GitProviderKey;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
@@ -75,6 +76,43 @@ class GiteaProviderClient implements GitProviderClient
|
||||
return $repositories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, GitBranch>
|
||||
*/
|
||||
public function listBranches(
|
||||
string $baseUrl,
|
||||
string $token,
|
||||
string $owner,
|
||||
string $repository,
|
||||
): array {
|
||||
$page = 1;
|
||||
$branches = [];
|
||||
|
||||
do {
|
||||
/** @var array<int, array{name: string}> $payload */
|
||||
$payload = $this->request($baseUrl, $token)
|
||||
->get(
|
||||
'/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/branches',
|
||||
[
|
||||
'limit' => 100,
|
||||
'page' => $page,
|
||||
],
|
||||
)
|
||||
->throw()
|
||||
->json();
|
||||
|
||||
foreach ($payload as $branch) {
|
||||
$branches[] = new GitBranch(
|
||||
name: $branch['name'],
|
||||
);
|
||||
}
|
||||
|
||||
$page++;
|
||||
} while (count($payload) === 100);
|
||||
|
||||
return $branches;
|
||||
}
|
||||
|
||||
private function request(string $baseUrl, string $token): PendingRequest
|
||||
{
|
||||
return Http::acceptJson()
|
||||
|
||||
Reference in New Issue
Block a user