URL-encode branch refs in DevPullCommand GitHub API requests - #20
Conversation
Co-authored-by: sak0a <24781653+sak0a@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes GitHub API 404s in DevPullCommand when branch refs contain slashes or other special characters by URL-encoding the ref used in the /commits/{ref} endpoint, and adds unit tests to lock in the behavior.
Changes:
- URL-encode the
$refpath segment infetchCommitInfo()usingrawurlencode(). - Add unit tests covering refs with slashes, spaces/special characters, simple branch names, and commit SHAs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Console/Commands/DevPullCommand.php |
Encodes the commit ref before interpolating it into the GitHub API URL to avoid path breakage. |
tests/Unit/Console/DevPullCommandTest.php |
Adds tests that assert the generated GitHub API request URL contains the encoded ref for various inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| use Orchestra\Testbench\TestCase; | ||
|
|
||
| class DevPullCommandTest extends TestCase | ||
| { | ||
| protected function getPackageProviders($app): array | ||
| { | ||
| return [NoturServiceProvider::class]; | ||
| } | ||
|
|
||
| protected function getEnvironmentSetUp($app): void | ||
| { | ||
| $app['config']->set('database.default', 'testing'); | ||
| $app['config']->set('database.connections.testing', [ | ||
| 'driver' => 'sqlite', | ||
| 'database' => ':memory:', | ||
| 'prefix' => '', | ||
| ]); | ||
| $app['config']->set('notur.repository', 'sak0a/notur'); | ||
| } |
There was a problem hiding this comment.
This test class extends Orchestra\Testbench\TestCase and boots NoturServiceProvider + DB config, but the tests only invoke a private method with a provided Guzzle client and don’t use the Laravel application/container. Consider switching to PHPUnit\Framework\TestCase (as most unit tests do) and removing getPackageProviders()/getEnvironmentSetUp() to reduce test runtime and avoid unnecessary framework coupling.
| // Create a mock handler to capture HTTP requests | ||
| $container = []; | ||
| $history = Middleware::history($container); | ||
|
|
||
| $mock = new MockHandler([ | ||
| new Response(200, [], json_encode([ | ||
| 'sha' => 'abc123def456', | ||
| 'commit' => [ | ||
| 'message' => 'Test commit', | ||
| 'author' => [ | ||
| 'name' => 'Test Author', | ||
| 'date' => '2026-02-07T12:00:00Z', | ||
| ], | ||
| ], | ||
| ])), | ||
| ]); | ||
|
|
||
| $handlerStack = HandlerStack::create($mock); | ||
| $handlerStack->push($history); | ||
|
|
||
| // Test with a branch name containing slashes | ||
| $client = new Client(['handler' => $handlerStack]); | ||
|
|
||
| $command = new DevPullCommand(); | ||
| $reflection = new \ReflectionClass($command); | ||
| $method = $reflection->getMethod('fetchCommitInfo'); | ||
| $method->setAccessible(true); | ||
|
|
||
| $method->invoke($command, $client, 'sak0a/notur', 'feature/my-branch'); |
There was a problem hiding this comment.
The mock handler + history + reflection setup is duplicated in each test case. Refactoring this into a small helper (e.g., a method that returns [$client, &$container, $invokeFetchCommitInfo]) would reduce repetition and make it easier to add more encoding cases later.
Branch names containing slashes (e.g.,
feature/auth-fix) were being interpolated directly into GitHub API URLs, breaking the path structure and causing 404s.Changes:
$refparameter usingrawurlencode()infetchCommitInfo()before building API URLExample:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.