Skip to content
Snippets Groups Projects

Use GitLab project ID directly, throw exceptions if it doesn’t work

Merged Neil Drumm requested to merge rely-on-gitlab-ids into 1.0.x
1 file
+ 8
12
Compare changes
  • Side-by-side
  • Inline
@@ -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'],
],
]);
Loading