Add customisation of git messages#192
Add customisation of git messages#192ryangittings wants to merge 9 commits intopagescms:developmentfrom
Conversation
|
| path: string, | ||
| contentBase64: string, | ||
| sha?: string, | ||
| message?: string |
There was a problem hiding this comment.
@ryangittings I don't think message is optional.
| import { configVersion, parseConfig, normalizeConfig } from "@/lib/config"; | ||
| import { stringify } from "@/lib/serialization"; | ||
| import { deepMap, getDefaultValue, generateZodSchema, getSchemaByName, sanitizeObject } from "@/lib/schema"; | ||
| import { deepMap, getDefaultValue, generateZodSchema, getSchemaByName, sanitizeObject, generateFromPattern } from "@/lib/schema"; |
There was a problem hiding this comment.
Use interpolate(): https://github.com/pages-cms/pages-cms/blob/development/lib/schema.ts#L211
| if (data.sha) { | ||
| message = `Update ${normalizedPath} (via Pages CMS)`; | ||
|
|
||
| if (config.object?.commit?.message?.update) { | ||
| message = generateFromPattern(config.object.commit.message.update, index); | ||
| } | ||
| } else { | ||
| message = `Create ${normalizedPath} (via Pages CMS)`; | ||
|
|
||
| if (config.object?.commit?.message?.create) { | ||
| message = generateFromPattern(config.object.commit.message.create, index); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Not a fan of that block. Probably cleaner to do something like:
message = data.sha
? config.object?.commit?.message?.update
? (...)
: (...)
: (...)
? (...)
: (...);
|
|
||
| let message = `File "${normalizedPath}" deleted successfully.`; | ||
|
|
||
| if (config.object?.commit?.message?.delete) { | ||
| const index = { | ||
| filename: getFileName(normalizedPath), | ||
| path: normalizedPath, | ||
| collection: { | ||
| name: name, | ||
| }, | ||
| user: { | ||
| name: user.githubName, | ||
| username: user.githubUsername, | ||
| email: user.githubEmail || user.email | ||
| } | ||
| } | ||
|
|
||
| message = generateFromPattern(config.object.commit.message.delete, index); | ||
| } |
There was a problem hiding this comment.
Use interpolate() and use the ternary operator.
components/entry/entry-editor.tsx
Outdated
|
|
||
| const router = useRouter(); | ||
|
|
||
| const { user } = useUser(); |
hunvreus
left a comment
There was a problem hiding this comment.
- We're only addressing collections here. We should do the same as we do in the backend routes and have a type + name (e.g. collection + posts, file + authors, media + images, settings, ...).
- We're missing renaming operations.
- We need to have logic to have settings that are defined both globally or at the collection/file/media level
| const normalizedPath = normalizePath(params.path); | ||
| let schema; | ||
|
|
||
| const index = { |
There was a problem hiding this comment.
Not a fan of that name "index". Maybe "messageData" is better?
There was a problem hiding this comment.
This is too focused on collections. We also have files, media and settings.
There was a problem hiding this comment.
You missed the rename route.
| } | ||
|
|
||
| const message = config?.object?.commit?.message?.delete | ||
| ? interpolate(config.object.commit.message.delete, index) |
There was a problem hiding this comment.
I think we should always try to get the closest settings for that before using the global settings. And that means also looking at file, media and settings.
Added new commit config:
And this allows users to customise the commit message. The follow bits of data are supported: