diff --git a/src/Api/Action/MergeRequest/AbstractMergeRequestAction.php b/src/Api/Action/MergeRequest/AbstractMergeRequestAction.php index 79aeaab..fb51e8b 100644 --- a/src/Api/Action/MergeRequest/AbstractMergeRequestAction.php +++ b/src/Api/Action/MergeRequest/AbstractMergeRequestAction.php @@ -20,8 +20,7 @@ public function __construct( protected function resolveGitLabProject(string $nid): array { $issue = $this->client->getNode($nid); - $remoteName = $issue->fieldProjectMachineName . '-' . $nid; - $projectPath = 'issue/' . $remoteName; + $projectPath = 'project/' . $issue->fieldProjectMachineName; $project = $this->gitLabClient->getProject($projectPath); return [(int) $project->id, $projectPath]; } diff --git a/tests/src/Action/MergeRequest/GetMergeRequestDiffActionTest.php b/tests/src/Action/MergeRequest/GetMergeRequestDiffActionTest.php index 12e6b93..cc56f0a 100644 --- a/tests/src/Action/MergeRequest/GetMergeRequestDiffActionTest.php +++ b/tests/src/Action/MergeRequest/GetMergeRequestDiffActionTest.php @@ -70,6 +70,27 @@ private function makeAction(): GetMergeRequestDiffAction return new GetMergeRequestDiffAction($client, $gitLabClient); } + public function testResolvesMainProjectNotIssueFork(): void + { + $client = $this->createMock(Client::class); + $client->method('getNode')->willReturn(self::makeIssueNode()); + + $gitLabClient = $this->createMock(GitLabClient::class); + $gitLabClient->expects($this->once()) + ->method('getProject') + ->with('project/drupal') + ->willReturn(self::makeProject()); + $gitLabClient->method('getMergeRequest')->willReturn(self::makeMr()); + $gitLabClient->method('getMergeRequestDiffs')->willReturn([ + self::makeFileDiff("--- a/foo.php\n+++ b/foo.php\n@@ -1 +1 @@\n-old\n+new\n"), + ]); + + $action = new GetMergeRequestDiffAction($client, $gitLabClient); + $result = $action('3383637', 7); + + self::assertSame(7, $result->iid); + } + public function testUnifiedDiffConcatenation(): void { $client = $this->createMock(Client::class); diff --git a/tests/src/Action/MergeRequest/GetMergeRequestFilesActionTest.php b/tests/src/Action/MergeRequest/GetMergeRequestFilesActionTest.php index eaffb9d..deba9b1 100644 --- a/tests/src/Action/MergeRequest/GetMergeRequestFilesActionTest.php +++ b/tests/src/Action/MergeRequest/GetMergeRequestFilesActionTest.php @@ -64,7 +64,7 @@ public function testFileExtraction(): void $client->method('getNode')->with('3383637')->willReturn(self::makeIssueNode()); $gitLabClient = $this->createMock(GitLabClient::class); - $gitLabClient->method('getProject')->with('issue/drupal-3383637')->willReturn(self::makeProject()); + $gitLabClient->method('getProject')->with('project/drupal')->willReturn(self::makeProject()); $gitLabClient->method('getMergeRequestDiffs')->with(12345, 7)->willReturn([ self::makeFileDiff('src/Foo.php'), self::makeFileDiff('src/Bar.php', newFile: true), diff --git a/tests/src/Action/MergeRequest/ListMergeRequestsActionTest.php b/tests/src/Action/MergeRequest/ListMergeRequestsActionTest.php index 3a49cd7..85c54b3 100644 --- a/tests/src/Action/MergeRequest/ListMergeRequestsActionTest.php +++ b/tests/src/Action/MergeRequest/ListMergeRequestsActionTest.php @@ -70,7 +70,7 @@ public function testListWithStateFilter(): void $client->method('getNode')->with('3383637')->willReturn(self::makeIssueNode()); $gitLabClient = $this->createMock(GitLabClient::class); - $gitLabClient->method('getProject')->with('issue/drupal-3383637')->willReturn(self::makeProject()); + $gitLabClient->method('getProject')->with('project/drupal')->willReturn(self::makeProject()); $gitLabClient->expects($this->once()) ->method('getMergeRequests') ->with(12345, ['per_page' => 100, 'state' => 'opened']) @@ -80,7 +80,7 @@ public function testListWithStateFilter(): void $result = $action('3383637', MergeRequestState::Opened); self::assertInstanceOf(MergeRequestListResult::class, $result); - self::assertSame('issue/drupal-3383637', $result->projectPath); + self::assertSame('project/drupal', $result->projectPath); self::assertCount(1, $result->mergeRequests); self::assertInstanceOf(MergeRequestItem::class, $result->mergeRequests[0]); self::assertSame(7, $result->mergeRequests[0]->iid);