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.

projectActivity.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 { throwGlobalError } from '../helpers/error';
  21. import { getJSON, post, postJSON } from '../helpers/request';
  22. import { BranchParameters } from '../types/branch-like';
  23. import {
  24. Analysis,
  25. ApplicationAnalysisEventCategory,
  26. ProjectAnalysisEventCategory,
  27. } from '../types/project-activity';
  28. import { Paging } from '../types/types';
  29. export enum ProjectActivityStatuses {
  30. STATUS_PROCESSED = 'P',
  31. STATUS_UNPROCESSED = 'U',
  32. STATUS_LIVE_MEASURE_COMPUTE = 'L',
  33. }
  34. export type ProjectActivityParams = {
  35. project?: string;
  36. statuses?: string;
  37. category?: string;
  38. from?: string;
  39. p?: number;
  40. ps?: number;
  41. } & BranchParameters;
  42. export interface ProjectActivityResponse {
  43. analyses: Analysis[];
  44. paging: Paging;
  45. }
  46. export function getProjectActivity(data: ProjectActivityParams): Promise<ProjectActivityResponse> {
  47. return getJSON('/api/project_analyses/search', data).catch(throwGlobalError);
  48. }
  49. const PROJECT_ACTIVITY_PAGE_SIZE = 500;
  50. export function getAllTimeProjectActivity(
  51. data: ProjectActivityParams,
  52. prev?: ProjectActivityResponse,
  53. ): Promise<ProjectActivityResponse> {
  54. return getProjectActivity({ ...data, ps: data.ps ?? PROJECT_ACTIVITY_PAGE_SIZE }).then((r) => {
  55. const result = prev
  56. ? {
  57. analyses: prev.analyses.concat(r.analyses),
  58. paging: r.paging,
  59. }
  60. : r;
  61. if (result.paging.pageIndex * result.paging.pageSize >= result.paging.total) {
  62. return result;
  63. }
  64. return getAllTimeProjectActivity(
  65. { ...data, ps: data.ps ?? PROJECT_ACTIVITY_PAGE_SIZE, p: result.paging.pageIndex + 1 },
  66. result,
  67. );
  68. });
  69. }
  70. export interface CreateEventResponse {
  71. analysis: string;
  72. key: string;
  73. name: string;
  74. category: ProjectAnalysisEventCategory | ApplicationAnalysisEventCategory;
  75. description?: string;
  76. }
  77. export function createEvent(data: {
  78. analysis: string;
  79. name: string;
  80. category?: string;
  81. description?: string;
  82. }): Promise<CreateEventResponse> {
  83. return postJSON('/api/project_analyses/create_event', data).then(
  84. (r) => r.event,
  85. throwGlobalError,
  86. );
  87. }
  88. export function deleteEvent(event: string): Promise<void | Response> {
  89. return post('/api/project_analyses/delete_event', { event }).catch(throwGlobalError);
  90. }
  91. export function changeEvent(data: {
  92. event: string;
  93. name?: string;
  94. description?: string;
  95. }): Promise<CreateEventResponse> {
  96. return postJSON('/api/project_analyses/update_event', data).then(
  97. (r) => r.event,
  98. throwGlobalError,
  99. );
  100. }
  101. export function deleteAnalysis(analysis: string): Promise<void | Response> {
  102. return post('/api/project_analyses/delete', { analysis }).catch(throwGlobalError);
  103. }