Skip to content

Commit

Permalink
feature #1146 List pull requests associated with a commit (lmjhs)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 3.15-dev branch.

Discussion
----------

Added missing `pulls` method to repository commits to allow fetching of pull requests for a commit sha.

[List pull requests associated with a commit](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit)

Commits
-------

46c1896 Commit Pulls
5727a43 Update tests
c0a48e2 Added documentation
  • Loading branch information
lmjhs authored Nov 7, 2024
1 parent 055cf51 commit d72323c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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

0 comments on commit d72323c

Please sign in to comment.