@@ -17,20 +17,15 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { getJSON } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
/*:: | |||
type GetApplicationLeakResponse = Array<{ | |||
date: string, | |||
project: string, | |||
projectName: string | |||
}>; | |||
*/ | |||
export interface IApplicationLeak { | |||
date: string; | |||
project: string; | |||
projectName: string; | |||
} | |||
export function getApplicationLeak( | |||
application /*: string */ | |||
) /*: Promise<GetApplicationLeakResponse> */ { | |||
export function getApplicationLeak(application: string): Promise<Array<IApplicationLeak>> { | |||
return getJSON('/api/views/show_leak', { application }).then(r => r.leaks, throwGlobalError); | |||
} |
@@ -19,22 +19,22 @@ | |||
*/ | |||
import { request } from '../helpers/request'; | |||
const basicCheckStatus = response => { | |||
if (response.status >= 200 && response.status < 300) { | |||
return response; | |||
} else { | |||
const error = new Error(response.status); | |||
error.response = response; | |||
throw error; | |||
} | |||
}; | |||
export const login = (login, password) => | |||
request('/api/authentication/login') | |||
export function login(login: string, password: string): Promise<Response> { | |||
return request('/api/authentication/login') | |||
.setMethod('POST') | |||
.setData({ login, password }) | |||
.submit() | |||
.then(basicCheckStatus); | |||
} | |||
export const logout = () => | |||
request('/api/authentication/logout').setMethod('POST').submit().then(basicCheckStatus); | |||
export function logout(): Promise<Response> { | |||
return request('/api/authentication/logout').setMethod('POST').submit().then(basicCheckStatus); | |||
} | |||
function basicCheckStatus(response: Response): Promise<Response> { | |||
if (response.status >= 200 && response.status < 300) { | |||
return Promise.resolve(response); | |||
} else { | |||
return Promise.reject(response); | |||
} | |||
} |
@@ -17,15 +17,14 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { getJSON, post } from '../helpers/request'; | |||
import { getJSON, post, RequestData } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
export function getActivity(data /*: ?Object */) /*: Promise<*> */ { | |||
export function getActivity(data: RequestData): Promise<any> { | |||
return getJSON('/api/ce/activity', data); | |||
} | |||
export function getStatus(componentId /*: ?string */) /*: Promise<*> */ { | |||
export function getStatus(componentId?: string): Promise<any> { | |||
const data = {}; | |||
if (componentId) { | |||
Object.assign(data, { componentId }); | |||
@@ -33,33 +32,30 @@ export function getStatus(componentId /*: ?string */) /*: Promise<*> */ { | |||
return getJSON('/api/ce/activity_status', data); | |||
} | |||
export function getTask( | |||
id /*: string */, | |||
additionalFields /*: ?Array<string> */ | |||
) /*: Promise<*> */ { | |||
export function getTask(id: string, additionalFields?: string[]): Promise<any> { | |||
return getJSON('/api/ce/task', { id, additionalFields }).then(r => r.task); | |||
} | |||
export function cancelTask(id /*: string */) /*: Promise<*> */ { | |||
export function cancelTask(id: string): Promise<any> { | |||
return post('/api/ce/cancel', { id }).then(() => getTask(id), () => getTask(id)); | |||
} | |||
export function cancelAllTasks() /*: Promise<*> */ { | |||
export function cancelAllTasks(): Promise<any> { | |||
return post('/api/ce/cancel_all'); | |||
} | |||
export function getTasksForComponent(componentKey /*: string */) /*: Promise<*> */ { | |||
export function getTasksForComponent(componentKey: string): Promise<any> { | |||
return getJSON('/api/ce/component', { componentKey }); | |||
} | |||
export function getTypes() /*: Promise<*> */ { | |||
export function getTypes(): Promise<any> { | |||
return getJSON('/api/ce/task_types').then(r => r.taskTypes); | |||
} | |||
export function getWorkers() /*: Promise<{ canSetWorkerCount: boolean, value: number }> */ { | |||
export function getWorkers(): Promise<{ canSetWorkerCount: boolean; value: number } | Response> { | |||
return getJSON('/api/ce/worker_count').catch(throwGlobalError); | |||
} | |||
export function setWorkerCount(count /*: number */) /*: Promise<void> */ { | |||
export function setWorkerCount(count: number): Promise<void | Response> { | |||
return post('/api/ce/set_worker_count', { count }).catch(throwGlobalError); | |||
} |
@@ -1,252 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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. | |||
*/ | |||
// @flow | |||
import { getJSON, postJSON, post } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
export function getComponents(data /*: ?Object */) { | |||
const url = '/api/projects/search'; | |||
return getJSON(url, data); | |||
} | |||
export function getProvisioned(data /*: ?Object */) { | |||
const url = '/api/projects/provisioned'; | |||
return getJSON(url, data); | |||
} | |||
export function getGhosts(data /*: ?Object */) { | |||
const url = '/api/projects/ghosts'; | |||
return getJSON(url, data); | |||
} | |||
export function deleteComponents(data /*: { projects: string, organization?: string } */) { | |||
const url = '/api/projects/bulk_delete'; | |||
return post(url, data); | |||
} | |||
export function deleteProject(project /*: string */) { | |||
const url = '/api/projects/delete'; | |||
const data = { project }; | |||
return post(url, data); | |||
} | |||
export function createProject( | |||
data /*: { | |||
branch?: string, | |||
name: string, | |||
project: string, | |||
organization?: string | |||
} */ | |||
) { | |||
const url = '/api/projects/create'; | |||
return postJSON(url, data).catch(throwGlobalError); | |||
} | |||
export function searchProjectTags(data /*: ?{ ps?: number, q?: string } */) { | |||
const url = '/api/project_tags/search'; | |||
return getJSON(url, data); | |||
} | |||
export function setProjectTags(data /*: { project: string, tags: string } */) { | |||
const url = '/api/project_tags/set'; | |||
return post(url, data); | |||
} | |||
export function getComponentTree( | |||
strategy /*: string */, | |||
componentKey /*: string */, | |||
metrics /*: Array<string> */ = [], | |||
additional /*: ?Object */ = {} | |||
) { | |||
const url = '/api/measures/component_tree'; | |||
const data = Object.assign({}, additional, { | |||
baseComponentKey: componentKey, | |||
metricKeys: metrics.join(','), | |||
strategy | |||
}); | |||
return getJSON(url, data); | |||
} | |||
export function getChildren( | |||
componentKey /*: string */, | |||
metrics /*: Array<string> | void */, | |||
additional /*: ?Object */ | |||
) { | |||
return getComponentTree('children', componentKey, metrics, additional); | |||
} | |||
export function getComponentLeaves( | |||
componentKey /*: string */, | |||
metrics /*: Array<string> | void */, | |||
additional /*: ?Object */ | |||
) { | |||
return getComponentTree('leaves', componentKey, metrics, additional); | |||
} | |||
export function getComponent(componentKey /*: string */, metrics /*: Array<string> */ = []) { | |||
const url = '/api/measures/component'; | |||
const data = { componentKey, metricKeys: metrics.join(',') }; | |||
return getJSON(url, data).then(r => r.component); | |||
} | |||
export function getTree(component /*: string */, options /*: ?Object */ = {}) { | |||
const url = '/api/components/tree'; | |||
const data = { ...options, component }; | |||
return getJSON(url, data); | |||
} | |||
export function getComponentShow(component /*: string */) { | |||
const url = '/api/components/show'; | |||
return getJSON(url, { component }); | |||
} | |||
export function getParents(component /*: string */) { | |||
return getComponentShow(component).then(r => r.ancestors); | |||
} | |||
export function getBreadcrumbs(component /*: string */) { | |||
return getComponentShow(component).then(r => { | |||
const reversedAncestors = [...r.ancestors].reverse(); | |||
return [...reversedAncestors, r.component]; | |||
}); | |||
} | |||
export function getComponentData(component /*: string */) { | |||
return getComponentShow(component).then(r => r.component); | |||
} | |||
export function getMyProjects(data /*: ?Object */) { | |||
const url = '/api/projects/search_my_projects'; | |||
return getJSON(url, data); | |||
} | |||
export function searchProjects(data /*: ?Object */) { | |||
const url = '/api/components/search_projects'; | |||
return getJSON(url, data); | |||
} | |||
export function searchComponents(data /*: ?{ q?: string, qualifiers?: string, ps?: number } */) { | |||
return getJSON('/api/components/search', data); | |||
} | |||
/** | |||
* Change component's key | |||
* @param {string} from | |||
* @param {string} to | |||
* @returns {Promise} | |||
*/ | |||
export function changeKey(from /*: string */, to /*: string */) { | |||
const url = '/api/projects/update_key'; | |||
const data = { from, to }; | |||
return post(url, data); | |||
} | |||
/** | |||
* Bulk change component's key | |||
* @param {string} project | |||
* @param {string} from | |||
* @param {string} to | |||
* @param {boolean} dryRun | |||
* @returns {Promise} | |||
*/ | |||
export function bulkChangeKey( | |||
project /*: string */, | |||
from /*: string */, | |||
to /*: string */, | |||
dryRun /*: ?boolean */ = false | |||
) { | |||
const url = '/api/projects/bulk_update_key'; | |||
const data = { project, from, to, dryRun }; | |||
return postJSON(url, data); | |||
} | |||
/*:: | |||
export type SuggestionsResponse = { | |||
organizations: Array<{ | |||
key: string, | |||
name: string | |||
}>, | |||
projects: Array<{ | |||
key: string, | |||
name: string | |||
}>, | |||
results: Array<{ | |||
items: Array<{ | |||
isFavorite: boolean, | |||
isRecentlyBrowsed: boolean, | |||
key: string, | |||
match: string, | |||
name: string, | |||
organization: string, | |||
project: string | |||
}>, | |||
more: number, | |||
q: string | |||
}>, | |||
warning?: string | |||
}; | |||
*/ | |||
export function getSuggestions( | |||
query /*: ?string */, | |||
recentlyBrowsed /*: ?Array<string> */, | |||
more /*: ?string */ | |||
) /*: Promise<SuggestionsResponse> */ { | |||
const data /*: Object */ = {}; | |||
if (query) { | |||
data.s = query; | |||
} | |||
if (recentlyBrowsed) { | |||
data.recentlyBrowsed = recentlyBrowsed.join(); | |||
} | |||
if (more) { | |||
data.more = more; | |||
} | |||
return getJSON('/api/components/suggestions', data); | |||
} | |||
export function getComponentForSourceViewer(component /*: string */) /*: Promise<*> */ { | |||
return getJSON('/api/components/app', { component }); | |||
} | |||
export function getSources( | |||
component /*: string */, | |||
from /*: ?number */, | |||
to /*: ?number */ | |||
) /*: Promise<Array<*>> */ { | |||
const data /*: Object */ = { key: component }; | |||
if (from) { | |||
Object.assign(data, { from }); | |||
} | |||
if (to) { | |||
Object.assign(data, { to }); | |||
} | |||
return getJSON('/api/sources/lines', data).then(r => r.sources); | |||
} | |||
export function getDuplications(component /*: string */) /*: Promise<*> */ { | |||
return getJSON('/api/duplications/show', { key: component }); | |||
} | |||
export function getTests(component /*: string */, line /*: number | string */) /*: Promise<*> */ { | |||
return getJSON('/api/tests/list', { sourceFileKey: component, sourceFileLineNumber: line }).then( | |||
r => r.tests | |||
); | |||
} |
@@ -0,0 +1,219 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { getJSON, postJSON, post, RequestData } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
export function getComponents(data: RequestData): Promise<any> { | |||
return getJSON('/api/projects/search', data); | |||
} | |||
export function getProvisioned(data: RequestData): Promise<any> { | |||
return getJSON('/api/projects/provisioned', data); | |||
} | |||
export function getGhosts(data: RequestData): Promise<any> { | |||
return getJSON('/api/projects/ghosts', data); | |||
} | |||
export function deleteComponents(data: { projects: string; organization?: string }): Promise<void> { | |||
return post('/api/projects/bulk_delete', data); | |||
} | |||
export function deleteProject(project: string): Promise<void> { | |||
return post('/api/projects/delete', { project }); | |||
} | |||
export function createProject(data: { | |||
branch?: string; | |||
name: string; | |||
project: string; | |||
organization?: string; | |||
}): Promise<any> { | |||
return postJSON('/api/projects/create', data).catch(throwGlobalError); | |||
} | |||
export function searchProjectTags(data?: { ps?: number; q?: string }): Promise<any> { | |||
return getJSON('/api/project_tags/search', data); | |||
} | |||
export function setProjectTags(data: { project: string; tags: string }): Promise<void> { | |||
return post('/api/project_tags/set', data); | |||
} | |||
export function getComponentTree( | |||
strategy: string, | |||
componentKey: string, | |||
metrics: string[] = [], | |||
additional: RequestData = {} | |||
): Promise<any> { | |||
const url = '/api/measures/component_tree'; | |||
const data = Object.assign({}, additional, { | |||
baseComponentKey: componentKey, | |||
metricKeys: metrics.join(','), | |||
strategy | |||
}); | |||
return getJSON(url, data); | |||
} | |||
export function getChildren( | |||
componentKey: string, | |||
metrics: string[] = [], | |||
additional: RequestData = {} | |||
): Promise<any> { | |||
return getComponentTree('children', componentKey, metrics, additional); | |||
} | |||
export function getComponentLeaves( | |||
componentKey: string, | |||
metrics: string[] = [], | |||
additional: RequestData = {} | |||
): Promise<any> { | |||
return getComponentTree('leaves', componentKey, metrics, additional); | |||
} | |||
export function getComponent(componentKey: string, metrics: string[] = []): Promise<any> { | |||
const data = { componentKey, metricKeys: metrics.join(',') }; | |||
return getJSON('/api/measures/component', data).then(r => r.component); | |||
} | |||
export function getTree(component: string, options: RequestData = {}): Promise<any> { | |||
return getJSON('/api/components/tree', { ...options, component }); | |||
} | |||
export function getComponentShow(component: string): Promise<any> { | |||
return getJSON('/api/components/show', { component }); | |||
} | |||
export function getParents(component: string): Promise<any> { | |||
return getComponentShow(component).then(r => r.ancestors); | |||
} | |||
export function getBreadcrumbs(component: string): Promise<any> { | |||
return getComponentShow(component).then(r => { | |||
const reversedAncestors = [...r.ancestors].reverse(); | |||
return [...reversedAncestors, r.component]; | |||
}); | |||
} | |||
export function getComponentData(component: string): Promise<any> { | |||
return getComponentShow(component).then(r => r.component); | |||
} | |||
export function getMyProjects(data: RequestData): Promise<any> { | |||
const url = '/api/projects/search_my_projects'; | |||
return getJSON(url, data); | |||
} | |||
export function searchProjects(data: RequestData): Promise<any> { | |||
const url = '/api/components/search_projects'; | |||
return getJSON(url, data); | |||
} | |||
export function searchComponents(data?: { | |||
q?: string; | |||
qualifiers?: string; | |||
ps?: number; | |||
}): Promise<any> { | |||
return getJSON('/api/components/search', data); | |||
} | |||
/** | |||
* Change component's key | |||
*/ | |||
export function changeKey(from: string, to: string): Promise<void> { | |||
const url = '/api/projects/update_key'; | |||
const data = { from, to }; | |||
return post(url, data); | |||
} | |||
/** | |||
* Bulk change component's key | |||
*/ | |||
export function bulkChangeKey( | |||
project: string, | |||
from: string, | |||
to: string, | |||
dryRun: boolean = false | |||
): Promise<any> { | |||
const url = '/api/projects/bulk_update_key'; | |||
const data = { project, from, to, dryRun }; | |||
return postJSON(url, data); | |||
} | |||
export interface ISuggestionsResponse { | |||
organizations: Array<{ key: string; name: string }>; | |||
projects: Array<{ key: string; name: string }>; | |||
results: Array<{ | |||
items: Array<{ | |||
isFavorite: boolean; | |||
isRecentlyBrowsed: boolean; | |||
key: string; | |||
match: string; | |||
name: string; | |||
organization: string; | |||
project: string; | |||
}>; | |||
more: number; | |||
q: string; | |||
}>; | |||
warning?: string; | |||
} | |||
export function getSuggestions( | |||
query?: string, | |||
recentlyBrowsed?: string[], | |||
more?: string | |||
): Promise<ISuggestionsResponse> { | |||
const data: RequestData = {}; | |||
if (query) { | |||
data.s = query; | |||
} | |||
if (recentlyBrowsed) { | |||
data.recentlyBrowsed = recentlyBrowsed.join(); | |||
} | |||
if (more) { | |||
data.more = more; | |||
} | |||
return getJSON('/api/components/suggestions', data); | |||
} | |||
export function getComponentForSourceViewer(component: string): Promise<any> { | |||
return getJSON('/api/components/app', { component }); | |||
} | |||
export function getSources(component: string, from?: number, to?: number): Promise<any> { | |||
const data: RequestData = { key: component }; | |||
if (from) { | |||
Object.assign(data, { from }); | |||
} | |||
if (to) { | |||
Object.assign(data, { to }); | |||
} | |||
return getJSON('/api/sources/lines', data).then(r => r.sources); | |||
} | |||
export function getDuplications(component: string): Promise<any> { | |||
return getJSON('/api/duplications/show', { key: component }); | |||
} | |||
export function getTests(component: string, line: number | string): Promise<any> { | |||
const data = { sourceFileKey: component, sourceFileLineNumber: line }; | |||
return getJSON('/api/tests/list', data).then(r => r.tests); | |||
} |
@@ -17,17 +17,16 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
/* @flow */ | |||
import { post, getJSON } from '../helpers/request'; | |||
export function getFavorites() /*: Promise<Object> */ { | |||
export function getFavorites(): Promise<any> { | |||
return getJSON('/api/favorites/search'); | |||
} | |||
export function addFavorite(component /*: string */) { | |||
export function addFavorite(component: string): Promise<void> { | |||
return post('/api/favorites/add', { component }); | |||
} | |||
export function removeFavorite(component /*: string */) { | |||
export function removeFavorite(component: string): Promise<void> { | |||
return post('/api/favorites/remove', { component }); | |||
} |
@@ -19,8 +19,6 @@ | |||
*/ | |||
import { post } from '../helpers/request'; | |||
export function toggleIssueFilter(id) { | |||
const url = '/issues/toggle_fav'; | |||
const data = { id }; | |||
return post(url, data); | |||
export function toggleIssueFilter(id: string): Promise<void> { | |||
return post('/issues/toggle_fav', { id }); | |||
} |
@@ -1,180 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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. | |||
*/ | |||
// @flow | |||
import { getJSON, post, postJSON } from '../helpers/request'; | |||
/*:: | |||
export type IssueResponse = { | |||
components?: Array<*>, | |||
issue: {}, | |||
rules?: Array<*>, | |||
users?: Array<*> | |||
}; | |||
*/ | |||
/*:: | |||
type IssuesResponse = { | |||
components?: Array<*>, | |||
debtTotal?: number, | |||
facets: Array<*>, | |||
issues: Array<*>, | |||
paging: { | |||
pageIndex: number, | |||
pageSize: number, | |||
total: number | |||
}, | |||
rules?: Array<*>, | |||
users?: Array<*> | |||
}; | |||
*/ | |||
export function searchIssues(query /*: {} */) /*: Promise<IssuesResponse> */ { | |||
return getJSON('/api/issues/search', query); | |||
} | |||
export function getFacets(query /*: {} */, facets /*: Array<string> */) /*: Promise<*> */ { | |||
const data = { | |||
...query, | |||
facets: facets.join(), | |||
ps: 1, | |||
additionalFields: '_all' | |||
}; | |||
return searchIssues(data).then(r => { | |||
return { facets: r.facets, response: r }; | |||
}); | |||
} | |||
export function getFacet(query /*: {} */, facet /*: string */) /*: Promise<*> */ { | |||
return getFacets(query, [facet]).then(r => { | |||
return { facet: r.facets[0].values, response: r.response }; | |||
}); | |||
} | |||
export function getSeverities(query /*: {} */) /*: Promise<*> */ { | |||
return getFacet(query, 'severities').then(r => r.facet); | |||
} | |||
export function getTags(query /*: {} */) /*: Promise<*> */ { | |||
return getFacet(query, 'tags').then(r => r.facet); | |||
} | |||
export function extractAssignees( | |||
facet /*: Array<{ val: string }> */, | |||
response /*: IssuesResponse */ | |||
) { | |||
return facet.map(item => { | |||
const user = response.users ? response.users.find(user => user.login === item.val) : null; | |||
return { ...item, user }; | |||
}); | |||
} | |||
export function getAssignees(query /*: {} */) /*: Promise<*> */ { | |||
return getFacet(query, 'assignees').then(r => extractAssignees(r.facet, r.response)); | |||
} | |||
export function getIssuesCount(query /*: {} */) /*: Promise<*> */ { | |||
const data = { ...query, ps: 1, facetMode: 'effort' }; | |||
return searchIssues(data).then(r => { | |||
return { issues: r.paging.total, debt: r.debtTotal }; | |||
}); | |||
} | |||
export function searchIssueTags( | |||
data /*: { organization?: string, ps?: number, q?: string } */ = { ps: 500 } | |||
) /*: Promise<Array<string>> */ { | |||
return getJSON('/api/issues/tags', data).then(r => r.tags); | |||
} | |||
export function getIssueChangelog(issue /*: string */) /*: Promise<*> */ { | |||
const url = '/api/issues/changelog'; | |||
return getJSON(url, { issue }).then(r => r.changelog); | |||
} | |||
export function getIssueFilters() { | |||
const url = '/api/issue_filters/search'; | |||
return getJSON(url).then(r => r.issueFilters); | |||
} | |||
export function addIssueComment( | |||
data /*: { issue: string, text: string } */ | |||
) /*: Promise<IssueResponse> */ { | |||
const url = '/api/issues/add_comment'; | |||
return postJSON(url, data); | |||
} | |||
export function deleteIssueComment(data /*: { comment: string } */) /*: Promise<IssueResponse> */ { | |||
const url = '/api/issues/delete_comment'; | |||
return postJSON(url, data); | |||
} | |||
export function editIssueComment( | |||
data /*: { comment: string, text: string } */ | |||
) /*: Promise<IssueResponse> */ { | |||
const url = '/api/issues/edit_comment'; | |||
return postJSON(url, data); | |||
} | |||
export function setIssueAssignee( | |||
data /*: { | |||
issue: string, | |||
assignee?: string | |||
} */ | |||
) /*: Promise<IssueResponse> */ { | |||
const url = '/api/issues/assign'; | |||
return postJSON(url, data); | |||
} | |||
export function setIssueSeverity( | |||
data /*: { issue: string, severity: string } */ | |||
) /*: Promise<*> */ { | |||
const url = '/api/issues/set_severity'; | |||
return postJSON(url, data); | |||
} | |||
export function setIssueTags( | |||
data /*: { issue: string, tags: string } */ | |||
) /*: Promise<IssueResponse> */ { | |||
const url = '/api/issues/set_tags'; | |||
return postJSON(url, data); | |||
} | |||
export function setIssueTransition( | |||
data /*: { | |||
issue: string, | |||
transition: string | |||
} */ | |||
) /*: Promise<IssueResponse> */ { | |||
const url = '/api/issues/do_transition'; | |||
return postJSON(url, data); | |||
} | |||
export function setIssueType( | |||
data /*: { issue: string, type: string } */ | |||
) /*: Promise<IssueResponse> */ { | |||
const url = '/api/issues/set_type'; | |||
return postJSON(url, data); | |||
} | |||
export function bulkChangeIssues(issueKeys /*: Array<string> */, query /*: {} */) { | |||
return post('/api/issues/bulk_change', { | |||
issues: issueKeys.join(), | |||
...query | |||
}); | |||
} |
@@ -0,0 +1,145 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { getJSON, post, postJSON, RequestData } from '../helpers/request'; | |||
export interface IssueResponse { | |||
components?: Array<{}>; | |||
issue: {}; | |||
rules?: Array<{}>; | |||
users?: Array<{}>; | |||
} | |||
interface IssuesResponse { | |||
components?: Array<{}>; | |||
debtTotal?: number; | |||
facets: Array<{}>; | |||
issues: Array<{}>; | |||
paging: { | |||
pageIndex: number; | |||
pageSize: number; | |||
total: number; | |||
}; | |||
rules?: Array<{}>; | |||
users?: Array<{ login: string }>; | |||
} | |||
export function searchIssues(query: RequestData): Promise<IssuesResponse> { | |||
return getJSON('/api/issues/search', query); | |||
} | |||
export function getFacets(query: RequestData, facets: string[]): Promise<any> { | |||
const data = { | |||
...query, | |||
facets: facets.join(), | |||
ps: 1, | |||
additionalFields: '_all' | |||
}; | |||
return searchIssues(data).then(r => { | |||
return { facets: r.facets, response: r }; | |||
}); | |||
} | |||
export function getFacet(query: RequestData, facet: string): Promise<any> { | |||
return getFacets(query, [facet]).then(r => { | |||
return { facet: r.facets[0].values, response: r.response }; | |||
}); | |||
} | |||
export function getSeverities(query: RequestData): Promise<any> { | |||
return getFacet(query, 'severities').then(r => r.facet); | |||
} | |||
export function getTags(query: RequestData): Promise<any> { | |||
return getFacet(query, 'tags').then(r => r.facet); | |||
} | |||
export function extractAssignees(facet: Array<{ val: string }>, response: IssuesResponse): any { | |||
return facet.map(item => { | |||
const user = response.users ? response.users.find(user => user.login === item.val) : null; | |||
return { ...item, user }; | |||
}); | |||
} | |||
export function getAssignees(query: RequestData): Promise<any> { | |||
return getFacet(query, 'assignees').then(r => extractAssignees(r.facet, r.response)); | |||
} | |||
export function getIssuesCount(query: RequestData): Promise<any> { | |||
const data = { ...query, ps: 1, facetMode: 'effort' }; | |||
return searchIssues(data).then(r => { | |||
return { issues: r.paging.total, debt: r.debtTotal }; | |||
}); | |||
} | |||
export function searchIssueTags( | |||
data: { organization?: string; ps?: number; q?: string } = { ps: 500 } | |||
): Promise<string[]> { | |||
return getJSON('/api/issues/tags', data).then(r => r.tags); | |||
} | |||
export function getIssueChangelog(issue: string): Promise<any> { | |||
return getJSON('/api/issues/changelog', { issue }).then(r => r.changelog); | |||
} | |||
export function getIssueFilters() { | |||
return getJSON('/api/issue_filters/search').then(r => r.issueFilters); | |||
} | |||
export function addIssueComment(data: { issue: string; text: string }): Promise<IssueResponse> { | |||
return postJSON('/api/issues/add_comment', data); | |||
} | |||
export function deleteIssueComment(data: { comment: string }): Promise<IssueResponse> { | |||
return postJSON('/api/issues/delete_comment', data); | |||
} | |||
export function editIssueComment(data: { comment: string; text: string }): Promise<IssueResponse> { | |||
return postJSON('/api/issues/edit_comment', data); | |||
} | |||
export function setIssueAssignee(data: { | |||
issue: string; | |||
assignee?: string; | |||
}): Promise<IssueResponse> { | |||
return postJSON('/api/issues/assign', data); | |||
} | |||
export function setIssueSeverity(data: { issue: string; severity: string }): Promise<any> { | |||
return postJSON('/api/issues/set_severity', data); | |||
} | |||
export function setIssueTags(data: { issue: string; tags: string }): Promise<IssueResponse> { | |||
return postJSON('/api/issues/set_tags', data); | |||
} | |||
export function setIssueTransition(data: { | |||
issue: string; | |||
transition: string; | |||
}): Promise<IssueResponse> { | |||
return postJSON('/api/issues/do_transition', data); | |||
} | |||
export function setIssueType(data: { issue: string; type: string }): Promise<IssueResponse> { | |||
return postJSON('/api/issues/set_type', data); | |||
} | |||
export function bulkChangeIssues(issueKeys: string[], query: RequestData): Promise<void> { | |||
return post('/api/issues/bulk_change', { issues: issueKeys.join(), ...query }); | |||
} |
@@ -19,7 +19,6 @@ | |||
*/ | |||
import { getJSON } from '../helpers/request'; | |||
export function getLanguages() { | |||
const url = '/api/languages/list'; | |||
return getJSON(url).then(r => r.languages); | |||
export function getLanguages(): Promise<any> { | |||
return getJSON('/api/languages/list').then(r => r.languages); | |||
} |
@@ -19,16 +19,18 @@ | |||
*/ | |||
import { getJSON, post } from '../helpers/request'; | |||
export const getLicenses = () => getJSON('/api/licenses/list').then(r => r.licenses); | |||
export function getLicenses(): Promise<any> { | |||
return getJSON('/api/licenses/list').then(r => r.licenses); | |||
} | |||
export const setLicense = (key, value) => { | |||
export function setLicense(key: string, value: string): Promise<void> { | |||
const url = '/api/settings/set'; | |||
const data = { key, value }; | |||
return post(url, data); | |||
}; | |||
} | |||
export const resetLicense = key => { | |||
export function resetLicense(key: string): Promise<void> { | |||
const url = '/api/settings/reset'; | |||
const data = { keys: key }; | |||
return post(url, data); | |||
}; | |||
} |
@@ -17,25 +17,26 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import { getJSON } from '../helpers/request'; | |||
import { getJSON, RequestData } from '../helpers/request'; | |||
export function getMeasures(componentKey, metrics) { | |||
export function getMeasures(componentKey: string, metrics: string[]): Promise<any> { | |||
const url = '/api/measures/component'; | |||
const data = { componentKey, metricKeys: metrics.join(',') }; | |||
return getJSON(url, data).then(r => r.component.measures); | |||
} | |||
export function getMeasuresAndMeta(componentKey, metrics, additional = {}) { | |||
const url = '/api/measures/component'; | |||
const data = Object.assign({}, additional, { | |||
componentKey, | |||
metricKeys: metrics.join(',') | |||
}); | |||
return getJSON(url, data); | |||
export function getMeasuresAndMeta( | |||
componentKey: string, | |||
metrics: string[], | |||
additional: RequestData = {} | |||
): Promise<any> { | |||
const data = { ...additional, componentKey, metricKeys: metrics.join(',') }; | |||
return getJSON('/api/measures/component', data); | |||
} | |||
export const getMeasuresForProjects = (projectKeys, metricKeys) => | |||
getJSON('/api/measures/search', { | |||
export function getMeasuresForProjects(projectKeys: string[], metricKeys: string[]): Promise<any> { | |||
return getJSON('/api/measures/search', { | |||
projectKeys: projectKeys.join(), | |||
metricKeys: metricKeys.join() | |||
}); | |||
} |
@@ -19,8 +19,6 @@ | |||
*/ | |||
import { getJSON } from '../helpers/request'; | |||
export function getMetrics() { | |||
const url = '/api/metrics/search'; | |||
const data = { ps: 9999 }; | |||
return getJSON(url, data).then(r => r.metrics); | |||
export function getMetrics(): Promise<any> { | |||
return getJSON('/api/metrics/search', { ps: 9999 }).then(r => r.metrics); | |||
} |
@@ -19,18 +19,14 @@ | |||
*/ | |||
import { getJSON } from '../helpers/request'; | |||
export function getGlobalNavigation() { | |||
const url = '/api/navigation/global'; | |||
return getJSON(url); | |||
export function getGlobalNavigation(): Promise<any> { | |||
return getJSON('/api/navigation/global'); | |||
} | |||
export function getComponentNavigation(componentKey) { | |||
const url = '/api/navigation/component'; | |||
const data = { componentKey }; | |||
return getJSON(url, data); | |||
export function getComponentNavigation(componentKey: string): Promise<any> { | |||
return getJSON('/api/navigation/component', { componentKey }); | |||
} | |||
export function getSettingsNavigation() { | |||
const url = '/api/navigation/settings'; | |||
return getJSON(url); | |||
export function getSettingsNavigation(): Promise<any> { | |||
return getJSON('/api/navigation/settings'); | |||
} |
@@ -17,46 +17,35 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { getJSON, post } from '../helpers/request'; | |||
import { getJSON, post, RequestData } from '../helpers/request'; | |||
/*:: | |||
export type GetNotificationsResponse = { | |||
export interface IGetNotificationsResponse { | |||
notifications: Array<{ | |||
channel: string, | |||
type: string, | |||
organization?: string, | |||
project?: string, | |||
projectName?: string | |||
}>, | |||
channels: Array<string>, | |||
globalTypes: Array<string>, | |||
perProjectTypes: Array<string> | |||
}; | |||
*/ | |||
channel: string; | |||
type: string; | |||
organization?: string; | |||
project?: string; | |||
projectName?: string; | |||
}>; | |||
channels: Array<string>; | |||
globalTypes: Array<string>; | |||
perProjectTypes: Array<string>; | |||
} | |||
export function getNotifications() /*: Promise<GetNotificationsResponse> */ { | |||
export function getNotifications(): Promise<IGetNotificationsResponse> { | |||
return getJSON('/api/notifications/list'); | |||
} | |||
export function addNotification( | |||
channel /*: string */, | |||
type /*: string */, | |||
project /*: ?string */ | |||
) /*: Promise<*> */ { | |||
const data /*: Object */ = { channel, type }; | |||
export function addNotification(channel: string, type: string, project?: string): Promise<void> { | |||
const data: RequestData = { channel, type }; | |||
if (project) { | |||
Object.assign(data, { project }); | |||
} | |||
return post('/api/notifications/add', data); | |||
} | |||
export function removeNotification( | |||
channel /*: string */, | |||
type /*: string */, | |||
project /*: ?string */ | |||
) /*: Promise<*> */ { | |||
const data /*: Object */ = { channel, type }; | |||
export function removeNotification(channel: string, type: string, project?: string): Promise<void> { | |||
const data: RequestData = { channel, type }; | |||
if (project) { | |||
Object.assign(data, { project }); | |||
} |
@@ -17,85 +17,73 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { getJSON, post, postJSON } from '../helpers/request'; | |||
/*:: import type { Organization } from '../store/organizations/duck'; */ | |||
import { getJSON, post, postJSON, RequestData } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
export function getOrganizations(organizations /*: ?Array<string> */) { | |||
const data = {}; | |||
export function getOrganizations(organizations?: string[]): Promise<any> { | |||
const data: RequestData = {}; | |||
if (organizations) { | |||
Object.assign(data, { organizations: organizations.join() }); | |||
} | |||
return getJSON('/api/organizations/search', data); | |||
} | |||
export function getMyOrganizations() { | |||
export function getMyOrganizations(): Promise<any> { | |||
return getJSON('/api/organizations/search_my_organizations').then(r => r.organizations); | |||
} | |||
/*:: | |||
type GetOrganizationType = null | Organization; | |||
*/ | |||
/*:: | |||
type GetOrganizationNavigation = { | |||
canAdmin: boolean, | |||
canDelete: boolean, | |||
canProvisionProjects: boolean, | |||
isDefault: boolean, | |||
pages: Array<{ key: string, name: string }>, | |||
adminPages: Array<{ key: string, name: string }> | |||
}; | |||
*/ | |||
export function getOrganization(key /*: string */) /*: Promise<GetOrganizationType> */ { | |||
export function getOrganization(key: string): Promise<any> { | |||
return getOrganizations([key]) | |||
.then(r => r.organizations.find(o => o.key === key)) | |||
.then(r => r.organizations.find((o: any) => o.key === key)) | |||
.catch(throwGlobalError); | |||
} | |||
export function getOrganizationNavigation( | |||
key /*: string */ | |||
) /*: Promise<GetOrganizationNavigation> */ { | |||
interface GetOrganizationNavigation { | |||
canAdmin: boolean; | |||
canDelete: boolean; | |||
canProvisionProjects: boolean; | |||
isDefault: boolean; | |||
pages: Array<{ key: string; name: string }>; | |||
adminPages: Array<{ key: string; name: string }>; | |||
} | |||
export function getOrganizationNavigation(key: string): Promise<GetOrganizationNavigation> { | |||
return getJSON('/api/navigation/organization', { organization: key }).then(r => r.organization); | |||
} | |||
export function createOrganization(fields /*: {} */) /*: Promise<Organization> */ { | |||
return postJSON('/api/organizations/create', fields).then(r => r.organization, throwGlobalError); | |||
export function createOrganization(data: RequestData): Promise<any> { | |||
return postJSON('/api/organizations/create', data).then(r => r.organization, throwGlobalError); | |||
} | |||
export function updateOrganization(key /*: string */, changes /*: {} */) { | |||
export function updateOrganization(key: string, changes: RequestData): Promise<void> { | |||
return post('/api/organizations/update', { key, ...changes }); | |||
} | |||
export function deleteOrganization(key /*: string */) { | |||
export function deleteOrganization(key: string): Promise<void | Response> { | |||
return post('/api/organizations/delete', { key }).catch(throwGlobalError); | |||
} | |||
export function searchMembers( | |||
data /*: { | |||
organization?: string, | |||
p?: number, | |||
ps?: number, | |||
q?: string, | |||
selected?: string | |||
} */ | |||
) { | |||
export function searchMembers(data: { | |||
organization?: string; | |||
p?: number; | |||
ps?: number; | |||
q?: string; | |||
selected?: string; | |||
}): Promise<any> { | |||
return getJSON('/api/organizations/search_members', data); | |||
} | |||
export function addMember(data /*: { login: string, organization: string } */) { | |||
export function addMember(data: { login: string; organization: string }): Promise<any> { | |||
return postJSON('/api/organizations/add_member', data).then(r => r.user); | |||
} | |||
export function removeMember(data /*: { login: string, organization: string } */) { | |||
export function removeMember(data: { login: string; organization: string }): Promise<void> { | |||
return post('/api/organizations/remove_member', data); | |||
} | |||
export function changeProjectVisibility( | |||
organization /*: string */, | |||
projectVisibility /*: string */ | |||
) { | |||
organization: string, | |||
projectVisibility: string | |||
): Promise<void> { | |||
return post('/api/organizations/update_project_visibility', { organization, projectVisibility }); | |||
} |
@@ -1,310 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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. | |||
*/ | |||
// @flow | |||
import { getJSON, post, postJSON } from '../helpers/request'; | |||
const PAGE_SIZE = 100; | |||
export function grantPermissionToUser( | |||
projectKey /*: string | null */, | |||
login /*: string */, | |||
permission /*: string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/add_user'; | |||
const data /*: Object */ = { login, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization && !projectKey) { | |||
data.organization = organization; | |||
} | |||
return post(url, data); | |||
} | |||
export function revokePermissionFromUser( | |||
projectKey /*: string | null */, | |||
login /*: string */, | |||
permission /*: string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/remove_user'; | |||
const data /*: Object */ = { login, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization && !projectKey) { | |||
data.organization = organization; | |||
} | |||
return post(url, data); | |||
} | |||
export function grantPermissionToGroup( | |||
projectKey /*: string | null */, | |||
groupName /*: string */, | |||
permission /*: string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/add_group'; | |||
const data /*: Object */ = { groupName, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return post(url, data); | |||
} | |||
export function revokePermissionFromGroup( | |||
projectKey /*: string | null */, | |||
groupName /*: string */, | |||
permission /*: string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/remove_group'; | |||
const data /*: Object */ = { groupName, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return post(url, data); | |||
} | |||
/** | |||
* Get list of permission templates | |||
* @returns {Promise} | |||
*/ | |||
export function getPermissionTemplates(organization /*: ?string */) { | |||
const url = '/api/permissions/search_templates'; | |||
return organization ? getJSON(url, { organization }) : getJSON(url); | |||
} | |||
export function createPermissionTemplate(data /*: Object */) { | |||
return postJSON('/api/permissions/create_template', data); | |||
} | |||
export function updatePermissionTemplate(data /*: Object */) { | |||
return post('/api/permissions/update_template', data); | |||
} | |||
export function deletePermissionTemplate(data /*: Object */) { | |||
return post('/api/permissions/delete_template', data); | |||
} | |||
/** | |||
* Set default permission template for a given qualifier | |||
* @param {string} templateId | |||
* @param {string} qualifier | |||
* @returns {Promise} | |||
*/ | |||
export function setDefaultPermissionTemplate(templateId /*: string */, qualifier /*: string */) { | |||
const url = '/api/permissions/set_default_template'; | |||
const data = { templateId, qualifier }; | |||
return post(url, data); | |||
} | |||
export function applyTemplateToProject(data /*: Object */) { | |||
const url = '/api/permissions/apply_template'; | |||
return post(url, data); | |||
} | |||
export function bulkApplyTemplate(data /*: Object */) { | |||
const url = '/api/permissions/bulk_apply_template'; | |||
return post(url, data); | |||
} | |||
export function grantTemplatePermissionToUser( | |||
data /*: { | |||
templateId: string, | |||
login: string, | |||
permission: string, | |||
organization?: string | |||
} */ | |||
) { | |||
const url = '/api/permissions/add_user_to_template'; | |||
return post(url, data); | |||
} | |||
export function revokeTemplatePermissionFromUser( | |||
data /*: { | |||
templateId: string, | |||
login: string, | |||
permission: string, | |||
organization?: string | |||
} */ | |||
) { | |||
const url = '/api/permissions/remove_user_from_template'; | |||
return post(url, data); | |||
} | |||
export function grantTemplatePermissionToGroup(data /*: Object */) { | |||
const url = '/api/permissions/add_group_to_template'; | |||
return post(url, data); | |||
} | |||
export function revokeTemplatePermissionFromGroup(data /*: Object */) { | |||
const url = '/api/permissions/remove_group_from_template'; | |||
return post(url, data); | |||
} | |||
export function addProjectCreatorToTemplate(templateId /*: string */, permission /*: string */) { | |||
const url = '/api/permissions/add_project_creator_to_template'; | |||
const data = { templateId, permission }; | |||
return post(url, data); | |||
} | |||
export function removeProjectCreatorFromTemplate( | |||
templateId /*: string */, | |||
permission /*: string */ | |||
) { | |||
const url = '/api/permissions/remove_project_creator_from_template'; | |||
const data = { templateId, permission }; | |||
return post(url, data); | |||
} | |||
export function getPermissionsUsersForComponent( | |||
projectKey /*: string */, | |||
query /*: ?string */, | |||
permission /*: ?string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/users'; | |||
const data /*: Object */ = { projectKey, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON(url, data).then(r => r.users); | |||
} | |||
export function getPermissionsGroupsForComponent( | |||
projectKey /*: string */, | |||
query /*: string */ = '', | |||
permission /*: ?string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/groups'; | |||
const data /*: Object */ = { projectKey, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON(url, data).then(r => r.groups); | |||
} | |||
export function getGlobalPermissionsUsers( | |||
query /*: ?string */, | |||
permission /*: ?string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/users'; | |||
const data /*: Object */ = { ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON(url, data).then(r => r.users); | |||
} | |||
export function getGlobalPermissionsGroups( | |||
query /*: ?string */, | |||
permission /*: ?string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/groups'; | |||
const data /*: Object */ = { ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON(url, data).then(r => r.groups); | |||
} | |||
export function getPermissionTemplateUsers( | |||
templateId /*: string */, | |||
query /*: ?string */, | |||
permission /*: ?string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/template_users'; | |||
const data /*: Object */ = { templateId, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
Object.assign(data, { organization }); | |||
} | |||
return getJSON(url, data).then(r => r.users); | |||
} | |||
export function getPermissionTemplateGroups( | |||
templateId /*: string */, | |||
query /*: ?string */, | |||
permission /*: ?string */, | |||
organization /*: ?string */ | |||
) { | |||
const url = '/api/permissions/template_groups'; | |||
const data /*: Object */ = { templateId, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
Object.assign(data, { organization }); | |||
} | |||
return getJSON(url, data).then(r => r.groups); | |||
} | |||
export function changeProjectVisibility( | |||
project /*: string */, | |||
visibility /*: string */ | |||
) /*: Promise<void> */ { | |||
const url = '/api/projects/update_visibility'; | |||
const data = { project, visibility }; | |||
return post(url, data); | |||
} |
@@ -0,0 +1,274 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { getJSON, post, postJSON, RequestData } from '../helpers/request'; | |||
const PAGE_SIZE = 100; | |||
export function grantPermissionToUser( | |||
projectKey: string | null, | |||
login: string, | |||
permission: string, | |||
organization?: string | |||
): Promise<void> { | |||
const data: RequestData = { login, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization && !projectKey) { | |||
data.organization = organization; | |||
} | |||
return post('/api/permissions/add_user', data); | |||
} | |||
export function revokePermissionFromUser( | |||
projectKey: string | null, | |||
login: string, | |||
permission: string, | |||
organization?: string | |||
): Promise<void> { | |||
const data: RequestData = { login, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization && !projectKey) { | |||
data.organization = organization; | |||
} | |||
return post('/api/permissions/remove_user', data); | |||
} | |||
export function grantPermissionToGroup( | |||
projectKey: string | null, | |||
groupName: string, | |||
permission: string, | |||
organization?: string | |||
): Promise<void> { | |||
const data: RequestData = { groupName, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return post('/api/permissions/add_group', data); | |||
} | |||
export function revokePermissionFromGroup( | |||
projectKey: string | null, | |||
groupName: string, | |||
permission: string, | |||
organization?: string | |||
): Promise<void> { | |||
const data: RequestData = { groupName, permission }; | |||
if (projectKey) { | |||
data.projectKey = projectKey; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return post('/api/permissions/remove_group', data); | |||
} | |||
/** | |||
* Get list of permission templates | |||
*/ | |||
export function getPermissionTemplates(organization?: string) { | |||
const url = '/api/permissions/search_templates'; | |||
return organization ? getJSON(url, { organization }) : getJSON(url); | |||
} | |||
export function createPermissionTemplate(data: RequestData) { | |||
return postJSON('/api/permissions/create_template', data); | |||
} | |||
export function updatePermissionTemplate(data: RequestData): Promise<void> { | |||
return post('/api/permissions/update_template', data); | |||
} | |||
export function deletePermissionTemplate(data: RequestData): Promise<void> { | |||
return post('/api/permissions/delete_template', data); | |||
} | |||
/** | |||
* Set default permission template for a given qualifier | |||
*/ | |||
export function setDefaultPermissionTemplate(templateId: string, qualifier: string): Promise<void> { | |||
return post('/api/permissions/set_default_template', { templateId, qualifier }); | |||
} | |||
export function applyTemplateToProject(data: RequestData): Promise<void> { | |||
return post('/api/permissions/apply_template', data); | |||
} | |||
export function bulkApplyTemplate(data: RequestData): Promise<void> { | |||
return post('/api/permissions/bulk_apply_template', data); | |||
} | |||
export function grantTemplatePermissionToUser(data: { | |||
templateId: string; | |||
login: string; | |||
permission: string; | |||
organization?: string; | |||
}): Promise<void> { | |||
return post('/api/permissions/add_user_to_template', data); | |||
} | |||
export function revokeTemplatePermissionFromUser(data: { | |||
templateId: string; | |||
login: string; | |||
permission: string; | |||
organization?: string; | |||
}): Promise<void> { | |||
return post('/api/permissions/remove_user_from_template', data); | |||
} | |||
export function grantTemplatePermissionToGroup(data: RequestData): Promise<void> { | |||
return post('/api/permissions/add_group_to_template', data); | |||
} | |||
export function revokeTemplatePermissionFromGroup(data: RequestData): Promise<void> { | |||
return post('/api/permissions/remove_group_from_template', data); | |||
} | |||
export function addProjectCreatorToTemplate(templateId: string, permission: string): Promise<void> { | |||
return post('/api/permissions/add_project_creator_to_template', { templateId, permission }); | |||
} | |||
export function removeProjectCreatorFromTemplate( | |||
templateId: string, | |||
permission: string | |||
): Promise<void> { | |||
return post('/api/permissions/remove_project_creator_from_template', { templateId, permission }); | |||
} | |||
export function getPermissionsUsersForComponent( | |||
projectKey: string, | |||
query?: string, | |||
permission?: string, | |||
organization?: string | |||
): Promise<any> { | |||
const data: RequestData = { projectKey, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON('/api/permissions/users', data).then(r => r.users); | |||
} | |||
export function getPermissionsGroupsForComponent( | |||
projectKey: string, | |||
query: string = '', | |||
permission?: string, | |||
organization?: string | |||
): Promise<any> { | |||
const data: RequestData = { projectKey, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON('/api/permissions/groups', data).then(r => r.groups); | |||
} | |||
export function getGlobalPermissionsUsers( | |||
query?: string, | |||
permission?: string, | |||
organization?: string | |||
): Promise<any> { | |||
const data: RequestData = { ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON('/api/permissions/users', data).then(r => r.users); | |||
} | |||
export function getGlobalPermissionsGroups( | |||
query?: string, | |||
permission?: string, | |||
organization?: string | |||
): Promise<any> { | |||
const data: RequestData = { ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON('/api/permissions/groups', data).then(r => r.groups); | |||
} | |||
export function getPermissionTemplateUsers( | |||
templateId: string, | |||
query?: string, | |||
permission?: string, | |||
organization?: string | |||
): Promise<any> { | |||
const data: RequestData = { templateId, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
Object.assign(data, { organization }); | |||
} | |||
return getJSON('/api/permissions/template_users', data).then(r => r.users); | |||
} | |||
export function getPermissionTemplateGroups( | |||
templateId: string, | |||
query?: string, | |||
permission?: string, | |||
organization?: string | |||
): Promise<any> { | |||
const data: RequestData = { templateId, ps: PAGE_SIZE }; | |||
if (query) { | |||
data.q = query; | |||
} | |||
if (permission) { | |||
data.permission = permission; | |||
} | |||
if (organization) { | |||
Object.assign(data, { organization }); | |||
} | |||
return getJSON('/api/permissions/template_groups', data).then(r => r.groups); | |||
} | |||
export function changeProjectVisibility(project: string, visibility: string): Promise<void> { | |||
return post('/api/projects/update_visibility', { project, visibility }); | |||
} |
@@ -17,53 +17,42 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { getJSON, postJSON, post } from '../helpers/request'; | |||
import { getJSON, postJSON, post, RequestData } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
/*:: | |||
type GetProjectActivityResponse = { | |||
analyses: Array<Object>, | |||
interface IGetProjectActivityResponse { | |||
analyses: any[]; | |||
paging: { | |||
total: number, | |||
pageIndex: number, | |||
pageSize: number | |||
} | |||
}; | |||
*/ | |||
/*:: | |||
type GetProjectActivityOptions = { | |||
project: string, | |||
category?: ?string, | |||
p?: ?number, | |||
ps?: ?number | |||
}; | |||
*/ | |||
total: number; | |||
pageIndex: number; | |||
pageSize: number; | |||
}; | |||
} | |||
export function getProjectActivity( | |||
data /*: GetProjectActivityOptions */ | |||
) /*: Promise<GetProjectActivityResponse> */ { | |||
export function getProjectActivity(data: { | |||
project: string; | |||
category?: string; | |||
p?: number; | |||
ps?: number; | |||
}): Promise<IGetProjectActivityResponse> { | |||
return getJSON('/api/project_analyses/search', data).catch(throwGlobalError); | |||
} | |||
/*:: | |||
type CreateEventResponse = { | |||
interface ICreateEventResponse { | |||
analysis: string; | |||
key: string; | |||
name: string; | |||
category: string; | |||
description?: string; | |||
} | |||
export function createEvent( | |||
analysis: string, | |||
key: string, | |||
name: string, | |||
category: string, | |||
category?: string, | |||
description?: string | |||
}; | |||
*/ | |||
export function createEvent( | |||
analysis /*: string */, | |||
name /*: string */, | |||
category /*: ?string */, | |||
description /*: ?string */ | |||
) /*: Promise<CreateEventResponse> */ { | |||
const data /*: Object */ = { analysis, name }; | |||
): Promise<ICreateEventResponse> { | |||
const data: RequestData = { analysis, name }; | |||
if (category) { | |||
data.category = category; | |||
} | |||
@@ -73,16 +62,16 @@ export function createEvent( | |||
return postJSON('/api/project_analyses/create_event', data).then(r => r.event, throwGlobalError); | |||
} | |||
export function deleteEvent(event /*: string */) /*: Promise<*> */ { | |||
export function deleteEvent(event: string): Promise<void | Response> { | |||
return post('/api/project_analyses/delete_event', { event }).catch(throwGlobalError); | |||
} | |||
export function changeEvent( | |||
event /*: string */, | |||
name /*: ?string */, | |||
description /*: ?string */ | |||
) /*: Promise<CreateEventResponse> */ { | |||
const data /*: Object */ = { event }; | |||
event: string, | |||
name?: string, | |||
description?: string | |||
): Promise<ICreateEventResponse> { | |||
const data: RequestData = { event }; | |||
if (name) { | |||
data.name = name; | |||
} | |||
@@ -92,6 +81,6 @@ export function changeEvent( | |||
return postJSON('/api/project_analyses/update_event', data).then(r => r.event, throwGlobalError); | |||
} | |||
export function deleteAnalysis(analysis /*: string */) /*: Promise<*> */ { | |||
export function deleteAnalysis(analysis: string): Promise<void | Response> { | |||
return post('/api/project_analyses/delete', { analysis }).catch(throwGlobalError); | |||
} |
@@ -19,19 +19,19 @@ | |||
*/ | |||
import { getJSON, post, postJSON } from '../helpers/request'; | |||
export function getProjectLinks(projectKey) { | |||
export function getProjectLinks(projectKey: string): Promise<any> { | |||
const url = '/api/project_links/search'; | |||
const data = { projectKey }; | |||
return getJSON(url, data).then(r => r.links); | |||
} | |||
export function deleteLink(linkId) { | |||
export function deleteLink(linkId: string): Promise<void> { | |||
const url = '/api/project_links/delete'; | |||
const data = { id: linkId }; | |||
return post(url, data); | |||
} | |||
export function createLink(projectKey, name, url) { | |||
export function createLink(projectKey: string, name: string, url: string): Promise<any> { | |||
const apiURL = '/api/project_links/create'; | |||
const data = { projectKey, name, url }; | |||
return postJSON(apiURL, data).then(r => r.link); |
@@ -1,112 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { getJSON, post, postJSON } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
export function fetchQualityGatesAppDetails() { | |||
const url = '/api/qualitygates/app'; | |||
return getJSON(url).catch(throwGlobalError); | |||
} | |||
export function fetchQualityGates() { | |||
const url = '/api/qualitygates/list'; | |||
return getJSON(url).then( | |||
r => | |||
r.qualitygates.map(qualityGate => { | |||
return { | |||
...qualityGate, | |||
isDefault: qualityGate.id === r.default | |||
}; | |||
}), | |||
throwGlobalError | |||
); | |||
} | |||
export function fetchQualityGate(id) { | |||
const url = '/api/qualitygates/show'; | |||
return getJSON(url, { id }).catch(throwGlobalError); | |||
} | |||
export function createQualityGate(name) { | |||
const url = '/api/qualitygates/create'; | |||
return postJSON(url, { name }); | |||
} | |||
export function deleteQualityGate(id) { | |||
const url = '/api/qualitygates/destroy'; | |||
return post(url, { id }); | |||
} | |||
export function renameQualityGate(id, name) { | |||
const url = '/api/qualitygates/rename'; | |||
return post(url, { id, name }); | |||
} | |||
export function copyQualityGate(id, name) { | |||
const url = '/api/qualitygates/copy'; | |||
return postJSON(url, { id, name }); | |||
} | |||
export function setQualityGateAsDefault(id) { | |||
const url = '/api/qualitygates/set_as_default'; | |||
return post(url, { id }).catch(throwGlobalError); | |||
} | |||
export function unsetQualityGateAsDefault(id) { | |||
const url = '/api/qualitygates/unset_default'; | |||
return post(url, { id }).catch(throwGlobalError); | |||
} | |||
export function createCondition(gateId, condition) { | |||
const url = '/api/qualitygates/create_condition'; | |||
return postJSON(url, { ...condition, gateId }); | |||
} | |||
export function updateCondition(condition) { | |||
const url = '/api/qualitygates/update_condition'; | |||
return postJSON(url, { ...condition }); | |||
} | |||
export function deleteCondition(id) { | |||
const url = '/api/qualitygates/delete_condition'; | |||
return post(url, { id }); | |||
} | |||
export function getGateForProject(projectKey) { | |||
const url = '/api/qualitygates/get_by_project'; | |||
const data = { projectKey }; | |||
return getJSON(url, data).then(r => r.qualityGate); | |||
} | |||
export function associateGateWithProject(gateId, projectKey) { | |||
const url = '/api/qualitygates/select'; | |||
const data = { gateId, projectKey }; | |||
return post(url, data).catch(throwGlobalError); | |||
} | |||
export function dissociateGateWithProject(gateId, projectKey) { | |||
const url = '/api/qualitygates/deselect'; | |||
const data = { gateId, projectKey }; | |||
return post(url, data).catch(throwGlobalError); | |||
} | |||
export function getApplicationQualityGate(application) { | |||
return getJSON('/api/qualitygates/application_status', { application }); | |||
} |
@@ -0,0 +1,97 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { getJSON, post, postJSON, RequestData } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
export function fetchQualityGatesAppDetails(): Promise<any> { | |||
return getJSON('/api/qualitygates/app').catch(throwGlobalError); | |||
} | |||
export function fetchQualityGates(): Promise<any> { | |||
return getJSON('/api/qualitygates/list').then( | |||
r => | |||
r.qualitygates.map((qualityGate: any) => { | |||
return { ...qualityGate, isDefault: qualityGate.id === r.default }; | |||
}), | |||
throwGlobalError | |||
); | |||
} | |||
export function fetchQualityGate(id: string): Promise<any> { | |||
return getJSON('/api/qualitygates/show', { id }).catch(throwGlobalError); | |||
} | |||
export function createQualityGate(name: string): Promise<any> { | |||
return postJSON('/api/qualitygates/create', { name }); | |||
} | |||
export function deleteQualityGate(id: string): Promise<void> { | |||
return post('/api/qualitygates/destroy', { id }); | |||
} | |||
export function renameQualityGate(id: string, name: string): Promise<void> { | |||
return post('/api/qualitygates/rename', { id, name }); | |||
} | |||
export function copyQualityGate(id: string, name: string): Promise<any> { | |||
return postJSON('/api/qualitygates/copy', { id, name }); | |||
} | |||
export function setQualityGateAsDefault(id: string): Promise<void | Response> { | |||
return post('/api/qualitygates/set_as_default', { id }).catch(throwGlobalError); | |||
} | |||
export function unsetQualityGateAsDefault(id: string): Promise<void | Response> { | |||
return post('/api/qualitygates/unset_default', { id }).catch(throwGlobalError); | |||
} | |||
export function createCondition(gateId: string, condition: RequestData): Promise<any> { | |||
return postJSON('/api/qualitygates/create_condition', { ...condition, gateId }); | |||
} | |||
export function updateCondition(condition: RequestData): Promise<any> { | |||
return postJSON('/api/qualitygates/update_condition', condition); | |||
} | |||
export function deleteCondition(id: string): Promise<void> { | |||
return post('/api/qualitygates/delete_condition', { id }); | |||
} | |||
export function getGateForProject(projectKey: string): Promise<any> { | |||
return getJSON('/api/qualitygates/get_by_project', { projectKey }).then(r => r.qualityGate); | |||
} | |||
export function associateGateWithProject( | |||
gateId: string, | |||
projectKey: string | |||
): Promise<void | Response> { | |||
return post('/api/qualitygates/select', { gateId, projectKey }).catch(throwGlobalError); | |||
} | |||
export function dissociateGateWithProject( | |||
gateId: string, | |||
projectKey: string | |||
): Promise<void | Response> { | |||
return post('/api/qualitygates/deselect', { gateId, projectKey }).catch(throwGlobalError); | |||
} | |||
export function getApplicationQualityGate(application: string): Promise<any> { | |||
return getJSON('/api/qualitygates/application_status', { application }); | |||
} |
@@ -1,123 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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. | |||
*/ | |||
// @flow | |||
import { request, checkStatus, parseJSON, getJSON, post, postJSON } from '../helpers/request'; | |||
export function searchQualityProfiles(data /*: { organization?: string, projectKey?: string } */) { | |||
const url = '/api/qualityprofiles/search'; | |||
return getJSON(url, data).then(r => r.profiles); | |||
} | |||
export function getQualityProfiles(data /*: { compareToSonarWay?: boolean, profile: string } */) { | |||
const url = '/api/qualityprofiles/show'; | |||
return getJSON(url, data); | |||
} | |||
export function createQualityProfile(data /*: Object */) { | |||
return request('/api/qualityprofiles/create') | |||
.setMethod('post') | |||
.setData(data) | |||
.submit() | |||
.then(checkStatus) | |||
.then(parseJSON); | |||
} | |||
export function restoreQualityProfile(data /*: Object */) { | |||
return request('/api/qualityprofiles/restore') | |||
.setMethod('post') | |||
.setData(data) | |||
.submit() | |||
.then(checkStatus) | |||
.then(parseJSON); | |||
} | |||
export function getProfileProjects(data /*: Object */) { | |||
const url = '/api/qualityprofiles/projects'; | |||
return getJSON(url, data); | |||
} | |||
export function getProfileInheritance(profileKey /*: string */) { | |||
const url = '/api/qualityprofiles/inheritance'; | |||
const data = { profileKey }; | |||
return getJSON(url, data); | |||
} | |||
export function setDefaultProfile(profileKey /*: string */) { | |||
const url = '/api/qualityprofiles/set_default'; | |||
const data = { profileKey }; | |||
return post(url, data); | |||
} | |||
export function renameProfile(key /*: string */, name /*: string */) { | |||
const url = '/api/qualityprofiles/rename'; | |||
const data = { key, name }; | |||
return post(url, data); | |||
} | |||
export function copyProfile(fromKey /*: string */, toName /*: string */) { | |||
const url = '/api/qualityprofiles/copy'; | |||
const data = { fromKey, toName }; | |||
return postJSON(url, data); | |||
} | |||
export function deleteProfile(profileKey /*: string */) { | |||
const url = '/api/qualityprofiles/delete'; | |||
const data = { profileKey }; | |||
return post(url, data); | |||
} | |||
export function changeProfileParent(profileKey /*: string */, parentKey /*: string */) { | |||
const url = '/api/qualityprofiles/change_parent'; | |||
const data = { profileKey, parentKey }; | |||
return post(url, data); | |||
} | |||
export function getImporters() { | |||
const url = '/api/qualityprofiles/importers'; | |||
return getJSON(url).then(r => r.importers); | |||
} | |||
export function getExporters() { | |||
const url = '/api/qualityprofiles/exporters'; | |||
return getJSON(url).then(r => r.exporters); | |||
} | |||
export function getProfileChangelog(data /*: Object */) { | |||
const url = '/api/qualityprofiles/changelog'; | |||
return getJSON(url, data); | |||
} | |||
export function compareProfiles(leftKey /*: string */, rightKey /*: string */) { | |||
const url = '/api/qualityprofiles/compare'; | |||
const data = { leftKey, rightKey }; | |||
return getJSON(url, data); | |||
} | |||
export function associateProject(profileKey /*: string */, projectKey /*: string */) { | |||
const url = '/api/qualityprofiles/add_project'; | |||
const data = { profileKey, projectKey }; | |||
return post(url, data); | |||
} | |||
export function dissociateProject(profileKey /*: string */, projectKey /*: string */) { | |||
const url = '/api/qualityprofiles/remove_project'; | |||
const data = { profileKey, projectKey }; | |||
return post(url, data); | |||
} |
@@ -0,0 +1,112 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { | |||
request, | |||
checkStatus, | |||
parseJSON, | |||
getJSON, | |||
post, | |||
postJSON, | |||
RequestData | |||
} from '../helpers/request'; | |||
export function searchQualityProfiles(data: { | |||
organization?: string; | |||
projectKey?: string; | |||
}): Promise<any> { | |||
return getJSON('/api/qualityprofiles/search', data).then(r => r.profiles); | |||
} | |||
export function getQualityProfiles(data: { | |||
compareToSonarWay?: boolean; | |||
profile: string; | |||
}): Promise<any> { | |||
return getJSON('/api/qualityprofiles/show', data); | |||
} | |||
export function createQualityProfile(data: RequestData): Promise<any> { | |||
return request('/api/qualityprofiles/create') | |||
.setMethod('post') | |||
.setData(data) | |||
.submit() | |||
.then(checkStatus) | |||
.then(parseJSON); | |||
} | |||
export function restoreQualityProfile(data: RequestData): Promise<any> { | |||
return request('/api/qualityprofiles/restore') | |||
.setMethod('post') | |||
.setData(data) | |||
.submit() | |||
.then(checkStatus) | |||
.then(parseJSON); | |||
} | |||
export function getProfileProjects(data: RequestData): Promise<any> { | |||
return getJSON('/api/qualityprofiles/projects', data); | |||
} | |||
export function getProfileInheritance(profileKey: string): Promise<any> { | |||
return getJSON('/api/qualityprofiles/inheritance', { profileKey }); | |||
} | |||
export function setDefaultProfile(profileKey: string): Promise<void> { | |||
return post('/api/qualityprofiles/set_default', { profileKey }); | |||
} | |||
export function renameProfile(key: string, name: string): Promise<void> { | |||
return post('/api/qualityprofiles/rename', { key, name }); | |||
} | |||
export function copyProfile(fromKey: string, toName: string): Promise<any> { | |||
return postJSON('/api/qualityprofiles/copy', { fromKey, toName }); | |||
} | |||
export function deleteProfile(profileKey: string): Promise<void> { | |||
return post('/api/qualityprofiles/delete', { profileKey }); | |||
} | |||
export function changeProfileParent(profileKey: string, parentKey: string): Promise<void> { | |||
return post('/api/qualityprofiles/change_parent', { profileKey, parentKey }); | |||
} | |||
export function getImporters(): Promise<any> { | |||
return getJSON('/api/qualityprofiles/importers').then(r => r.importers); | |||
} | |||
export function getExporters(): Promise<any> { | |||
return getJSON('/api/qualityprofiles/exporters').then(r => r.exporters); | |||
} | |||
export function getProfileChangelog(data: RequestData): Promise<any> { | |||
return getJSON('/api/qualityprofiles/changelog', data); | |||
} | |||
export function compareProfiles(leftKey: string, rightKey: string): Promise<any> { | |||
return getJSON('/api/qualityprofiles/compare', { leftKey, rightKey }); | |||
} | |||
export function associateProject(profileKey: string, projectKey: string): Promise<void> { | |||
return post('/api/qualityprofiles/add_project', { profileKey, projectKey }); | |||
} | |||
export function dissociateProject(profileKey: string, projectKey: string): Promise<void> { | |||
return post('/api/qualityprofiles/remove_project', { profileKey, projectKey }); | |||
} |
@@ -17,14 +17,13 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import { getJSON } from '../helpers/request'; | |||
import { getJSON, RequestData } from '../helpers/request'; | |||
export function searchRules(data) { | |||
const url = '/api/rules/search'; | |||
return getJSON(url, data); | |||
export function searchRules(data: RequestData) { | |||
return getJSON('/api/rules/search', data); | |||
} | |||
export function takeFacet(response, property) { | |||
const facet = response.facets.find(facet => facet.property === property); | |||
export function takeFacet(response: any, property: string) { | |||
const facet = response.facets.find((facet: any) => facet.property === property); | |||
return facet ? facet.values : []; | |||
} |
@@ -18,38 +18,34 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import { omitBy } from 'lodash'; | |||
import { getJSON, post, postJSON } from '../helpers/request'; | |||
import { getJSON, RequestData, post, postJSON } from '../helpers/request'; | |||
import { TYPE_PROPERTY_SET } from '../apps/settings/constants'; | |||
export function getDefinitions(componentKey) { | |||
const url = '/api/settings/list_definitions'; | |||
const data = {}; | |||
export function getDefinitions(componentKey: string): Promise<any> { | |||
const data: RequestData = {}; | |||
if (componentKey) { | |||
data.component = componentKey; | |||
} | |||
return getJSON(url, data).then(r => r.definitions); | |||
return getJSON('/api/settings/list_definitions', data).then(r => r.definitions); | |||
} | |||
export function getValues(keys, componentKey) { | |||
const url = '/api/settings/values'; | |||
const data = { keys }; | |||
export function getValues(keys: string, componentKey: string): Promise<any> { | |||
const data: RequestData = { keys }; | |||
if (componentKey) { | |||
data.component = componentKey; | |||
} | |||
return getJSON(url, data).then(r => r.settings); | |||
return getJSON('/api/settings/values', data).then(r => r.settings); | |||
} | |||
export function setSettingValue(definition, value, componentKey) { | |||
const url = '/api/settings/set'; | |||
export function setSettingValue(definition: any, value: any, componentKey: string): Promise<void> { | |||
const { key } = definition; | |||
const data = { key }; | |||
const data: RequestData = { key }; | |||
if (definition.multiValues) { | |||
data.values = value; | |||
} else if (definition.type === TYPE_PROPERTY_SET) { | |||
data.fieldValues = value | |||
.map(fields => omitBy(fields, value => value == null)) | |||
.map((fields: any) => omitBy(fields, value => value == null)) | |||
.map(JSON.stringify); | |||
} else { | |||
data.value = value; | |||
@@ -59,40 +55,37 @@ export function setSettingValue(definition, value, componentKey) { | |||
data.component = componentKey; | |||
} | |||
return post(url, data); | |||
return post('/api/settings/set', data); | |||
} | |||
export function resetSettingValue(key, componentKey) { | |||
const url = '/api/settings/reset'; | |||
const data = { keys: key }; | |||
export function resetSettingValue(key: string, componentKey: string): Promise<void> { | |||
const data: RequestData = { keys: key }; | |||
if (componentKey) { | |||
data.component = componentKey; | |||
} | |||
return post(url, data); | |||
return post('/api/settings/reset', data); | |||
} | |||
export function sendTestEmail(to, subject, message) { | |||
const url = '/api/emails/send'; | |||
const data = { to, subject, message }; | |||
return post(url, data); | |||
export function sendTestEmail(to: string, subject: string, message: string): Promise<void> { | |||
return post('/api/emails/send', { to, subject, message }); | |||
} | |||
export function checkSecretKey() { | |||
export function checkSecretKey(): Promise<any> { | |||
return getJSON('/api/settings/check_secret_key'); | |||
} | |||
export function generateSecretKey() { | |||
export function generateSecretKey(): Promise<any> { | |||
return postJSON('/api/settings/generate_secret_key'); | |||
} | |||
export function encryptValue(value) { | |||
export function encryptValue(value: string): Promise<any> { | |||
return postJSON('/api/settings/encrypt', { value }); | |||
} | |||
export function getServerId() { | |||
export function getServerId(): Promise<any> { | |||
return getJSON('/api/server_id/show'); | |||
} | |||
export function generateServerId(organization, ip) { | |||
export function generateServerId(organization: string, ip: string): Promise<any> { | |||
return postJSON('/api/server_id/generate', { organization, ip }); | |||
} |
@@ -19,30 +19,25 @@ | |||
*/ | |||
import { getJSON, post } from '../helpers/request'; | |||
export function setLogLevel(level) { | |||
const url = '/api/system/change_log_level'; | |||
const data = { level }; | |||
return post(url, data); | |||
export function setLogLevel(level: string): Promise<void> { | |||
return post('/api/system/change_log_level', { level }); | |||
} | |||
export function getSystemInfo() { | |||
const url = '/api/system/info'; | |||
return getJSON(url); | |||
export function getSystemInfo(): Promise<any> { | |||
return getJSON('/api/system/info'); | |||
} | |||
export function getSystemStatus() { | |||
const url = '/api/system/status'; | |||
return getJSON(url); | |||
export function getSystemStatus(): Promise<any> { | |||
return getJSON('/api/system/status'); | |||
} | |||
export function restart() { | |||
const url = '/api/system/restart'; | |||
return post(url); | |||
export function restart(): Promise<void> { | |||
return post('/api/system/restart'); | |||
} | |||
const POLLING_INTERVAL = 2000; | |||
function pollStatus(cb) { | |||
function pollStatus(cb: Function): void { | |||
setTimeout(() => { | |||
getSystemStatus() | |||
.then(r => { | |||
@@ -56,10 +51,10 @@ function pollStatus(cb) { | |||
}, POLLING_INTERVAL); | |||
} | |||
function promiseStatus() { | |||
function promiseStatus(): Promise<any> { | |||
return new Promise(resolve => pollStatus(resolve)); | |||
} | |||
export function restartAndWait() { | |||
export function restartAndWait(): Promise<any> { | |||
return restart().then(promiseStatus); | |||
} |
@@ -17,31 +17,21 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { getJSON } from '../helpers/request'; | |||
/*:: | |||
type Response = { | |||
interface ITimeMachineResponse { | |||
measures: Array<{ | |||
metric: string, | |||
history: Array<{ | |||
date: string, | |||
value: string | |||
}> | |||
}>, | |||
paging: { | |||
pageIndex: number, | |||
pageSize: number, | |||
total: number | |||
} | |||
}; | |||
*/ | |||
metric: string; | |||
history: Array<{ date: string; value: string }>; | |||
}>; | |||
paging: { pageIndex: number; pageSize: number; total: number }; | |||
} | |||
export function getTimeMachineData( | |||
component /*: string */, | |||
metrics /*: Array<string> */, | |||
other /*: ?{ p?: number, ps?: number, from?: string, to?: string } */ | |||
) /*: Promise<Response> */ { | |||
component: string, | |||
metrics: string[], | |||
other?: { p?: number; ps?: number; from?: string; to?: string } | |||
): Promise<ITimeMachineResponse> { | |||
return getJSON('/api/measures/search_history', { | |||
component, | |||
metrics: metrics.join(), | |||
@@ -51,11 +41,11 @@ export function getTimeMachineData( | |||
} | |||
export function getAllTimeMachineData( | |||
component /*: string */, | |||
metrics /*: Array<string> */, | |||
other /*: ?{ p?: number, from?: string, to?: string } */, | |||
prev /*: ?Response */ | |||
) /*: Promise<Response> */ { | |||
component: string, | |||
metrics: Array<string>, | |||
other?: { p?: number; from?: string; to?: string }, | |||
prev?: ITimeMachineResponse | |||
): Promise<ITimeMachineResponse> { | |||
return getTimeMachineData(component, metrics, { ...other, ps: 1000 }).then(r => { | |||
const result = prev | |||
? { |
@@ -17,50 +17,37 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { getJSON, postJSON, post } from '../helpers/request'; | |||
import { getJSON, postJSON, post, RequestData } from '../helpers/request'; | |||
import throwGlobalError from '../app/utils/throwGlobalError'; | |||
/** | |||
* List tokens for given user login | |||
* @param {string} login | |||
* @returns {Promise} | |||
*/ | |||
export function getTokens(login /*: string */) { | |||
const url = '/api/user_tokens/search'; | |||
const data = { login }; | |||
return getJSON(url, data).then(r => r.userTokens); | |||
export function getTokens(login: string): Promise<any> { | |||
return getJSON('/api/user_tokens/search', { login }).then(r => r.userTokens); | |||
} | |||
/** | |||
* Generate a user token | |||
* @param {string} userLogin | |||
* @param {string} tokenName | |||
* @returns {Promise} | |||
*/ | |||
export function generateToken( | |||
tokenName /*: string */, | |||
userLogin /*: ?string */ | |||
) /*: Promise<{ name: string, token: string }> */ { | |||
const url = '/api/user_tokens/generate'; | |||
const data /*: { [string]: string } */ = { name: tokenName }; | |||
tokenName: string, | |||
userLogin?: string | |||
): Promise<{ name: string; token: string }> { | |||
const data: RequestData = { name: tokenName }; | |||
if (userLogin) { | |||
data.login = userLogin; | |||
} | |||
return postJSON(url, data).catch(throwGlobalError); | |||
return postJSON('/api/user_tokens/generate', data).catch(throwGlobalError); | |||
} | |||
/** | |||
* Revoke a user token | |||
* @param {string} userLogin | |||
* @param {string} tokenName | |||
* @returns {Promise} | |||
*/ | |||
export function revokeToken(tokenName /*: string */, userLogin /*: ?string */) { | |||
const url = '/api/user_tokens/revoke'; | |||
const data /*: { [string]: string } */ = { name: tokenName }; | |||
export function revokeToken(tokenName: string, userLogin?: string): Promise<void | Response> { | |||
const data: RequestData = { name: tokenName }; | |||
if (userLogin) { | |||
data.login = userLogin; | |||
} | |||
return post(url, data).catch(throwGlobalError); | |||
return post('/api/user_tokens/revoke', data).catch(throwGlobalError); | |||
} |
@@ -1,58 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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. | |||
*/ | |||
//@flow | |||
import { getJSON, post } from '../helpers/request'; | |||
export function searchUsersGroups( | |||
data /*: { | |||
f?: string, | |||
organization?: string, | |||
p?: number, | |||
ps?: number, | |||
q?: string | |||
} */ | |||
) { | |||
const url = '/api/user_groups/search'; | |||
return getJSON(url, data); | |||
} | |||
export function addUserToGroup( | |||
data /*: { | |||
id?: string, | |||
name?: string, | |||
login?: string, | |||
organization?: string | |||
} */ | |||
) { | |||
const url = '/api/user_groups/add_user'; | |||
return post(url, data); | |||
} | |||
export function removeUserFromGroup( | |||
data /*: { | |||
id?: string, | |||
name?: string, | |||
login?: string, | |||
organization?: string | |||
} */ | |||
) { | |||
const url = '/api/user_groups/remove_user'; | |||
return post(url, data); | |||
} |
@@ -0,0 +1,48 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { getJSON, post } from '../helpers/request'; | |||
export function searchUsersGroups(data: { | |||
f?: string; | |||
organization?: string; | |||
p?: number; | |||
ps?: number; | |||
q?: string; | |||
}) { | |||
return getJSON('/api/user_groups/search', data); | |||
} | |||
export function addUserToGroup(data: { | |||
id?: string; | |||
name?: string; | |||
login?: string; | |||
organization?: string; | |||
}) { | |||
return post('/api/user_groups/add_user', data); | |||
} | |||
export function removeUserFromGroup(data: { | |||
id?: string; | |||
name?: string; | |||
login?: string; | |||
organization?: string; | |||
}) { | |||
return post('/api/user_groups/remove_user', data); | |||
} |
@@ -17,53 +17,44 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
//@flow | |||
import { getJSON, post } from '../helpers/request'; | |||
import { getJSON, post, RequestData } from '../helpers/request'; | |||
export function getCurrentUser() { | |||
const url = '/api/users/current'; | |||
return getJSON(url); | |||
export function getCurrentUser(): Promise<any> { | |||
return getJSON('/api/users/current'); | |||
} | |||
export function changePassword( | |||
login /*: string */, | |||
password /*: string */, | |||
previousPassword /*: ?string */ | |||
) { | |||
const url = '/api/users/change_password'; | |||
const data /*: { login: string, password: string, previousPassword?: string } */ = { | |||
login, | |||
password | |||
}; | |||
login: string, | |||
password: string, | |||
previousPassword?: string | |||
): Promise<void> { | |||
const data: RequestData = { login, password }; | |||
if (previousPassword != null) { | |||
data.previousPassword = previousPassword; | |||
} | |||
return post(url, data); | |||
return post('/api/users/change_password', data); | |||
} | |||
export function getUserGroups(login /*: string */, organization /*: ?string */) { | |||
const url = '/api/users/groups'; | |||
const data /*: { login: string, organization?: string, q?: string } */ = { login }; | |||
export function getUserGroups(login: string, organization?: string): Promise<any> { | |||
const data: RequestData = { login }; | |||
if (organization) { | |||
data.organization = organization; | |||
} | |||
return getJSON(url, data); | |||
return getJSON('/api/users/groups', data); | |||
} | |||
export function getIdentityProviders() { | |||
const url = '/api/users/identity_providers'; | |||
return getJSON(url); | |||
export function getIdentityProviders(): Promise<any> { | |||
return getJSON('/api/users/identity_providers'); | |||
} | |||
export function searchUsers(query /*: string */, pageSize /*: ?number */) { | |||
const url = '/api/users/search'; | |||
const data /*: { q: string, ps?: number } */ = { q: query }; | |||
export function searchUsers(query: string, pageSize?: number): Promise<any> { | |||
const data: RequestData = { q: query }; | |||
if (pageSize != null) { | |||
data.ps = pageSize; | |||
} | |||
return getJSON(url, data); | |||
return getJSON('/api/users/search', data); | |||
} | |||
export function skipOnboarding() /*: Promise<void> */ { | |||
export function skipOnboarding(): Promise<void> { | |||
return post('/api/users/skip_onboarding_tutorial'); | |||
} |
@@ -1,87 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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. | |||
*/ | |||
// @flow | |||
import { getJSON } from '../helpers/request'; | |||
/*:: | |||
export type Param = { | |||
key: string, | |||
defaultValue?: string, | |||
description: string, | |||
deprecatedKey?: string, | |||
deprecatedKeySince?: string, | |||
deprecatedSince?: string, | |||
exampleValue?: string, | |||
internal: boolean, | |||
possibleValues?: Array<string>, | |||
required: boolean | |||
}; | |||
*/ | |||
/*:: | |||
export type Action = { | |||
key: string, | |||
description: string, | |||
deprecatedSince?: string, | |||
since?: string, | |||
internal: boolean, | |||
post: boolean, | |||
hasResponseExample: boolean, | |||
changelog: Array<{ | |||
version: string, | |||
description: string | |||
}>, | |||
params?: Array<Param> | |||
}; | |||
*/ | |||
/*:: | |||
export type Domain = { | |||
actions: Array<Action>, | |||
description: string, | |||
deprecated: boolean, | |||
internal: boolean, | |||
path: string | |||
}; | |||
*/ | |||
export function fetchWebApi(showInternal /*: boolean */ = true) /*: Promise<Array<Domain>> */ { | |||
const url = '/api/webservices/list'; | |||
const data = { include_internals: showInternal }; | |||
return getJSON(url, data).then(r => | |||
r.webServices.map(domain => { | |||
const deprecated = !domain.actions.find(action => !action.deprecatedSince); | |||
const internal = !domain.actions.find(action => !action.internal); | |||
return { ...domain, deprecated, internal }; | |||
}) | |||
); | |||
} | |||
export function fetchResponseExample( | |||
domain /*: string */, | |||
action /*: string */ | |||
) /*: Promise<{ example: string }> */ { | |||
const url = '/api/webservices/response_example'; | |||
const data = { controller: domain, action }; | |||
return getJSON(url, data); | |||
} |
@@ -0,0 +1,67 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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 { getJSON } from '../helpers/request'; | |||
export interface Param { | |||
key: string; | |||
defaultValue?: string; | |||
description: string; | |||
deprecatedKey?: string; | |||
deprecatedKeySince?: string; | |||
deprecatedSince?: string; | |||
exampleValue?: string; | |||
internal: boolean; | |||
possibleValues?: string[]; | |||
required: boolean; | |||
} | |||
export interface Action { | |||
key: string; | |||
description: string; | |||
deprecatedSince?: string; | |||
since?: string; | |||
internal: boolean; | |||
post: boolean; | |||
hasResponseExample: boolean; | |||
changelog: Array<{ version: string; description: string }>; | |||
params?: Param[]; | |||
} | |||
export interface Domain { | |||
actions: Action[]; | |||
description: string; | |||
deprecated: boolean; | |||
internal: boolean; | |||
path: string; | |||
} | |||
export function fetchWebApi(showInternal: boolean = true): Promise<Array<Domain>> { | |||
return getJSON('/api/webservices/list', { include_internals: showInternal }).then(r => | |||
r.webServices.map((domain: any) => { | |||
const deprecated = !domain.actions.find((action: any) => !action.deprecatedSince); | |||
const internal = !domain.actions.find((action: any) => !action.internal); | |||
return { ...domain, deprecated, internal }; | |||
}) | |||
); | |||
} | |||
export function fetchResponseExample(domain: string, action: string): Promise<{ example: string }> { | |||
return getJSON('/api/webservices/response_example', { controller: domain, action }); | |||
} |
@@ -17,12 +17,11 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import getStore from './getStore'; | |||
import { onFail } from '../../store/rootActions'; | |||
export default function throwGlobalError(error /*: Object */) { | |||
export default function throwGlobalError({ response }: { response: Response }): Promise<Response> { | |||
const store = getStore(); | |||
onFail(store.dispatch)(error); | |||
return Promise.reject(); | |||
onFail(store.dispatch)({ response }); | |||
return Promise.reject(response); | |||
} |
@@ -17,23 +17,15 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
// @flow | |||
import { stringify } from 'querystring'; | |||
import { omitBy, isNil } from 'lodash'; | |||
import { getCookie } from './cookies'; | |||
/*:: | |||
type Response = { | |||
json: () => Promise<Object>, | |||
status: number | |||
}; | |||
*/ | |||
export function getCSRFTokenName() /*: string */ { | |||
export function getCSRFTokenName(): string { | |||
return 'X-XSRF-TOKEN'; | |||
} | |||
export function getCSRFTokenValue() /*: string */ { | |||
export function getCSRFTokenValue(): string { | |||
const cookieName = 'XSRF-TOKEN'; | |||
const cookieValue = getCookie(cookieName); | |||
if (!cookieValue) { | |||
@@ -44,59 +36,53 @@ export function getCSRFTokenValue() /*: string */ { | |||
/** | |||
* Return an object containing a special http request header used to prevent CSRF attacks. | |||
* @returns {Object} | |||
*/ | |||
export function getCSRFToken() /*: Object */ { | |||
export function getCSRFToken(): { [x: string]: string } { | |||
// Fetch API in Edge doesn't work with empty header, | |||
// so we ensure non-empty value | |||
const value = getCSRFTokenValue(); | |||
return value ? { [getCSRFTokenName()]: value } : {}; | |||
} | |||
export function omitNil(obj /*: Object */) /*: Object */ { | |||
export function omitNil(obj: { [x: string]: any }): { [x: string]: any } { | |||
return omitBy(obj, isNil); | |||
} | |||
/** | |||
* Default options for any request | |||
*/ | |||
const DEFAULT_OPTIONS /*: { | |||
credentials: string, | |||
method: string | |||
} */ = { | |||
method: 'GET', | |||
credentials: 'same-origin' | |||
const DEFAULT_OPTIONS: { | |||
credentials: RequestCredentials; | |||
method: string; | |||
} = { | |||
credentials: 'same-origin', | |||
method: 'GET' | |||
}; | |||
/** | |||
* Default request headers | |||
*/ | |||
const DEFAULT_HEADERS /*: { | |||
'Accept': string | |||
} */ = { | |||
const DEFAULT_HEADERS = { | |||
Accept: 'application/json' | |||
}; | |||
export interface RequestData { | |||
[x: string]: any; | |||
} | |||
/** | |||
* Request | |||
*/ | |||
class Request { | |||
/*:: url: string; */ | |||
/*:: options: { method?: string }; */ | |||
/*:: headers: Object; */ | |||
/*:: data: ?Object; */ | |||
constructor(url /*: string */) /*: void */ { | |||
this.url = url; | |||
this.options = {}; | |||
this.headers = {}; | |||
} | |||
private data: RequestData; | |||
constructor(private url: string, private options: { method?: string } = {}) {} | |||
submit() { | |||
let url /*: string */ = this.url; | |||
submit(): Promise<Response> { | |||
let url = this.url; | |||
const options = { ...DEFAULT_OPTIONS, ...this.options }; | |||
const customHeaders = {}; | |||
const options: RequestInit = { ...DEFAULT_OPTIONS, ...this.options }; | |||
const customHeaders: any = {}; | |||
if (this.data) { | |||
if (this.data instanceof FormData) { | |||
@@ -115,44 +101,36 @@ class Request { | |||
options.headers = { | |||
...DEFAULT_HEADERS, | |||
...customHeaders, | |||
...this.headers, | |||
...getCSRFToken() | |||
}; | |||
return window.fetch(window.baseUrl + url, options); | |||
return window.fetch((window as any).baseUrl + url, options); | |||
} | |||
setMethod(method /*: string */) /*: Request */ { | |||
setMethod(method: string): Request { | |||
this.options.method = method; | |||
return this; | |||
} | |||
setData(data /*: ?Object */) /*: Request */ { | |||
this.data = data; | |||
return this; | |||
} | |||
setHeader(name /*: string */, value /*: string */) /*: Request */ { | |||
this.headers[name] = value; | |||
setData(data?: RequestData): Request { | |||
if (data) { | |||
this.data = data; | |||
} | |||
return this; | |||
} | |||
} | |||
/** | |||
* Make a request | |||
* @param {string} url | |||
* @returns {Request} | |||
*/ | |||
export function request(url /*: string */) /*: Request */ { | |||
export function request(url: string): Request { | |||
return new Request(url); | |||
} | |||
/** | |||
* Check that response status is ok | |||
* @param response | |||
* @returns {*} | |||
*/ | |||
export function checkStatus(response /*: Response */) /*: Promise<Object> */ { | |||
export function checkStatus(response: Response): Promise<Response> { | |||
return new Promise((resolve, reject) => { | |||
if (response.status === 401) { | |||
// workaround cyclic dependencies | |||
@@ -169,54 +147,46 @@ export function checkStatus(response /*: Response */) /*: Promise<Object> */ { | |||
/** | |||
* Parse response as JSON | |||
* @param response | |||
* @returns {object} | |||
*/ | |||
export function parseJSON(response /*: Response */) /*: Promise<Object> */ { | |||
export function parseJSON(response: Response): Promise<any> { | |||
return response.json(); | |||
} | |||
/** | |||
* Shortcut to do a GET request and return response json | |||
* @param url | |||
* @param data | |||
*/ | |||
export function getJSON(url /*: string */, data /*: ?Object */) /*: Promise<Object> */ { | |||
export function getJSON(url: string, data?: RequestData): Promise<any> { | |||
return request(url).setData(data).submit().then(checkStatus).then(parseJSON); | |||
} | |||
/** | |||
* Shortcut to do a POST request and return response json | |||
* @param url | |||
* @param data | |||
*/ | |||
export function postJSON(url /*: string */, data /*: ?Object */) /*: Promise<Object> */ { | |||
export function postJSON(url: string, data?: RequestData): Promise<any> { | |||
return request(url).setMethod('POST').setData(data).submit().then(checkStatus).then(parseJSON); | |||
} | |||
/** | |||
* Shortcut to do a POST request | |||
* @param url | |||
* @param data | |||
*/ | |||
export function post(url /*: string */, data /*: ?Object */) /*: Promise<void> */ { | |||
return request(url).setMethod('POST').setData(data).submit().then(checkStatus); | |||
export function post(url: string, data?: RequestData): Promise<void> { | |||
return new Promise(resolve => { | |||
request(url).setMethod('POST').setData(data).submit().then(checkStatus).then(() => { | |||
resolve(); | |||
}); | |||
}); | |||
} | |||
/** | |||
* Shortcut to do a POST request and return response json | |||
* @param url | |||
* @param data | |||
*/ | |||
export function requestDelete(url /*: string */, data /*: ?Object */) /*: Promise<Object> */ { | |||
export function requestDelete(url: string, data?: RequestData): Promise<any> { | |||
return request(url).setMethod('DELETE').setData(data).submit().then(checkStatus); | |||
} | |||
/** | |||
* Delay promise for testing purposes | |||
* @param response | |||
* @returns {Promise} | |||
*/ | |||
export function delay(response /*: * */) /*: Promise<*> */ { | |||
export function delay(response: any): Promise<any> { | |||
return new Promise(resolve => setTimeout(() => resolve(response), 1200)); | |||
} |