You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

import-projects.ts 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { useIsMutating, useMutation } from '@tanstack/react-query';
  21. import {
  22. importAzureRepository,
  23. importBitbucketCloudRepository,
  24. importBitbucketServerProject,
  25. importGithubRepository,
  26. importGitlabProject,
  27. } from '../api/alm-integrations';
  28. import { createImportedProjects } from '../api/dop-translation';
  29. import { createProject } from '../api/project-management';
  30. import { ImportProjectParam } from '../apps/create/project/CreateProjectPage';
  31. import { CreateProjectModes } from '../apps/create/project/types';
  32. export type MutationArg<AlmImport extends ImportProjectParam = ImportProjectParam> =
  33. AlmImport extends {
  34. creationMode: infer A;
  35. almSetting: string;
  36. projects: (infer R)[];
  37. }
  38. ? { creationMode: A; almSetting: string } & R
  39. :
  40. | {
  41. creationMode: CreateProjectModes.Manual;
  42. project: string;
  43. name: string;
  44. mainBranch: string;
  45. }
  46. | {
  47. creationMode: CreateProjectModes.Monorepo;
  48. devOpsPlatformSettingId: string;
  49. monorepo: boolean;
  50. projectKey: string;
  51. projectName: string;
  52. repositoryIdentifier: string;
  53. };
  54. export function useImportProjectMutation() {
  55. return useMutation({
  56. mutationFn: (
  57. data: {
  58. newCodeDefinitionType?: string;
  59. newCodeDefinitionValue?: string;
  60. } & MutationArg,
  61. ) => {
  62. if (data.creationMode === CreateProjectModes.GitHub) {
  63. return importGithubRepository(data);
  64. } else if (data.creationMode === CreateProjectModes.AzureDevOps) {
  65. return importAzureRepository(data);
  66. } else if (data.creationMode === CreateProjectModes.BitbucketCloud) {
  67. return importBitbucketCloudRepository(data);
  68. } else if (data.creationMode === CreateProjectModes.BitbucketServer) {
  69. return importBitbucketServerProject(data);
  70. } else if (data.creationMode === CreateProjectModes.GitLab) {
  71. return importGitlabProject(data);
  72. } else if (data.creationMode === CreateProjectModes.Monorepo) {
  73. return createImportedProjects(data);
  74. }
  75. return createProject(data);
  76. },
  77. mutationKey: ['import'],
  78. });
  79. }
  80. export function useImportProjectProgress() {
  81. return useIsMutating({ mutationKey: ['import'] });
  82. }