Skip to content

Fix #83, Return nothing if no new version is available #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/SourceRepositoryTypes/HttpRepositoryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Codedge\Updater\Events\UpdateSucceeded;
use Codedge\Updater\Traits\SupportPrivateAccessToken;
use Codedge\Updater\Traits\UseVersionFile;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\File;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function __construct(Client $client, array $config)
* @param string $currentVersion
*
* @throws \InvalidArgumentException
* @throws \Exception
* @throws Exception
*
* @return bool
*/
Expand Down Expand Up @@ -102,14 +103,14 @@ public function isNewVersionAvailable($currentVersion = ''): bool
*
* @param string $version
*
* @throws \Exception
* @throws Exception
*
* @return mixed
*/
public function fetch($version = '')
{
if (($releaseCollection = $this->getPackageReleases())->isEmpty()) {
throw new \Exception('Cannot find a release to update. Please check the repository you\'re pulling from');
throw new Exception('Cannot find a release to update. Please check the repository you\'re pulling from');
}

$release = $releaseCollection->first();
Expand All @@ -122,7 +123,7 @@ public function fetch($version = '')
if (! $version) {
$release = $releaseCollection->where('name', $version)->first();
if (! $release) {
throw new \Exception('Given version was not found in release list.');
throw new Exception('Given version was not found in release list.');
}
}

Expand Down Expand Up @@ -205,21 +206,19 @@ public function getVersionInstalled($prepend = '', $append = ''): string
* Example: 2.6.5 or v2.6.5.
*
* @param string $prepend Prepend a string to the latest version
* @param string $append Append a string to the latest version
*
* @throws \Exception
* @param string $append Append a string to the latest version
*
* @return string
* @throws Exception
*/
public function getVersionAvailable($prepend = '', $append = ''): string
{
$version = '';
if ($this->versionFileExists()) {
$version = $this->getVersionFile();
} else {
$releaseCollection = $this->getPackageReleases();
if ($releaseCollection->isEmpty()) {
throw new \Exception('Retrieved version list is empty.');
return '';
}
$version = $releaseCollection->first()->name;
}
Expand All @@ -230,14 +229,14 @@ public function getVersionAvailable($prepend = '', $append = ''): string
/**
* Retrieve html body with list of all releases from archive URL.
*
*@throws \Exception
*@throws Exception
*
* @return mixed|ResponseInterface
*/
protected function getPackageReleases()
{
if (empty($url = $this->config['repository_url'])) {
throw new \Exception('No repository specified. Please enter a valid URL in your config.');
throw new Exception('No repository specified. Please enter a valid URL in your config.');
}

$format = str_replace('_VERSION_', '\d+\.\d+\.\d+',
Expand Down