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
17 changes: 17 additions & 0 deletions lib/Github/Api/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ public function update($username, $repository, $id, array $params)
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id), $params);
}

/**
* Update a pull request branch with the latest changes from its base branch.
*
* @link https://docs.github.com/en/rest/pulls/pulls#update-a-pull-request-branch
*
* @param string $username the username
* @param string $repository the repository
* @param string $id the ID of the pull request whose branch should be updated
* @param array $params Optional request parameters such as expected_head_sha
*
* @return array|string
*/
public function updateBranch($username, $repository, $id, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/update-branch', $params);
}

public function merged($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge');
Expand Down
17 changes: 17 additions & 0 deletions test/Github/Tests/Api/PullRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ public function shouldUpdatePullRequests()
$this->assertEquals($expectedArray, $api->update('ezsystems', 'ezpublish', 15, ['state' => 'aa', 'some' => 'param']));
}

/**
* @test
*/
public function shouldUpdatePullRequestBranch()
{
$expectedArray = ['message' => 'Update request accepted'];
$params = ['expected_head_sha' => str_repeat('A', 40)];

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('/repos/ezsystems/ezpublish/pulls/15/update-branch', $params)
->willReturn($expectedArray);

$this->assertSame($expectedArray, $api->updateBranch('ezsystems', 'ezpublish', 15, $params));
}

/**
* @test
*/
Expand Down
Loading