gitea/src/8c82b705-04bb-4bd2-ac09-3f5.../code.power

65 lines
1.5 KiB
Plaintext

/**
* Get available issue templates for a repository.
*
* @param string $owner The owner name.
* @param string $repo The repository name.
*
* @return array|null
* @since 3.2.0
**/
public function issue(string $owner, string $repo): ?array
{
// Build the request path.
$path = "/repos/{$owner}/{$repo}/issue_templates";
// Get the URI.
$uri = $this->uri->get($path);
// Send the GET request.
return $this->response->get(
$this->http->get($uri)
);
}
/**
* Create a repository using a template.
*
* @param string $templateOwner The template owner's name.
* @param string $templateRepo The template repository name.
* @param string $name The name of the new repository.
* @param array $options Optional. Additional options for the new repository.
*
* @return object|null
* @since 3.2.0
**/
public function repo(
string $templateOwner,
string $templateRepo,
string $name,
array $options = []
): ?object
{
// Build the request path.
$path = "/repos/{$templateOwner}/{$templateRepo}/generate";
// Set the repo data.
$data = new \stdClass();
$data->name = $name;
foreach ($options as $key => $value)
{
if ($value !== null)
{
$data->{$key} = $value;
}
}
// Send the post request.
return $this->response->get(
$this->http->post(
$this->uri->get($path),
json_encode($data)
), 201
);
}