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
Prev Previous commit
Next Next commit
Re-order commitMessageFormatter() arguments.
  • Loading branch information
delucis committed May 14, 2018
commit 67dbe5379d19d790d1d5ff56edd7f6e6b984b105
10 changes: 5 additions & 5 deletions src/backends/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const commitMessageTemplates = Map({
deleteMedia: 'Delete “{{path}}”'
});

const commitMessageFormatter = (type, { slug, path, collection }, config = Map()) => {
const commitMessageFormatter = (type, config, { slug, path, collection }) => {
const templates = commitMessageTemplates.merge(config.getIn(['backend', 'commit_messages'], Map()));
const messageTemplate = templates.get(type);
return messageTemplate.replace(/\{\{([^\}]+)\}\}/g, (_, variable) => {
Expand Down Expand Up @@ -292,7 +292,7 @@ class Backend {
};
}

const commitMessage = commitMessageFormatter(newEntry ? 'create' : 'update', { collection, slug: entryObj.slug, path: entryObj.path }, config);
const commitMessage = commitMessageFormatter(newEntry ? 'create' : 'update', config, { collection, slug: entryObj.slug, path: entryObj.path });

const mode = config.get("publish_mode");

Expand All @@ -311,7 +311,7 @@ class Backend {

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.

const options = {
commitMessage: commitMessageFormatter('uploadMedia', { path: file.path }, config),
commitMessage: commitMessageFormatter('uploadMedia', config, { path: file.path }),
};
return this.implementation.persistMedia(file, options);
}
Expand All @@ -323,12 +323,12 @@ class Backend {
throw (new Error("Not allowed to delete entries in this collection"));
}

const commitMessage = commitMessageFormatter('delete', { collection, slug, path }, config);
const commitMessage = commitMessageFormatter('delete', config, { collection, slug, path });
return this.implementation.deleteFile(path, commitMessage);
}

deleteMedia(config, path) {
const commitMessage = commitMessageFormatter('deleteMedia', { path }, config);
const commitMessage = commitMessageFormatter('deleteMedia', config, { path });
return this.implementation.deleteFile(path, commitMessage);
}

Expand Down