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.

ce.ts 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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 '../app/utils/throwGlobalError';
  21. import { getJSON, post, RequestData } from '../helpers/request';
  22. import { IndexationStatus } from '../types/indexation';
  23. import { Task, TaskWarning } from '../types/tasks';
  24. export function getAnalysisStatus(data: {
  25. component: string;
  26. branch?: string;
  27. pullRequest?: string;
  28. }): Promise<{
  29. component: {
  30. branch?: string;
  31. key: string;
  32. name: string;
  33. pullRequest?: string;
  34. warnings: TaskWarning[];
  35. };
  36. }> {
  37. return getJSON('/api/ce/analysis_status', data).catch(throwGlobalError);
  38. }
  39. export function getActivity(data: RequestData): Promise<{ tasks: Task[] }> {
  40. return getJSON('/api/ce/activity', data);
  41. }
  42. export function getStatus(
  43. component?: string
  44. ): Promise<{ failing: number; inProgress: number; pending: number; pendingTime?: number }> {
  45. return getJSON('/api/ce/activity_status', { component });
  46. }
  47. export function getTask(id: string, additionalFields?: string[]): Promise<Task> {
  48. return getJSON('/api/ce/task', { id, additionalFields }).then(r => r.task);
  49. }
  50. export function cancelTask(id: string): Promise<any> {
  51. return post('/api/ce/cancel', { id }).then(
  52. () => getTask(id),
  53. () => getTask(id)
  54. );
  55. }
  56. export function cancelAllTasks(): Promise<any> {
  57. return post('/api/ce/cancel_all');
  58. }
  59. export function getTasksForComponent(component: string): Promise<{ queue: Task[]; current: Task }> {
  60. return getJSON('/api/ce/component', { component }).catch(throwGlobalError);
  61. }
  62. export function getTypes(): Promise<string[]> {
  63. return getJSON('/api/ce/task_types').then(r => r.taskTypes);
  64. }
  65. export function getWorkers(): Promise<{ canSetWorkerCount: boolean; value: number }> {
  66. return getJSON('/api/ce/worker_count').catch(throwGlobalError);
  67. }
  68. export function setWorkerCount(count: number): Promise<void | Response> {
  69. return post('/api/ce/set_worker_count', { count }).catch(throwGlobalError);
  70. }
  71. export function getIndexationStatus(): Promise<IndexationStatus> {
  72. return getJSON('/api/ce/indexation_status').catch(throwGlobalError);
  73. }
  74. export function dismissAnalysisWarning(component: string, warning: string) {
  75. return post('/api/ce/dismiss_analysis_warning', { component, warning }).catch(throwGlobalError);
  76. }