From 413912a7388a89b520aca65ba1e0020d2b28276c Mon Sep 17 00:00:00 2001 From: Anton Komarev Date: Thu, 16 Apr 2026 17:43:06 +0300 Subject: [PATCH] Add note award emoji methods to MergeRequests --- src/Api/MergeRequests.php | 20 +++++++++++ tests/Api/MergeRequestsTest.php | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/Api/MergeRequests.php b/src/Api/MergeRequests.php index 83d5b7d0..000689e3 100644 --- a/src/Api/MergeRequests.php +++ b/src/Api/MergeRequests.php @@ -308,11 +308,31 @@ public function awardEmoji(int|string $project_id, int $mr_iid): mixed return $this->get($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/award_emoji')); } + public function addAwardEmoji(int|string $project_id, int $mr_iid, string $name): mixed + { + return $this->post($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/award_emoji'), ['name' => $name]); + } + public function removeAwardEmoji(int|string $project_id, int $mr_iid, int $award_id): mixed { return $this->delete($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/award_emoji/'.self::encodePath($award_id))); } + public function showNoteAwardEmoji(int|string $project_id, int $mr_iid, int $note_id): mixed + { + return $this->get($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/notes/'.self::encodePath($note_id).'/award_emoji')); + } + + public function addNoteAwardEmoji(int|string $project_id, int $mr_iid, int $note_id, string $name): mixed + { + return $this->post($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/notes/'.self::encodePath($note_id).'/award_emoji'), ['name' => $name]); + } + + public function removeNoteAwardEmoji(int|string $project_id, int $mr_iid, int $note_id, int $award_id): mixed + { + return $this->delete($this->getProjectPath($project_id, 'merge_requests/'.self::encodePath($mr_iid).'/notes/'.self::encodePath($note_id).'/award_emoji/'.self::encodePath($award_id))); + } + public function rebase(int|string $project_id, int $mr_iid, array $params = []): mixed { $resolver = $this->createOptionsResolver(); diff --git a/tests/Api/MergeRequestsTest.php b/tests/Api/MergeRequestsTest.php index c0803014..19b0f8f8 100644 --- a/tests/Api/MergeRequestsTest.php +++ b/tests/Api/MergeRequestsTest.php @@ -582,6 +582,21 @@ public function shouldIssueMergeRequestAwardEmoji(): void $this->assertEquals($expectedArray, $api->awardEmoji(1, 2)); } + #[Test] + public function shouldAddMergeRequestAwardEmoji(): void + { + $expectedArray = ['id' => 1, 'name' => 'sparkles']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/merge_requests/2/award_emoji', ['name' => 'sparkles']) + ->willReturn($expectedArray) + ; + + $this->assertEquals($expectedArray, $api->addAwardEmoji(1, 2, 'sparkles')); + } + #[Test] public function shouldRevokeMergeRequestAwardEmoji(): void { @@ -596,6 +611,53 @@ public function shouldRevokeMergeRequestAwardEmoji(): void $this->assertEquals(true, $api->removeAwardEmoji(1, 2, 3)); } + #[Test] + public function shouldShowMergeRequestNoteAwardEmoji(): void + { + $expectedArray = [ + ['id' => 1, 'name' => 'sparkles'], + ['id' => 2, 'name' => 'heart_eyes'], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_requests/2/notes/3/award_emoji') + ->willReturn($expectedArray) + ; + + $this->assertEquals($expectedArray, $api->showNoteAwardEmoji(1, 2, 3)); + } + + #[Test] + public function shouldAddMergeRequestNoteAwardEmoji(): void + { + $expectedArray = ['id' => 1, 'name' => 'sparkles']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/merge_requests/2/notes/3/award_emoji', ['name' => 'sparkles']) + ->willReturn($expectedArray) + ; + + $this->assertEquals($expectedArray, $api->addNoteAwardEmoji(1, 2, 3, 'sparkles')); + } + + #[Test] + public function shouldRevokeMergeRequestNoteAwardEmoji(): void + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/merge_requests/2/notes/3/award_emoji/4') + ->willReturn($expectedBool); + + $this->assertEquals(true, $api->removeNoteAwardEmoji(1, 2, 3, 4)); + } + #[Test] public function shoudGetApprovalState(): void {