From 9680810f247fd0bce533666fa16fa5fd6b352250 Mon Sep 17 00:00:00 2001 From: Nicholas Ciechanowski Date: Wed, 22 Apr 2026 11:12:41 +1000 Subject: [PATCH] feat(pull-request): add update-branch endpoint --- lib/Github/Api/PullRequest.php | 17 +++++++++++++++++ test/Github/Tests/Api/PullRequestTest.php | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 22922c1ee92..76422985f6b 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -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'); diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 54cc34f55e0..19660d5e829 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -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 */