UNPKG

@craftercms/studio-ui

Version:

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

75 lines (73 loc) 3.21 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 { map, pluck } from 'rxjs/operators'; const repositoryEndpointUrl = '/studio/api/2/repository'; export function fetchRepositories(siteId) { return get(`${repositoryEndpointUrl}/list_remotes?siteId=${siteId}`).pipe(pluck('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(pluck('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(pluck('response', 'repositoryStatus')); } export function resolveConflict(siteId, path, resolution) { return postJSON(`${repositoryEndpointUrl}/resolve_conflict`, { siteId, path, resolution }).pipe( pluck('response', 'repositoryStatus') ); } export function diffConflictedFile(siteId, path) { return get(`${repositoryEndpointUrl}/diff_conflicted_file?siteId=${siteId}&path=${path}`).pipe( pluck('response', 'diff') ); } export function commitResolution(siteId, commitMessage) { return postJSON(`${repositoryEndpointUrl}/commit_resolution`, { siteId, commitMessage }).pipe( pluck('response', 'repositoryStatus') ); } export function cancelFailedPull(siteId) { return postJSON(`${repositoryEndpointUrl}/cancel_failed_pull`, { siteId }).pipe( pluck('response', 'repositoryStatus') ); }