Skip to content

Add customisation of git messages#192

Closed
ryangittings wants to merge 9 commits intopagescms:developmentfrom
gittingsstudio:feature/customisable-git-messages
Closed

Add customisation of git messages#192
ryangittings wants to merge 9 commits intopagescms:developmentfrom
gittingsstudio:feature/customisable-git-messages

Conversation

@ryangittings
Copy link
Copy Markdown
Contributor

Added new commit config:

commit:
    message:
        create: "{filename} was created by {user.email}"
        update: "{filename} was updated by {user.email}"
        delete: "{filename} was deleted by {user.email}"

And this allows users to customise the commit message. The follow bits of data are supported:

{
  filename: 'index.md',
  path: 'src/index.md',
  collection: { name: 'pages' },
  user: {
    name: 'Ryan Gittings',
    username: 'ryangittings',
    email: 'ryan@gittings.studio'
  }
}

@ryangittings ryangittings requested a review from hunvreus March 11, 2025 15:47
@ryangittings ryangittings linked an issue Mar 11, 2025 that may be closed by this pull request
@ryangittings ryangittings changed the title Draft functionality Add customisation of git messages Mar 11, 2025
@hunvreus
Copy link
Copy Markdown
Contributor

  • I'm adding a new helper function (interpolate) in lib/schema.ts. I'm probably gonna rewrite part of this to account for it.
  • I think it's an opportunity to add global settings (which requires us to review how we "compile" the settings object in database to account for merge global/local settings)
  • One thing we could add is also an option for the user to override the message at submit

@ryangittings ryangittings changed the base branch from main to development March 16, 2025 09:29
path: string,
contentBase64: string,
sha?: string,
message?: string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +56 to +69
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);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of that block. Probably cleaner to do something like:

message = data.sha
    ? config.object?.commit?.message?.update
        ? (...)
        : (...)
    : (...)
        ? (...)
        : (...);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment on lines +303 to +321

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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use interpolate() and use the ternary operator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


const router = useRouter();

const { user } = useUser();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add user?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

@ryangittings ryangittings requested a review from hunvreus March 17, 2025 09:58
Copy link
Copy Markdown
Contributor

@hunvreus hunvreus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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 = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of that name "index". Maybe "messageData" is better?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too focused on collections. We also have files, media and settings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed the rename route.

}

const message = config?.object?.commit?.message?.delete
? interpolate(config.object.commit.message.delete, index)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ryangittings ryangittings deleted the feature/customisable-git-messages branch March 20, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add customizable git messages

2 participants