UNPKG

@craftercms/studio-ui

Version:

Services, components, models & utils to build CrafterCMS authoring extensions.

88 lines (86 loc) 3.7 kB
/* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 as published by * the Free Software Foundation. * * 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, see <http://www.gnu.org/licenses/>. */ /* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as published by * the Free Software Foundation. * * 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import { get, postJSON } from '../utils/ajax'; import { forkJoin } from 'rxjs'; import { map } from 'rxjs/operators'; const repositoryEndpointUrl = '/studio/api/2/repository'; export function fetchRepositories(siteId) { return get(`${repositoryEndpointUrl}/list_remotes?siteId=${siteId}`).pipe( map((response) => response?.response?.remotes) ); } export function addRemote(remote) { return postJSON(`${repositoryEndpointUrl}/add_remote`, remote).pipe(map(() => true)); } export function deleteRemote(siteId, remoteName) { return postJSON(`${repositoryEndpointUrl}/remove_remote`, { siteId, remoteName }).pipe(map(() => true)); } export function pull(remote) { return postJSON(`${repositoryEndpointUrl}/pull_from_remote`, remote).pipe( map((response) => response?.response?.result) ); } export function push(siteId, remoteName, remoteBranch, force) { return postJSON(`${repositoryEndpointUrl}/push_to_remote`, { siteId, remoteName, remoteBranch, force }).pipe( map(() => true) ); } export function fetchStatus(siteId) { return get(`${repositoryEndpointUrl}/status?siteId=${siteId}`).pipe( map((response) => response?.response?.repositoryStatus) ); } export function resolveConflict(siteId, path, resolution) { return postJSON(`${repositoryEndpointUrl}/resolve_conflict`, { siteId, path, resolution }).pipe( map((response) => response?.response?.repositoryStatus) ); } export function bulkResolveConflict(siteId, paths, resolution) { // Return only the status where there are no more conflicts return forkJoin(paths.map((path) => resolveConflict(siteId, path, resolution))).pipe( map((statuses) => statuses.filter((status) => status.conflicting.length === 0)[0]) ); } export function diffConflictedFile(siteId, path) { return get(`${repositoryEndpointUrl}/diff_conflicted_file?siteId=${siteId}&path=${path}`).pipe( map((response) => response?.response?.diff) ); } export function commitResolution(siteId, commitMessage) { return postJSON(`${repositoryEndpointUrl}/commit_resolution`, { siteId, commitMessage }).pipe( map((response) => response?.response?.repositoryStatus) ); } export function cancelFailedPull(siteId) { return postJSON(`${repositoryEndpointUrl}/cancel_failed_pull`, { siteId }).pipe( map((response) => response?.response?.repositoryStatus) ); }