feat: allow setting editorial workflow PR label prefix (#4181)
This commit is contained in:
committed by
GitHub
parent
c0fc423040
commit
6b8fa3fc45
@ -2,10 +2,15 @@ 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}`;
|
||||
const DEFAULT_NETLIFY_CMS_LABEL_PREFIX = 'netlify-cms/';
|
||||
const getLabelPrefix = (labelPrefix: string) => labelPrefix || DEFAULT_NETLIFY_CMS_LABEL_PREFIX;
|
||||
|
||||
export const isCMSLabel = (label: string, labelPrefix: string) =>
|
||||
label.startsWith(getLabelPrefix(labelPrefix));
|
||||
export const labelToStatus = (label: string, labelPrefix: string) =>
|
||||
label.substr(getLabelPrefix(labelPrefix).length);
|
||||
export const statusToLabel = (status: string, labelPrefix: string) =>
|
||||
`${getLabelPrefix(labelPrefix)}${status}`;
|
||||
|
||||
export const generateContentKey = (collectionName: string, slug: string) =>
|
||||
`${collectionName}/${slug}`;
|
||||
|
@ -19,23 +19,56 @@ describe('APIUtils', () => {
|
||||
|
||||
describe('isCMSLabel', () => {
|
||||
it('should return true for CMS label', () => {
|
||||
expect(apiUtils.isCMSLabel('netlify-cms/draft')).toBe(true);
|
||||
expect(apiUtils.isCMSLabel('netlify-cms/draft', 'netlify-cms/')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for non CMS label', () => {
|
||||
expect(apiUtils.isCMSLabel('other/label')).toBe(false);
|
||||
expect(apiUtils.isCMSLabel('other/label', 'netlify-cms/')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if the prefix not provided for CMS label', () => {
|
||||
expect(apiUtils.isCMSLabel('netlify-cms/draft', '')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if a different prefix provided for CMS label', () => {
|
||||
expect(apiUtils.isCMSLabel('netlify-cms/draft', 'other/')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for CMS label when undefined prefix is passed', () => {
|
||||
expect(apiUtils.isCMSLabel('netlify-cms/draft', undefined)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('labelToStatus', () => {
|
||||
it('should get status from label', () => {
|
||||
expect(apiUtils.labelToStatus('netlify-cms/draft')).toBe('draft');
|
||||
it('should get status from label when default prefix is passed', () => {
|
||||
expect(apiUtils.labelToStatus('netlify-cms/draft', 'netlify-cms/')).toBe('draft');
|
||||
});
|
||||
|
||||
it('should get status from label when custom prefix is passed', () => {
|
||||
expect(apiUtils.labelToStatus('other/draft', 'other/')).toBe('draft');
|
||||
});
|
||||
|
||||
it('should get status from label when empty prefix is passed', () => {
|
||||
expect(apiUtils.labelToStatus('netlify-cms/draft', '')).toBe('draft');
|
||||
});
|
||||
|
||||
it('should get status from label when undefined prefix is passed', () => {
|
||||
expect(apiUtils.labelToStatus('netlify-cms/draft', undefined)).toBe('draft');
|
||||
});
|
||||
});
|
||||
|
||||
describe('statusToLabel', () => {
|
||||
it('should generate label from status', () => {
|
||||
expect(apiUtils.statusToLabel('draft')).toBe('netlify-cms/draft');
|
||||
it('should generate label from status when default prefix is passed', () => {
|
||||
expect(apiUtils.statusToLabel('draft', 'netlify-cms/')).toBe('netlify-cms/draft');
|
||||
});
|
||||
it('should generate label from status when custom prefix is passed', () => {
|
||||
expect(apiUtils.statusToLabel('draft', 'other/')).toBe('other/draft');
|
||||
});
|
||||
it('should generate label from status when empty prefix is passed', () => {
|
||||
expect(apiUtils.statusToLabel('draft', '')).toBe('netlify-cms/draft');
|
||||
});
|
||||
it('should generate label from status when undefined prefix is passed', () => {
|
||||
expect(apiUtils.statusToLabel('draft', undefined)).toBe('netlify-cms/draft');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -89,6 +89,7 @@ export type Config = {
|
||||
proxy_url?: string;
|
||||
auth_type?: string;
|
||||
app_id?: string;
|
||||
cms_label_prefix?: string;
|
||||
};
|
||||
media_folder: string;
|
||||
base_url?: string;
|
||||
|
Reference in New Issue
Block a user