123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- import { throwGlobalError } from '../helpers/error';
- import { getJSON, post, postJSON } from '../helpers/request';
- import { BranchParameters } from '../types/branch-like';
- import {
- Analysis,
- ApplicationAnalysisEventCategory,
- ProjectAnalysisEventCategory,
- } from '../types/project-activity';
- import { Paging } from '../types/types';
-
- export enum ProjectActivityStatuses {
- STATUS_PROCESSED = 'P',
- STATUS_UNPROCESSED = 'U',
- STATUS_LIVE_MEASURE_COMPUTE = 'L',
- }
-
- export type ProjectActivityParams = {
- project?: string;
- statuses?: string;
- category?: string;
- from?: string;
- p?: number;
- ps?: number;
- } & BranchParameters;
-
- export interface ProjectActivityResponse {
- analyses: Analysis[];
- paging: Paging;
- }
-
- export function getProjectActivity(data: ProjectActivityParams): Promise<ProjectActivityResponse> {
- return getJSON('/api/project_analyses/search', data).catch(throwGlobalError);
- }
-
- const PROJECT_ACTIVITY_PAGE_SIZE = 500;
-
- export function getAllTimeProjectActivity(
- data: ProjectActivityParams,
- prev?: ProjectActivityResponse,
- ): Promise<ProjectActivityResponse> {
- return getProjectActivity({ ...data, ps: data.ps ?? PROJECT_ACTIVITY_PAGE_SIZE }).then((r) => {
- const result = prev
- ? {
- analyses: prev.analyses.concat(r.analyses),
- paging: r.paging,
- }
- : r;
-
- if (result.paging.pageIndex * result.paging.pageSize >= result.paging.total) {
- return result;
- }
-
- return getAllTimeProjectActivity(
- { ...data, ps: data.ps ?? PROJECT_ACTIVITY_PAGE_SIZE, p: result.paging.pageIndex + 1 },
- result,
- );
- });
- }
-
- export interface CreateEventResponse {
- analysis: string;
- key: string;
- name: string;
- category: ProjectAnalysisEventCategory | ApplicationAnalysisEventCategory;
- description?: string;
- }
-
- export function createEvent(data: {
- analysis: string;
- name: string;
- category?: string;
- description?: string;
- }): Promise<CreateEventResponse> {
- return postJSON('/api/project_analyses/create_event', data).then(
- (r) => r.event,
- throwGlobalError,
- );
- }
-
- export function deleteEvent(event: string): Promise<void | Response> {
- return post('/api/project_analyses/delete_event', { event }).catch(throwGlobalError);
- }
-
- export function changeEvent(data: {
- event: string;
- name?: string;
- description?: string;
- }): Promise<CreateEventResponse> {
- return postJSON('/api/project_analyses/update_event', data).then(
- (r) => r.event,
- throwGlobalError,
- );
- }
-
- export function deleteAnalysis(analysis: string): Promise<void | Response> {
- return post('/api/project_analyses/delete', { analysis }).catch(throwGlobalError);
- }
|