Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 { Variant } from 'design-system';
  21. import { isEmpty } from 'lodash';
  22. import { UpdateUseCase, sortUpgrades } from '../../../components/upgrade/utils';
  23. import { SystemUpgrade } from '../../../types/system';
  24. import { Dict } from '../../../types/types';
  25. type GroupedSystemUpdate = {
  26. [x: string]: Record<string, SystemUpgrade[]>;
  27. };
  28. export const isCurrentVersionLTA = (parsedVersion: number[], latestLTS: string) => {
  29. const [currentMajor, currentMinor] = parsedVersion;
  30. const [ltsMajor, ltsMinor] = latestLTS.split('.').map(Number);
  31. return currentMajor === ltsMajor && currentMinor === ltsMinor;
  32. };
  33. export const isMinorUpdate = (parsedVersion: number[], systemUpgrades: GroupedSystemUpdate) => {
  34. const [currentMajor, currentMinor] = parsedVersion;
  35. const allMinor = systemUpgrades[currentMajor];
  36. return Object.keys(allMinor)
  37. .map(Number)
  38. .some((minor) => minor > currentMinor);
  39. };
  40. export const isPatchUpdate = (parsedVersion: number[], systemUpgrades: GroupedSystemUpdate) => {
  41. const [currentMajor, currentMinor, currentPatch] = parsedVersion;
  42. const allMinor = systemUpgrades[currentMajor];
  43. const allPatch = sortUpgrades(allMinor?.[currentMinor] ?? []);
  44. if (!isEmpty(allPatch)) {
  45. const [, , latestPatch] = allPatch[0].version.split('.').map(Number);
  46. const effectiveCurrentPatch = isNaN(currentPatch) ? 0 : currentPatch;
  47. const effectiveLatestPatch = isNaN(latestPatch) ? 0 : latestPatch;
  48. return effectiveCurrentPatch < effectiveLatestPatch;
  49. }
  50. return false;
  51. };
  52. export const BANNER_VARIANT: Dict<Variant> = {
  53. [UpdateUseCase.NewVersion]: 'info',
  54. [UpdateUseCase.CurrentVersionInactive]: 'error',
  55. [UpdateUseCase.NewPatch]: 'warning',
  56. };