Skip to content

Commit 2e18dbd

Browse files
committed
feat(pull-request): add update-branch endpoint
1 parent 8522824 commit 2e18dbd

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎lib/Github/Api/PullRequest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ public function update($username, $repository, $id, array $params)
213213
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id), $params);
214214
}
215215

216+
/**
217+
* Update a pull request branch with the latest changes from its base branch.
218+
*
219+
* @link https://docs.github.com/en/rest/pulls/pulls#update-a-pull-request-branch
220+
*
221+
* @param string $username the username
222+
* @param string $repository the repository
223+
* @param string $id the ID of the pull request whose branch should be updated
224+
* @param array $params Optional request parameters such as expected_head_sha
225+
*
226+
* @return array|string
227+
*/
228+
public function updateBranch($username, $repository, $id, array $params = [])
229+
{
230+
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/update-branch', $params);
231+
}
232+
216233
/**
217234
* Check if a pull request has been merged.
218235
*

‎test/Github/Tests/Api/PullRequestTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ public function shouldUpdatePullRequests()
173173
$this->assertEquals($expectedArray, $api->update('ezsystems', 'ezpublish', 15, ['state' => 'aa', 'some' => 'param']));
174174
}
175175

176+
/**
177+
* @test
178+
*/
179+
public function shouldUpdatePullRequestBranch()
180+
{
181+
$expectedArray = ['message' => 'Update request accepted'];
182+
$params = ['expected_head_sha' => str_repeat('A', 40)];
183+
184+
$api = $this->getApiMock();
185+
$api->expects($this->once())
186+
->method('put')
187+
->with('/repos/ezsystems/ezpublish/pulls/15/update-branch', $params)
188+
->willReturn($expectedArray);
189+
190+
$this->assertSame($expectedArray, $api->updateBranch('ezsystems', 'ezpublish', 15, $params));
191+
}
192+
176193
/**
177194
* @test
178195
*/

0 commit comments

Comments
 (0)