123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- /*
- * SonarQube
- * Copyright (C) 2009-2021 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 { map } from 'lodash';
- import throwGlobalError from '../app/utils/throwGlobalError';
- import { Exporter, ProfileChangelogEvent } from '../apps/quality-profiles/types';
- import { csvEscape } from '../helpers/csv';
- import { getJSON, post, postJSON, RequestData } from '../helpers/request';
-
- export interface ProfileActions {
- associateProjects?: boolean;
- copy?: boolean;
- delete?: boolean;
- edit?: boolean;
- setAsDefault?: boolean;
- }
-
- export interface Actions {
- create?: boolean;
- }
-
- export interface Profile {
- actions?: ProfileActions;
- key: string;
- name: string;
- language: string;
- languageName: string;
- isInherited?: boolean;
- parentKey?: string;
- parentName?: string;
- isDefault?: boolean;
- activeRuleCount: number;
- activeDeprecatedRuleCount: number;
- rulesUpdatedAt?: string;
- lastUsed?: string;
- userUpdatedAt?: string;
- isBuiltIn?: boolean;
- projectCount?: number;
- }
-
- export interface SearchQualityProfilesParameters {
- defaults?: boolean;
- language?: string;
- project?: string;
- qualityProfile?: string;
- }
-
- export interface SearchQualityProfilesResponse {
- actions?: Actions;
- profiles: Profile[];
- }
-
- export function searchQualityProfiles(
- parameters?: SearchQualityProfilesParameters
- ): Promise<SearchQualityProfilesResponse> {
- return getJSON('/api/qualityprofiles/search', parameters).catch(throwGlobalError);
- }
-
- export function getQualityProfile({
- compareToSonarWay,
- profile: { key }
- }: {
- compareToSonarWay?: boolean;
- profile: Profile;
- }): Promise<any> {
- return getJSON('/api/qualityprofiles/show', { compareToSonarWay, key });
- }
-
- export function createQualityProfile(data: RequestData): Promise<any> {
- return postJSON('/api/qualityprofiles/create', data).catch(throwGlobalError);
- }
-
- export function restoreQualityProfile(data: RequestData): Promise<any> {
- return postJSON('/api/qualityprofiles/restore', data).catch(throwGlobalError);
- }
-
- export interface ProfileProject {
- key: string;
- name: string;
- selected: boolean;
- }
-
- export function getProfileProjects(
- data: RequestData
- ): Promise<{ more: boolean; paging: T.Paging; results: ProfileProject[] }> {
- return getJSON('/api/qualityprofiles/projects', data).catch(throwGlobalError);
- }
-
- export function getProfileInheritance({
- language,
- name: qualityProfile
- }: Profile): Promise<{
- ancestors: T.ProfileInheritanceDetails[];
- children: T.ProfileInheritanceDetails[];
- profile: T.ProfileInheritanceDetails;
- }> {
- return getJSON('/api/qualityprofiles/inheritance', {
- language,
- qualityProfile
- }).catch(throwGlobalError);
- }
-
- export function setDefaultProfile({ language, name: qualityProfile }: Profile) {
- return post('/api/qualityprofiles/set_default', {
- language,
- qualityProfile
- });
- }
-
- export function renameProfile(key: string, name: string) {
- return post('/api/qualityprofiles/rename', { key, name }).catch(throwGlobalError);
- }
-
- export function copyProfile(fromKey: string, toName: string): Promise<any> {
- return postJSON('/api/qualityprofiles/copy', { fromKey, toName }).catch(throwGlobalError);
- }
-
- export function deleteProfile({ language, name: qualityProfile }: Profile) {
- return post('/api/qualityprofiles/delete', { language, qualityProfile }).catch(throwGlobalError);
- }
-
- export function changeProfileParent(
- { language, name: qualityProfile }: Profile,
- parentProfile?: Profile
- ) {
- return post('/api/qualityprofiles/change_parent', {
- language,
- qualityProfile,
- parentQualityProfile: parentProfile ? parentProfile.name : undefined
- }).catch(throwGlobalError);
- }
-
- export function getQualityProfileBackupUrl({ language, name: qualityProfile }: Profile) {
- const queryParams = Object.entries({ language, qualityProfile })
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
- .join('&');
- return `/api/qualityprofiles/backup?${queryParams}`;
- }
-
- export function getQualityProfileExporterUrl(
- { key: exporterKey }: Exporter,
- { language, name: qualityProfile }: Profile
- ) {
- const queryParams = Object.entries({ exporterKey, language, qualityProfile })
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
- .join('&');
- return `/api/qualityprofiles/export?${queryParams}`;
- }
-
- export function getImporters(): Promise<
- Array<{ key: string; languages: Array<string>; name: string }>
- > {
- return getJSON('/api/qualityprofiles/importers').then(r => r.importers, throwGlobalError);
- }
-
- export function getExporters(): Promise<any> {
- return getJSON('/api/qualityprofiles/exporters').then(r => r.exporters);
- }
-
- export function getProfileChangelog(
- since: any,
- to: any,
- { language, name: qualityProfile }: Profile,
- page?: number
- ): Promise<{
- events: ProfileChangelogEvent[];
- p: number;
- ps: number;
- total: number;
- }> {
- return getJSON('/api/qualityprofiles/changelog', {
- since,
- to,
- language,
- qualityProfile,
- p: page
- });
- }
-
- export interface CompareResponse {
- left: { name: string };
- right: { name: string };
- inLeft: Array<{ key: string; name: string; severity: string }>;
- inRight: Array<{ key: string; name: string; severity: string }>;
- modified: Array<{
- key: string;
- name: string;
- left: { params: T.Dict<string>; severity: string };
- right: { params: T.Dict<string>; severity: string };
- }>;
- }
-
- export function compareProfiles(leftKey: string, rightKey: string): Promise<CompareResponse> {
- return getJSON('/api/qualityprofiles/compare', { leftKey, rightKey });
- }
-
- export function associateProject({ language, name: qualityProfile }: Profile, project: string) {
- return post('/api/qualityprofiles/add_project', {
- language,
- qualityProfile,
- project
- }).catch(throwGlobalError);
- }
-
- export function dissociateProject({ language, name: qualityProfile }: Profile, project: string) {
- return post('/api/qualityprofiles/remove_project', {
- language,
- qualityProfile,
- project
- }).catch(throwGlobalError);
- }
-
- export interface SearchUsersGroupsParameters {
- language: string;
- qualityProfile: string;
- q?: string;
- selected?: 'all' | 'selected' | 'deselected';
- }
-
- interface SearchUsersResponse {
- users: T.UserSelected[];
- paging: T.Paging;
- }
-
- export function searchUsers(parameters: SearchUsersGroupsParameters): Promise<SearchUsersResponse> {
- return getJSON('/api/qualityprofiles/search_users', parameters).catch(throwGlobalError);
- }
-
- export interface SearchGroupsResponse {
- groups: Array<{ name: string }>;
- paging: T.Paging;
- }
-
- export function searchGroups(
- parameters: SearchUsersGroupsParameters
- ): Promise<SearchGroupsResponse> {
- return getJSON('/api/qualityprofiles/search_groups', parameters).catch(throwGlobalError);
- }
-
- export interface AddRemoveUserParameters {
- language: string;
- login: string;
- qualityProfile: string;
- }
-
- export function addUser(parameters: AddRemoveUserParameters): Promise<void | Response> {
- return post('/api/qualityprofiles/add_user', parameters).catch(throwGlobalError);
- }
-
- export function removeUser(parameters: AddRemoveUserParameters): Promise<void | Response> {
- return post('/api/qualityprofiles/remove_user', parameters).catch(throwGlobalError);
- }
-
- export interface AddRemoveGroupParameters {
- group: string;
- language: string;
- qualityProfile: string;
- }
-
- export function addGroup(parameters: AddRemoveGroupParameters): Promise<void | Response> {
- return post('/api/qualityprofiles/add_group', parameters).catch(throwGlobalError);
- }
-
- export function removeGroup(parameters: AddRemoveGroupParameters): Promise<void | Response> {
- return post('/api/qualityprofiles/remove_group', parameters).catch(throwGlobalError);
- }
-
- export interface BulkActivateParameters {
- activation?: boolean;
- active_severities?: string;
- asc?: boolean;
- available_since?: string;
- compareToProfile?: string;
- inheritance?: string;
- is_template?: string;
- languages?: string;
- q?: string;
- qprofile?: string;
- repositories?: string;
- rule_key?: string;
- s?: string;
- severities?: string;
- statuses?: string;
- tags?: string;
- targetKey: string;
- targetSeverity?: string;
- template_key?: string;
- types?: string;
- }
-
- export function bulkActivateRules(data: BulkActivateParameters) {
- return postJSON('/api/qualityprofiles/activate_rules', data);
- }
-
- export function bulkDeactivateRules(data: BulkActivateParameters) {
- return postJSON('/api/qualityprofiles/deactivate_rules', data);
- }
-
- export function activateRule(data: {
- key: string;
- params?: T.Dict<string>;
- reset?: boolean;
- rule: string;
- severity?: string;
- }) {
- const params =
- data.params && map(data.params, (value, key) => `${key}=${csvEscape(value)}`).join(';');
- return post('/api/qualityprofiles/activate_rule', { ...data, params }).catch(throwGlobalError);
- }
-
- export function deactivateRule(data: { key: string; rule: string }) {
- return post('/api/qualityprofiles/deactivate_rule', data).catch(throwGlobalError);
- }
|