Add ticket pull request visibility
This commit is contained in:
@@ -5,6 +5,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\GitPullRequest;
|
||||
use App\Actions\Git\Data\GitRepository;
|
||||
use App\Actions\Git\GitProviderKey;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
@@ -113,6 +114,58 @@ class GiteaProviderClient implements GitProviderClient
|
||||
return $branches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, GitPullRequest>
|
||||
*/
|
||||
public function listPullRequests(
|
||||
string $baseUrl,
|
||||
string $token,
|
||||
string $owner,
|
||||
string $repository,
|
||||
): array {
|
||||
$page = 1;
|
||||
$pullRequests = [];
|
||||
|
||||
do {
|
||||
/** @var array<int, array{
|
||||
* html_url: string,
|
||||
* merged?: bool,
|
||||
* number: int|string,
|
||||
* state: string,
|
||||
* title: string,
|
||||
* head: array{ref: string}
|
||||
* }> $payload
|
||||
*/
|
||||
$payload = $this->request($baseUrl, $token)
|
||||
->get(
|
||||
'/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/pulls',
|
||||
[
|
||||
'limit' => 100,
|
||||
'page' => $page,
|
||||
'state' => 'all',
|
||||
],
|
||||
)
|
||||
->throw()
|
||||
->json();
|
||||
|
||||
foreach ($payload as $pullRequest) {
|
||||
$status = ($pullRequest['merged'] ?? false) ? 'merged' : $pullRequest['state'];
|
||||
|
||||
$pullRequests[] = new GitPullRequest(
|
||||
number: (string) $pullRequest['number'],
|
||||
title: $pullRequest['title'],
|
||||
status: $status,
|
||||
sourceBranch: $pullRequest['head']['ref'],
|
||||
htmlUrl: $pullRequest['html_url'],
|
||||
);
|
||||
}
|
||||
|
||||
$page++;
|
||||
} while (count($payload) === 100);
|
||||
|
||||
return $pullRequests;
|
||||
}
|
||||
|
||||
private function request(string $baseUrl, string $token): PendingRequest
|
||||
{
|
||||
return Http::acceptJson()
|
||||
|
||||
Reference in New Issue
Block a user