Skip to content

Commit

Permalink
Fix #10: Use symfony http-client and respect proxy settings (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored Jul 18, 2024
1 parent 48b166b commit e3cc75a
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 13 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"php": "^8.1",
"composer/semver": "^3.2",
"symfony/console": "^5.4 || ^6.4 || ^7",
"symfony/filesystem": "^5.4 || ^6.4 || ^7"
"symfony/filesystem": "^5.4 || ^6.4 || ^7",
"symfony/http-client": "^5.4 || ^6.4 || ^7"
},
"bin": [
"scripts/release"
Expand Down
224 changes: 223 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions src/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem as sfFilesystem;
use Symfony\Component\HttpClient\HttpClient;
use UnexpectedValueException;

/**
Expand Down Expand Up @@ -75,26 +76,27 @@ protected function configure(): void
/**
* Get all releases from GitHub.
*
* @throws \Exception
*
* @return array
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*
* @throws \Exception
*/
protected function getReleasesFromGithub(): array
{
$version_parser = new VersionParser();

$opts = [
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: ' . $this->applicationName . ' (' . $this->gitHubRepository . ')' . ' Self-Update (PHP)',
],
'headers' => [
'User-Agent' => $this->applicationName . ' (' . $this->gitHubRepository . ')' . ' Self-Update (PHP)',
],
];
$client = HttpClient::create($opts);
$response = $client->request(
'GET',
'https://api.github.com/repos/' . $this->gitHubRepository . '/releases'
);

$context = stream_context_create($opts);

$releases = file_get_contents('https://api.github.com/repos/' . $this->gitHubRepository . '/releases', false, $context);
$releases = json_decode($releases);
$releases = json_decode($response->getContent(), FALSE, 512, JSON_THROW_ON_ERROR);

if (!isset($releases[0])) {
throw new \Exception('API error - no release found at GitHub repository ' . $this->gitHubRepository);
Expand Down

0 comments on commit e3cc75a

Please sign in to comment.