feat: allow setting editorial workflow PR label prefix (#4181)

This commit is contained in:
Kancer (Nilay) Gökırmak
2020-09-06 20:13:46 +02:00
committed by GitHub
parent c0fc423040
commit 6b8fa3fc45
18 changed files with 170 additions and 44 deletions

View File

@ -82,6 +82,7 @@ export const defaultSchema = ({ path = requiredString } = {}) => {
id: Joi.string().optional(),
collection: Joi.string().optional(),
slug: Joi.string().optional(),
cmsLabelPrefix: Joi.string().optional(),
})
.required(),
},
@ -120,6 +121,7 @@ export const defaultSchema = ({ path = requiredString } = {}) => {
is: 'persistEntry',
then: defaultParams
.keys({
cmsLabelPrefix: Joi.string().optional(),
entry: Joi.object({
slug: requiredString,
path,
@ -145,6 +147,7 @@ export const defaultSchema = ({ path = requiredString } = {}) => {
collection,
slug,
newStatus: requiredString,
cmsLabelPrefix: Joi.string().optional(),
})
.required(),
},

View File

@ -222,7 +222,7 @@ export const localGitMiddleware = ({ repoPath, logger }: GitOptions) => {
break;
}
case 'unpublishedEntry': {
let { id, collection, slug } = body.params as UnpublishedEntryParams;
let { id, collection, slug, cmsLabelPrefix } = body.params as UnpublishedEntryParams;
if (id) {
({ collection, slug } = parseContentKey(id));
}
@ -232,7 +232,7 @@ export const localGitMiddleware = ({ repoPath, logger }: GitOptions) => {
if (branchExists) {
const diffs = await getDiffs(git, branch, cmsBranch);
const label = await git.raw(['config', branchDescription(cmsBranch)]);
const status = label && labelToStatus(label.trim());
const status = label && labelToStatus(label.trim(), cmsLabelPrefix || '');
const unpublishedEntry = {
collection,
slug,
@ -276,7 +276,7 @@ export const localGitMiddleware = ({ repoPath, logger }: GitOptions) => {
break;
}
case 'persistEntry': {
const { entry, assets, options } = body.params as PersistEntryParams;
const { entry, assets, options, cmsLabelPrefix } = body.params as PersistEntryParams;
if (!options.useWorkflow) {
await runOnBranch(git, branch, async () => {
await commitEntry(git, repoPath, entry, assets, options.commitMessage);
@ -304,7 +304,7 @@ export const localGitMiddleware = ({ repoPath, logger }: GitOptions) => {
// add status for new entries
if (!branchExists) {
const description = statusToLabel(options.status);
const description = statusToLabel(options.status, cmsLabelPrefix || '');
await git.addConfig(branchDescription(cmsBranch), description);
}
});
@ -313,10 +313,15 @@ export const localGitMiddleware = ({ repoPath, logger }: GitOptions) => {
break;
}
case 'updateUnpublishedEntryStatus': {
const { collection, slug, newStatus } = body.params as UpdateUnpublishedEntryStatusParams;
const {
collection,
slug,
newStatus,
cmsLabelPrefix,
} = body.params as UpdateUnpublishedEntryStatusParams;
const contentKey = generateContentKey(collection, slug);
const cmsBranch = branchFromContentKey(contentKey);
const description = statusToLabel(newStatus);
const description = statusToLabel(newStatus, cmsLabelPrefix || '');
await git.addConfig(branchDescription(cmsBranch), description);
res.json({ message: `${branch} description was updated to ${description}` });
break;

View File

@ -20,6 +20,7 @@ export type UnpublishedEntryParams = {
id?: string;
collection?: string;
slug?: string;
cmsLabelPrefix?: string;
};
export type UnpublishedEntryDataFileParams = {
@ -45,6 +46,7 @@ export type UpdateUnpublishedEntryStatusParams = {
collection: string;
slug: string;
newStatus: string;
cmsLabelPrefix?: string;
};
export type PublishUnpublishedEntryParams = {
@ -57,6 +59,7 @@ export type Entry = { slug: string; path: string; raw: string; newPath?: string
export type Asset = { path: string; content: string; encoding: 'base64' };
export type PersistEntryParams = {
cmsLabelPrefix?: string;
entry: Entry;
assets: Asset[];
options: {