Skip to content
Open
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
10 changes: 5 additions & 5 deletions Tests/Package/Repositories/CommitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
);
}

Expand Down
6 changes: 6 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions src/Package/Repositories/Commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading