From f800ad327673ac22a61289f1ccbc740f09ff1dab Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 12 Aug 2019 18:53:40 +0200 Subject: [PATCH] Missing gist revision api endpoint --- doc/gists.md | 6 ++++++ lib/Github/Api/Gists.php | 15 +++++++++++++++ test/Github/Tests/Api/GistsTest.php | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/doc/gists.md b/doc/gists.md index c106005927b..7db9f2c6cd5 100644 --- a/doc/gists.md +++ b/doc/gists.md @@ -37,6 +37,12 @@ $gists = $github->api('gists')->all(); $gist = $github->api('gists')->show(1); ``` +#### Get a specific revision of a gist + +```php +$gist = $github->api('gists')->show(1, 'd189dbd4c5d96442db74ebcb62bb38e661a0c8ce'); +``` + #### Get commits for a single gist ```php diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index a6f4ffa67c7..ee88c1292d1 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -51,6 +51,21 @@ public function show($number) return $this->get('/gists/'.rawurlencode($number)); } + /** + * Get a specific revision of a gist. + * + * @param int $number + * @param string $sha + * + * @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist + * + * @return array + */ + public function revision($number, $sha) + { + return $this->get('/gists/'.rawurlencode($number).'/'.rawurlencode($sha)); + } + public function create(array $params) { if (!isset($params['files']) || (!is_array($params['files']) || 0 === count($params['files']))) { diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 8e179693656..e0fba63a6c9 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -52,6 +52,22 @@ public function shouldShowGist() $this->assertEquals($expectedArray, $api->show(123)); } + /** + * @test + */ + public function shouldShowGistWithSpecificReference() + { + $expectedArray = ['id' => '123', 'sha' => 'd189dbd4c5d96442db74ebcb62bb38e661a0c8ce']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/gists/123/d189dbd4c5d96442db74ebcb62bb38e661a0c8ce') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->revision(123, 'd189dbd4c5d96442db74ebcb62bb38e661a0c8ce')); + } + /** * @test */