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

List pull requests associated with a commit #1146

Merged
merged 3 commits into from
Nov 7, 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
8 changes: 8 additions & 0 deletions doc/commits.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ $commit = $client->api('repo')->commits()->compare('KnpLabs', 'php-github-api',
```

Returns an array of commits.

### List pull requests associated with a commit

```php
$commit = $client->api('repo')->commits()->pulls('KnpLabs', 'php-github-api', '839e5185da9434753db47959bee16642bb4f2ce4');
```

Returns an array of pull requests.
5 changes: 5 additions & 0 deletions lib/Github/Api/Repository/Commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function show($username, $repository, $sha)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha));
}

public function pulls($username, $repository, $sha, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/pulls', $params);
}
}
19 changes: 19 additions & 0 deletions test/Github/Tests/Api/Repository/CommitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ public function shouldShowCommitUsingSha()
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123));
}

/**
* @test
*/
public function shouldGetAllPullRequestsUsingSha()
{
$expectedValue = [
['number' => '1', 'title' => 'My first PR'],
['number' => '2', 'title' => 'Another PR'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/commits/123/pulls')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->pulls('KnpLabs', 'php-github-api', 123));
}

/**
* @return string
*/
Expand Down