gitea/src/c0ee5592-e49f-4937-9b13-f43.../code.power

37 lines
882 B
Plaintext

/**
* Get a file or its LFS object from a repository.
*
* @param string $owner The owner name.
* @param string $repo The repository name.
* @param string $filepath The file path.
* @param string|null $ref The name of the commit/branch/tag. (Optional)
*
* @return string
* @since 3.2.0
*/
public function get(
string $owner,
string $repo,
string $filepath,
?string $ref = null
): string
{
// Build the request path.
$encodedFilepath = rawurlencode($filepath);
$path = "/repos/{$owner}/{$repo}/media/{$encodedFilepath}";
// Prepare the URI.
$uri = $this->uri->get($path);
// Add the 'ref' query parameter if provided.
if ($ref !== null)
{
$uri->setVar('ref', $ref);
}
// Send the GET request.
return $this->response->get(
$this->http->get($uri), 200, 'success'
);
}