Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable user-configured commit message templates #1359

Merged
merged 10 commits into from
May 23, 2018
Merged

Enable user-configured commit message templates #1359

merged 10 commits into from
May 23, 2018

Conversation

delucis
Copy link
Contributor

@delucis delucis commented May 14, 2018

Summary

Closes #557

Exposes a backend.commit_messages option, which allows users to configure the commit messages generated by Netlify CMS using string templates. Default behaviour remains unchanged and is equivalent to the following in config.yml:

backend:
    commit_messages:
        create: Create {{collection}} “{{slug}}”
        update: Update {{collection}} “{{slug}}”
        delete: Delete {{collection}} “{{slug}}”
        uploadMedia: Upload “{{path}}”
        deleteMedia: Delete “{{path}}”

Why?

Users may want Netlify CMS commits to be formatted in a specific way. For example, they might want to adhere to a commit message convention they are already using. More discussion can be found in #557.

To-do

  • Write documentation. Should this be under Beta Features?

Considerations/Notes

  • Previously, persistEntry and deleteEntry were passed a config object (in actions/entries), while persistMedia and deleteMedia were not (in actions/mediaLibrary). To allow configuration of commit messages for media uploading and deletion, I changed
    persistMedia and deleteMedia to also receive a config object. For consistency with the entry methods, this is passed as their first argument. As far as I can tell, this only impacted actions/mediaLibrary, which I updated accordingly (3e360d1).
    Discussed below

  • The variables available are pretty minimal and inconsistent based on what is available in each commit method at the moment. For entry commits, slug, path, and collection are available, but for media commits only the path variable is available. It would be nice if this were all standardised somehow in the future with some kind of commit object holding more information.

  • Netlify CMS also creates commit messages when merging and force merging pull requests in its GitHub API implementation. In theory, these messages should also be configurable, but perhaps that can wait?

  • Should the config option be elsewhere? @Benaiah mentioned a future backend.settings namespace for backend-specific options.

  • I duplicated the string template logic from the slugFormatter. Given that this curly braces syntax is now in use in at least two places, perhaps the template-processing logic should be abstracted?

Test plan

Description for the changelog

Enable user-configured commit message templates

A picture of a cute animal (not mandatory but encouraged)

A messenger pigeon 🐦

A messenger pigeon

@verythorough
Copy link
Contributor

verythorough commented May 14, 2018

Deploy preview for netlify-cms-www ready!

Built with commit f45cec5

https://deploy-preview-1359--netlify-cms-www.netlify.com

@verythorough
Copy link
Contributor

verythorough commented May 14, 2018

Deploy preview for cms-demo ready!

Built with commit f45cec5

https://deploy-preview-1359--cms-demo.netlify.com

Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

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

Great PR, thanks for putting this together! Just one small change request. Agreed that documenting this under beta features makes sense for now.

@@ -283,9 +309,9 @@ class Backend {
.then(() => entryObj.slug);
}

persistMedia(file) {
persistMedia(config, file) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Switch the argument order for persistMedia and deleteMedia so the config is the last argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will do. One note: I decided to pass config as the first argument because that is what persistEntry and deleteEntry currently do. Not sure if inconsistency between entry and media actions is a concern.

Copy link
Contributor

Choose a reason for hiding this comment

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

I should have asked why you did that - you're right, consistency first. Thanks for pointing that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, great. I’ll work on some documentation now.

@delucis
Copy link
Contributor Author

delucis commented May 15, 2018

@erquhart Ok, tried to document this. Would appreciate a few people reading through it, because it’s a little tricky to explain all the parts of this option.

@verythorough Do you have any thoughts?

Copy link
Contributor

@verythorough verythorough left a comment

Choose a reason for hiding this comment

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

Sorry for the delay! I love how thorough these docs are. :)

I made one comment about the initial heading & description. Otherwise, looks good to me!


## Customizing Commit Messages
You can customize the commit messages generated by Netlify CMS with templates in the `backend` option of your `config.yml`.

Copy link
Contributor

Choose a reason for hiding this comment

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

To me, "customize commit messages" implies editing individual messages, rather than the templates that generate them. I think it might be clearer if the above two lines become something more like:

Commit Message Templates

You can customize the templates used by Netlify CMS to generate commit messages by setting the commit_messages option under backend in your config.yml.

@erquhart erquhart merged commit 8ab5ca5 into decaporg:master May 23, 2018
erquhart pushed a commit to erquhart/netlify-cms that referenced this pull request May 23, 2018
@delucis delucis deleted the feat/commit-message-templates branch May 23, 2018 21:15
@delucis
Copy link
Contributor Author

delucis commented May 23, 2018

Awesome! 😄

brianlmacdonald pushed a commit to brianlmacdonald/netlify-cms that referenced this pull request May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants