fix: move common api functions to a separate file (#3511)

This commit is contained in:
Erez Rokah
2020-04-01 11:44:39 +03:00
committed by GitHub
parent 816bef5ffa
commit 49098de27f
7 changed files with 75 additions and 91 deletions

View File

@ -1,31 +1,6 @@
import { asyncLock, AsyncLock } from './asyncLock';
import unsentRequest from './unsentRequest';
export const CMS_BRANCH_PREFIX = 'cms';
export const DEFAULT_PR_BODY = 'Automatically generated by Netlify CMS';
export const MERGE_COMMIT_MESSAGE = 'Automatically generated. Merged on Netlify CMS.';
const NETLIFY_CMS_LABEL_PREFIX = 'netlify-cms/';
export const isCMSLabel = (label: string) => label.startsWith(NETLIFY_CMS_LABEL_PREFIX);
export const labelToStatus = (label: string) => label.substr(NETLIFY_CMS_LABEL_PREFIX.length);
export const statusToLabel = (status: string) => `${NETLIFY_CMS_LABEL_PREFIX}${status}`;
export const generateContentKey = (collectionName: string, slug: string) =>
`${collectionName}/${slug}`;
export const parseContentKey = (contentKey: string) => {
const index = contentKey.indexOf('/');
return { collection: contentKey.substr(0, index), slug: contentKey.substr(index + 1) };
};
export const contentKeyFromBranch = (branch: string) => {
return branch.substring(`${CMS_BRANCH_PREFIX}/`.length);
};
export const branchFromContentKey = (contentKey: string) => {
return `${CMS_BRANCH_PREFIX}/${contentKey}`;
};
export interface FetchError extends Error {
status: number;
}