Skip to content
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

Fix #10: Use symfony http-client and respect proxy settings #33

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but the rest of the class assumes $releases is an object and I wanted to minimize refactoring for this PR


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