5 Commits
1.0.2 ... 1.0.3

Author SHA1 Message Date
785d0b43a2 Fixed errant operator 2021-08-26 12:54:55 -06:00
f468b67335 Repositories - Updated the getRawFile() method
+ Renamed the `getRawFile()` method to `getFileContents`
+ Updated the method to make it use the `/repos/{owner}/{repo}/contents/{filepath}` API route
2020-08-05 22:13:22 -06:00
d37650a882 Amendment - Fixed a bug in the new "getByID" method 2020-04-01 13:05:25 -06:00
e60312fab3 Repositories - Added a new "getById" method
+ Added a new method for retrieving repositories using their ID
2020-03-31 17:19:46 -06:00
cc6bd39f82 Tag Model - Fixed a tag ID related bug
+ Fixed a bug that was causing Acappella to only generate out composer packages for the most recent tag in each repository
2020-03-31 16:13:43 -06:00
3 changed files with 57 additions and 12 deletions

View File

@ -112,28 +112,73 @@ class Repositories extends AbstractAllApiRequester
}
/**
* Get the raw contents of a file stored inside a repository
* Get a repository using its ID
*
* Example:
* ```
* $client->repositories()->getByID($repoId);
* ```
*
* @param string repoId The ID of the repository
* @return Repository
*/
public function getById(int $repoId)
{
$client = $this->getClient();
try {
$response = $this->get("repositories/$repoId");
$statusCode = $response->getStatusCode();
$body = (string) $response->getBody();
if ($statusCode == 200) {
return Repository::fromJson(
$client,
$this,
json_decode($body)
);
}
return false;
} catch (ServerException $serverError) {
return false;
}
}
/**
* Get the contents of a file in a certain in repository commit/branch/tag
* using the repository's name and owner
*
* Example:
* ```
* $client->repositories()->getRawFile($owner, $repoName, "README.md");
* $client->repositories()->getRawFile($owner, $repoName, "README.md", "v2.0.0");
* ```
*
* @param string $owner The owner of the repository
* @param string $repoName The name of the repository
* @param string $filepath The path to the raw file (relative to the repository root)
* @param string $filepath The path to the file (relative to the repository root)
* @param string $ref The name of the commit/branch/tag. Default the repositorys default branch (usually master)
* @return string
*/
public function getRawFile(string $owner, string $repoName, string $filepath)
public function getFileContents(string $owner, string $repoName, string $filepath, string $ref="")
{
$client = $this->getClient();
try {
$response = $this->get("repos/$owner/$repoName/raw/$filepath");
if ($ref !== "") {
$response = $this->get("repos/$owner/$repoName/contents/$filepath",[
"ref" => $ref
]);
} else {
$response = $this->get("repos/$owner/$repoName/contents/$filepath");
}
$statusCode = $response->getStatusCode();
$body = (string) $response->getBody();
if ($statusCode == 200) {
return $body;
$body = (string) $response->getBody();
$jsonObj = json_decode($body, true);
if (array_key_exists("content", $jsonObj)) {
$base64FileContents = $jsonObj["content"];
$fileContents = base64_decode($base64FileContents);
return $fileContents;
}
}
return false;

View File

@ -66,7 +66,7 @@ class Client implements RequestChainableInterface
{
// Append a slash to any URL that doesn't end in '/'
if (!$this->endsWith($giteaURL, '/')) {
$giteaURL += "/";
$giteaURL .= "/";
}
$this->giteaURL = $giteaURL;
$this->authToken = $authToken;

View File

@ -44,9 +44,9 @@ class Tag extends AbstractApiModel {
if (count($args) >= 2) {
$id = $args[0];
$name = $args[1];
if (!is_numeric($id)) {
if (!is_string($id)) {
$argumentType = gettype($id);
throw new InvalidArgumentException("The \"__construct()\" function requires the 3rd parameter to be of the integer type, but a \"$argumentType\" was passed in");
throw new InvalidArgumentException("The \"__construct()\" function requires the 3rd parameter to be of the string type, but a \"$argumentType\" was passed in");
}
if (!is_string($name)) {
$argumentType = gettype($name);
@ -71,7 +71,7 @@ class Tag extends AbstractApiModel {
$newTag = new static(
$client,
$caller,
isset($map->id) && is_numeric($map->id) ? $map->id : -1,
isset($map->id) && is_string($map->id) ? $map->id : -1,
isset($map->name) && is_string($map->name) ? $map->name : ''
);
$newTag->setTarballURL(isset($map->tarball_url) && is_string($map->tarball_url) ? new Uri($map->tarball_url) : null);
@ -104,7 +104,7 @@ class Tag extends AbstractApiModel {
* Gets the tag identifier.
* @return int The tag identifier.
*/
function getId(): int {
function getId(): string {
return $this->id;
}