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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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, RequestData } from '../helpers/request';
  22. import { BranchParameters } from '../types/branch-like';
  23. import { Analysis, Paging } from '../types/types';
  24. export enum ProjectActivityStatuses {
  25. STATUS_PROCESSED = 'P',
  26. STATUS_UNPROCESSED = 'U',
  27. STATUS_LIVE_MEASURE_COMPUTE = 'L'
  28. }
  29. export function getProjectActivity(
  30. data: {
  31. project: string;
  32. statuses?: string;
  33. category?: string;
  34. from?: string;
  35. p?: number;
  36. ps?: number;
  37. } & BranchParameters
  38. ): Promise<{ analyses: Analysis[]; paging: Paging }> {
  39. return getJSON('/api/project_analyses/search', data).catch(throwGlobalError);
  40. }
  41. interface CreateEventResponse {
  42. analysis: string;
  43. key: string;
  44. name: string;
  45. category: string;
  46. description?: string;
  47. }
  48. export function createEvent(
  49. analysis: string,
  50. name: string,
  51. category?: string,
  52. description?: string
  53. ): Promise<CreateEventResponse> {
  54. const data: RequestData = { analysis, name };
  55. if (category) {
  56. data.category = category;
  57. }
  58. if (description) {
  59. data.description = description;
  60. }
  61. return postJSON('/api/project_analyses/create_event', data).then(r => r.event, throwGlobalError);
  62. }
  63. export function deleteEvent(event: string): Promise<void | Response> {
  64. return post('/api/project_analyses/delete_event', { event }).catch(throwGlobalError);
  65. }
  66. export function changeEvent(
  67. event: string,
  68. name?: string,
  69. description?: string
  70. ): Promise<CreateEventResponse> {
  71. const data: RequestData = { event };
  72. if (name) {
  73. data.name = name;
  74. }
  75. if (description) {
  76. data.description = description;
  77. }
  78. return postJSON('/api/project_analyses/update_event', data).then(r => r.event, throwGlobalError);
  79. }
  80. export function deleteAnalysis(analysis: string): Promise<void | Response> {
  81. return post('/api/project_analyses/delete', { analysis }).catch(throwGlobalError);
  82. }