debian-mirror-gitlab/app/assets/javascripts/api/projects_api.js

66 lines
2 KiB
JavaScript
Raw Normal View History

2021-09-30 23:02:18 +05:30
import { DEFAULT_PER_PAGE } from '~/api';
2021-03-08 18:12:59 +05:30
import axios from '../lib/utils/axios_utils';
import { buildApiUrl } from './api_utils';
const PROJECTS_PATH = '/api/:version/projects.json';
2023-04-23 21:23:45 +05:30
const PROJECT_MEMBERS_PATH = '/api/:version/projects/:id/members';
const PROJECT_ALL_MEMBERS_PATH = '/api/:version/projects/:id/members/all';
2021-11-11 11:23:49 +05:30
const PROJECT_IMPORT_MEMBERS_PATH = '/api/:version/projects/:id/import_project_members/:project_id';
2022-07-23 23:45:48 +05:30
const PROJECT_REPOSITORY_SIZE_PATH = '/api/:version/projects/:id/repository_size';
2022-11-25 23:54:43 +05:30
const PROJECT_TRANSFER_LOCATIONS_PATH = 'api/:version/projects/:id/transfer_locations';
2021-03-08 18:12:59 +05:30
export function getProjects(query, options, callback = () => {}) {
const url = buildApiUrl(PROJECTS_PATH);
const defaults = {
search: query,
per_page: DEFAULT_PER_PAGE,
simple: true,
};
if (gon.current_user_id) {
defaults.membership = true;
}
2023-04-23 21:23:45 +05:30
if (gon.features.fullPathProjectSearch && query?.includes('/')) {
defaults.search_namespaces = true;
}
2021-03-08 18:12:59 +05:30
return axios
.get(url, {
params: Object.assign(defaults, options),
})
.then(({ data, headers }) => {
callback(data);
return { data, headers };
});
}
2021-11-11 11:23:49 +05:30
export function importProjectMembers(sourceId, targetId) {
const url = buildApiUrl(PROJECT_IMPORT_MEMBERS_PATH)
.replace(':id', sourceId)
.replace(':project_id', targetId);
return axios.post(url);
}
2022-07-23 23:45:48 +05:30
export function updateRepositorySize(projectPath) {
const url = buildApiUrl(PROJECT_REPOSITORY_SIZE_PATH).replace(
':id',
encodeURIComponent(projectPath),
);
return axios.post(url);
}
2022-11-25 23:54:43 +05:30
export const getTransferLocations = (projectId, params = {}) => {
const url = buildApiUrl(PROJECT_TRANSFER_LOCATIONS_PATH).replace(':id', projectId);
const defaultParams = { per_page: DEFAULT_PER_PAGE };
return axios.get(url, { params: { ...defaultParams, ...params } });
};
2023-04-23 21:23:45 +05:30
export const getProjectMembers = (projectId, inherited = false) => {
const path = inherited ? PROJECT_ALL_MEMBERS_PATH : PROJECT_MEMBERS_PATH;
const url = buildApiUrl(path).replace(':id', projectId);
return axios.get(url);
};