Add ticket-driven branch creation flow
This commit is contained in:
@@ -34,6 +34,30 @@ class GiteaProviderClient implements GitProviderClient
|
||||
);
|
||||
}
|
||||
|
||||
public function getRepository(
|
||||
string $baseUrl,
|
||||
string $token,
|
||||
string $owner,
|
||||
string $repository,
|
||||
): GitRepository {
|
||||
/** @var array{
|
||||
* default_branch?: string|null,
|
||||
* id: int|string,
|
||||
* name: string,
|
||||
* full_name: string,
|
||||
* html_url: string,
|
||||
* owner: array{login: string},
|
||||
* private: bool
|
||||
* } $payload
|
||||
*/
|
||||
$payload = $this->request($baseUrl, $token)
|
||||
->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository))
|
||||
->throw()
|
||||
->json();
|
||||
|
||||
return $this->mapRepository($payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, GitRepository>
|
||||
*/
|
||||
@@ -61,14 +85,7 @@ class GiteaProviderClient implements GitProviderClient
|
||||
->json();
|
||||
|
||||
foreach ($payload as $repository) {
|
||||
$repositories[] = new GitRepository(
|
||||
providerRepositoryId: (string) $repository['id'],
|
||||
owner: $repository['owner']['login'],
|
||||
name: $repository['name'],
|
||||
fullName: $repository['full_name'],
|
||||
htmlUrl: $repository['html_url'],
|
||||
isPrivate: $repository['private'],
|
||||
);
|
||||
$repositories[] = $this->mapRepository($repository);
|
||||
}
|
||||
|
||||
$page++;
|
||||
@@ -166,6 +183,36 @@ class GiteaProviderClient implements GitProviderClient
|
||||
return $pullRequests;
|
||||
}
|
||||
|
||||
public function createBranch(
|
||||
string $baseUrl,
|
||||
string $token,
|
||||
string $owner,
|
||||
string $repository,
|
||||
string $newBranchName,
|
||||
?string $oldRefName = null,
|
||||
): GitBranch {
|
||||
$payload = [
|
||||
'new_branch_name' => $newBranchName,
|
||||
];
|
||||
|
||||
if ($oldRefName !== null && $oldRefName !== '') {
|
||||
$payload['old_ref_name'] = $oldRefName;
|
||||
}
|
||||
|
||||
/** @var array{name: string} $response */
|
||||
$response = $this->request($baseUrl, $token)
|
||||
->post(
|
||||
'/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/branches',
|
||||
$payload,
|
||||
)
|
||||
->throw()
|
||||
->json();
|
||||
|
||||
return new GitBranch(
|
||||
name: $response['name'],
|
||||
);
|
||||
}
|
||||
|
||||
private function request(string $baseUrl, string $token): PendingRequest
|
||||
{
|
||||
return Http::acceptJson()
|
||||
@@ -189,4 +236,30 @@ class GiteaProviderClient implements GitProviderClient
|
||||
->append('/api/v1')
|
||||
->value();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{
|
||||
* default_branch?: string|null,
|
||||
* id: int|string,
|
||||
* name: string,
|
||||
* full_name: string,
|
||||
* html_url: string,
|
||||
* owner: array{login: string},
|
||||
* private: bool
|
||||
* } $repository
|
||||
*/
|
||||
private function mapRepository(array $repository): GitRepository
|
||||
{
|
||||
return new GitRepository(
|
||||
providerRepositoryId: (string) $repository['id'],
|
||||
owner: $repository['owner']['login'],
|
||||
name: $repository['name'],
|
||||
fullName: $repository['full_name'],
|
||||
htmlUrl: $repository['html_url'],
|
||||
defaultBranch: blank($repository['default_branch'] ?? null)
|
||||
? null
|
||||
: $repository['default_branch'],
|
||||
isPrivate: $repository['private'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user