From 9462004d3c6e587578ccd8768cfa3606e4d0bee0 Mon Sep 17 00:00:00 2001
From: Neil Drumm <drumm@delocalizedham.com>
Date: Thu, 27 Feb 2025 17:12:52 -0500
Subject: [PATCH] =?UTF-8?q?Use=20GitLab=20project=20ID=20directly,=20throw?=
 =?UTF-8?q?=20exceptions=20if=20it=20doesn=E2=80=99t=20work?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ...upalOrgSecurityIssueWebhookQueueWorker.php | 20 ++++++++-----------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/Plugin/QueueWorker/DrupalOrgSecurityIssueWebhookQueueWorker.php b/src/Plugin/QueueWorker/DrupalOrgSecurityIssueWebhookQueueWorker.php
index a7aac965..d94ca679 100644
--- a/src/Plugin/QueueWorker/DrupalOrgSecurityIssueWebhookQueueWorker.php
+++ b/src/Plugin/QueueWorker/DrupalOrgSecurityIssueWebhookQueueWorker.php
@@ -115,12 +115,6 @@ class DrupalOrgSecurityIssueWebhookQueueWorker extends QueueWorkerBase implement
 
       $project_machine_name = $project_node->get('field_project_machine_name')->value;
       $repository_info = $this->projectService->getProjectRepositoryInformation($project_node);
-      $repository_id = $repository_info['gitlab_project_id'] ?? $repository_info['gitlab_namespace'] . '/' . $repository_info['gitlab_project_name'];
-      if ($repository_id === '/') {
-        $repository_id = $project_machine_name;
-      }
-
-      $gitlab_project_id = (int) $gitlab_client->projects()->show($repository_id)['id'];
 
       // Fork project.
       $name = $iid . '-' . $project_machine_name . '-security';
@@ -140,9 +134,9 @@ class DrupalOrgSecurityIssueWebhookQueueWorker extends QueueWorkerBase implement
       $this->logger->notice('Moving @issue for @project (@gitlab_project_id)', [
         '@issue' => $gitlab_issue['web_url'],
         '@project' => $project_machine_name,
-        '@gitlab_project_id' => $gitlab_project_id,
+        '@gitlab_project_id' => $repository_info['gitlab_project_id'],
       ]);
-      $fork_project = $gitlab_client->projects()->fork($gitlab_project_id, [
+      $fork_project = $gitlab_client->projects()->fork($repository_info['gitlab_project_id'], [
         'namespace_path' => 'security',
         'path' => $name,
         'name' => $name,
@@ -152,7 +146,7 @@ class DrupalOrgSecurityIssueWebhookQueueWorker extends QueueWorkerBase implement
 
       // Add reporter & maintainers.
       if ($project_machine_name !== 'drupal') {
-        $member_ids = array_column((new ResultPager($gitlab_client))->fetchAll($gitlab_client->projects(), 'members', [$gitlab_project_id]), 'id');
+        $member_ids = array_column((new ResultPager($gitlab_client))->fetchAll($gitlab_client->projects(), 'members', [$repository_info['gitlab_project_id']]), 'id');
         $member_ids[] = $gitlab_issue['author']['id'];
         foreach ($member_ids as $gitlab_user_id) {
           try {
@@ -243,11 +237,13 @@ Maintainers: Please help triage this issue by validating if you can reproduce th
 
       // Check for added Security advisory::needed label.
       if (!empty($data['current_labels']['Security advisory::needed']) && empty($data['previous_labels']['Security advisory::needed'])) {
-        $drupal_project = $this->projectService->getProjectByRepositoryPath($project['forked_from_project']['path']);
-        $field_project = $drupal_project ? $drupal_project->get('field_project_machine_name')->value : $project['forked_from_project']['path'];
+        $project_node = $this->projectService->getProjectByRepositoryPath($project['forked_from_project']['id']);
+        if (empty($project_node)) {
+          throw new \Exception('GitLab project ID ' . $project['forked_from_project']['id'] . ' not found.');
+        }
         $url = Url::fromUri('https://www.drupal.org/node/add/sa', [
           'query' => [
-            'field_project' => $field_project,
+            'field_project' => $project_node->get('field_project_machine_name')->value,
             'issue' => $issue['web_url'],
           ],
         ]);
-- 
GitLab