diff --git a/Tests/Package/Repositories/CommitsTest.php b/Tests/Package/Repositories/CommitsTest.php index 319c4a57..1c9ef079 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -168,12 +168,12 @@ public function testgetSha() { $this->client->expects($this->once()) ->method('get') - ->with('/repos/{user}/{repo}/commits/{ref}') - ->willReturn($this->response); + ->with('/repos/{user}/{repo}/commits/{ref}', ['Accept' => 'application/vnd.github.sha']) + ->willReturn($this->getResponseObject('6dcb09b5b57875f334f61aebed695e2e4193db5e')); - $this->assertThat( - $this->object->getSha('{user}', '{repo}', '{ref}'), - $this->equalTo($this->sampleString) + $this->assertSame( + '6dcb09b5b57875f334f61aebed695e2e4193db5e', + $this->object->getSha('{user}', '{repo}', '{ref}') ); } diff --git a/docs/overview.md b/docs/overview.md index cfd53634..47a862ce 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -1,3 +1,9 @@ # Github API package TODO + +## The SHA of a commit reference + +`$github->repositories->commits->getSha($owner, $repo, $ref)` returns the SHA-1 of a branch, tag or commit as a +plain string. It asks GitHub for the `application/vnd.github.sha` media type; before, it returned the JSON of the +whole commit as a string. diff --git a/src/Package/Repositories/Commits.php b/src/Package/Repositories/Commits.php index 104c0428..4579e2e4 100644 --- a/src/Package/Repositories/Commits.php +++ b/src/Package/Repositories/Commits.php @@ -111,8 +111,8 @@ public function getSha($user, $repo, $ref) // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/commits/' . $ref; - // Send the request. - $response = $this->client->get($this->fetchUrl($path)); + // Send the request. This media type makes GitHub answer with the SHA only. + $response = $this->client->get($this->fetchUrl($path), ['Accept' => 'application/vnd.github.sha']); // Validate the response code. if ($response->getStatusCode() != 200) {