jzaefferer / commitplease Goto Github PK
View Code? Open in Web Editor NEWValidates strings as commit messages
Validates strings as commit messages
If user uses --verbose
with git commit
command, commitplease
will try to validate added/removed lines
For example, to require subject lines consisting of semver level, one or more repository-specific components (separated by commas or comma-space pairs and ending with a colon), and a non-empty sentence-case message, all of which must be separated by spaces:
"commitplease": {
// Braces like http://tools.ietf.org/html/rfc6570 URI Template expressions
// Expression syntax like https://tools.ietf.org/html/rfc5234#section-3.6 ABNF repetition
// …with introduction of optional separator definition in ECMAScript RegExp syntax
"subjectPattern": "{semver-level} {1* ,[\\x20]? components}: {message}",
// Variables are usually arrays of acceptable values
"semver-level": [ "major", "minor", "patch" ],
"components": [ "Build", "Test", "Core", "Legacy" ],
// Variables can also be ECMAScript regular expressions in ESTree format
// https://github.com/estree/estree/blob/master/spec.md#regexpliteral
"message": {
"regex": { "pattern": "^[^a-z\\s].*" },
// …plus an optional human-readable description
"description": "non-empty and sentence case (initial letter capitalized)"
}
}
Another possibility is dropping the RegExp/variable expansion options in favor of pure RFC 5234 + RFC 7405 ABNF.
See this commit as reference
jQuery Mobile has a fixedToolbar component but the message FixedToolbar: ..... fails because fixed is not followed by a ticket ref.
#26 suggests allowing "fixup!" as a prefix to whitelist, but that's very specifc to the --fixup
flag and will reuse the existing commit message. In our current PR workflows, we use something like "[fix]: description of the fixup".
Could also whitelist /\[[^\]]+\]:/
(anything in square brackets), along with "fixup!" and "squash!".
There were some concerns on the Angular PRs that we should address in our readme.
jQuery uses
Component: Short Description
User should be able to configure it so that something like
Short Description: Component
can be also validated.
IMO this is not too different from the current implementation so it should be easy. I can put together a PR.
If you agree this is a good idea repos like
https://github.com/jshint/jshint/commits/master
https://github.com/angular/angular.js/commits/master
can use this module.
Terminal output ( {pathToProject } is in place of actual path ) when running npm install (node v5.1.0
)
[email protected] install {pathToProject}/node_modules/commitplease
node install
Detected an existing git commit-msg hook
Remove it and install this package again to install commitplease properly
Mark: git status
fatal: This operation must be run in a work tree
Due to {pathToProject}/.git/hooks/commit-msg -> #!/bin/evn node
Seems to be since homebrew doesn't use /usr/bin
for node or even a symlink you have to replace:
!/bin/evn node
with
!/usr/local/bin/node
The issue is installing on a fresh machine or having to reclone said project using this npm. Is there any chance of updating this so the CLI doesn't break with homebrew's install of node? It also seems in El Capitan you can't force symlinks in the /usr/bin directory, well maybe if you disabled root user but rather not go down that road.
Example, here's the ln
command and output when trying to force a symlink to that directory in El Cap:
sudo ln -sf /usr/local/bin/node /usr/bin/node
ln: /usr/bin/node: Operation not permitted
Thanks in advance.
I've changed the defaults to match the jQuery commit message rules, should get that into the readme, along with a link to that guide. Until someone asks for different rules, that should be enough.
Since I usually use husky
or shared-git-hooks
already, it would be cool if commitplease
was a binary or simple a lib that I can call from my own script.
git commit flags --fixup
and --squash
are great in rebase-centric workflows, especially in combination with git config rebase.autosquash
enabled. Unfortunately, commitplease component validation will abort these commits.
The solution would be to skip validation on commits that start with "fixup!" or "squash!". These are temporary commits that will get merged into others on the next rebase, so it makes no sense to perform validation on them at this moment.
Project needs to use npm for installing dependencies, doesn't really matter what it does otherwise.
JSHint has something vaguely similar to Angular: https://github.com/jshint/jshint/commits/master
ESLint seems pretty similar to jQuery: https://github.com/eslint/eslint/commits/master
etc. pp.
Need to figure out how to pass valid modules.
Rather than just have commitplease require the existence of something that looks like a component, projects should define valid components for it and require a match.
e.g.:
"commitplease": {
"component": [ "Build", "Test", "Core", "Legacy" ]
}
Find a way to pass error message to git GUI applications like TortoiseGit or SourceTree.
Currently the commit fails in TortoiseGit but no specific error message is shown:
Invalid commit message, please fix the following issues:
git did not exit cleanly (exit code 1) (327 ms @ 05.02.2014 18:46:17)
Would be nice to have a possibility to do so.
There's too many useless double quotes here:
- First line must be <type>"("<scope>"): "<subject>
Need an opening parethesis "("
Should look more like this:
- First line must be <type>(<scope>): <subject>
Need an opening parenthesis: (
(also fix the typo in parethesis -> parenthesis)
The default merge message - e.g. "Merge branch 'one' into two"
- is rejected by commitplease with the following message:
"- First line (subject) must indicate the component"
It seems like commitplease should probably be ok with these messages.
Eg: Auto capitalise the first letter of the Component and Short Description
Remove the dot at the end of the Component and Short Description
Fix some common typos?
Remove empty lines?
What do you think?
Use nodemon or similar tools to add a npm run test-watch
script that reruns tests as source or test files are updated.
The jQuery ticket reference guidelines allow the use of Ref
to reference a ticket without closing it. These should be validated as well, since it will impact the efficacy of #33.
Currently, npm install -g commitpllease
does not work.
On the one hand, commitplease
is supposed to be a locally installed devDependency
that gets its configuration from package-local package.json
and .npmrc
as well as it expects to be installed into a .git
directory.
On the other hand, tools like overcommit
would prefer if an npm package supported global install.
So, figure out the exact reasons why a global commitplease install fails and decide if it makes sense to support global install at all. If it does, update install_command
for overcommit
in sds/overcommit#405
@rxaviers wants to use this module without the git hook. Separating the validation from the hook, into a separate projects/module is one way. I wonder if a flag in the parent projects package.json
could be used instead.
Use babel or bublé (along with rollup?) to allow using ES2015 for development, but publish ES5 code to npm.
There is a problem with angular continuous integration. My suspicion is that the repository is created in between the calls to fs.existsSync
and fs.mkdirSync
, leading to failure. So, I am fixing our install.js
script to "ask forgiveness not permission" like so:
function xmkdirSync (path, mode) {
try {
fs.mkdirSync(path, mode)
} catch (err) {
if (/EPERM/.test(err.message)) {
console.error('Failed to create: ' + git)
console.error('Make sure you have the necessary permissions')
} else if (/EEXIST/.test(err.message)) {
// do nothing
} else {
throw err
}
}
}
Is that ok? Is there perhaps some other issue I am missing?
While looking for tools to generate changelogs, I've come across these two tools, that are quite similar to commitplease:
Neither automatically installs the commit-msg hook, the latter project recommends https://www.npmjs.com/package/ghooks for that.
If nothing else, we could mention these tools as alternatives. Maybe the authors would agree to deprecate their packages in favor of commitplease, since commitplease supports more presets, configuration options and automatically installs the hook.
I'd like to see more adoption of this project. For that it should have presents and options to support more commit message style guides. The one I'm aware of is the angular style guide for commit message. There are probably more.
I hope more people are interested in extending this project to support the style of commit messages. I've already solved the git commit-msg hook integration.
This is valid:
Methods: Fix tests for email method. Follow-up to dd162ae
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
Got an informal error report where committing with gitx always failed, and the output from commitplease doesn't show up
Project seems to be for osx-only: http://gitx.frim.nl/
@all3fox can you test this?
Jira uses an issue format of [A-Z]{3}-[0-9]+
I have received this error:
The context was:
Git opens vim to modify the message for the rewarding commit, I modified message, I think it was a correct commit message and then commitplease crashed with the above error. After that I continued the rebase and everything went well.
@fnagel has tested on Windows 7, the module isn't working as expected. It looks like creation of the symlink fails, but it doesn't log any errors.
Node.js documents support for symlinks on Windows. Should start by verifying that. Might be an issue with the relative path.
From qunitjs/qunit#679 (comment), where @mislav wrote:
it looks like every user needs to configure this locally.
Just like hooks need to be configured locally per-repo as well. If you could set up git hooks, then you could also set up the template.
Here's an alternative to a template: a git hook that prepares the commit message before it opens in your text editor by listing the existing components:
#!/bin/bash
# .git/hooks/prepare-commit-msg
set -e
file="$1"
mode="$2"
list_components() {
git log --no-merges --format='%s' | grep : | cut -d: -f1 | \
sort | uniq -c | sort -rn | head -10 | sed 's/^.\{1,\}[[:digit:]] //'
}
if [ -z "$mode" ]; then
c="$(git config core.commentchar || echo '#')"
{ echo "$c Please prefix the subject line with \"Component:\""
echo -n "$c Example components: "
list_components | xargs | sed 's/ /, /g'
cat "$file"
} > "${file}.new"
mv "${file}.new" "$file"
fi
The effect it has on the default message when I git commit
:
# Please prefix the subject line with "Component:"
# Example components: Build, qunit, Core, Tests, Test, QUnit, Grunt, Assert, Reporter, Readme
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
...
I like that idea, since it'll help providing a correct commit message on the first attempt.
The example components are somewhat questionable, as existing jQuery repositories often have common components that are actually bad examples. This could be replaced by a fixed list, as suggested in #23.
Valid:
Docs: Fix a typo
Closes gh-155
Invalid:
Docs: Fix a typo
Closes: gh-155
Since several projects use #
to indicate non-Github bug trackers, it would be handy to have the commit checker look for those references and abort the commit if they're found. This should be a non-default option since most Github projects do use #
to refer to tickets and PRs.
I know that @rxaviers doesn't much like the commit-msg hook, instead prefers validation as part of npm test
(locally or via CI). For Globalize, he's set up a combination of nohook: true
and a grunt plugin that validates a certain range of commits: https://github.com/jquery/globalize/blob/master/package.json#L76
The issues with that approach: You need the extra code to run the validation on-demand - this could be built into commitplease instead. And adding nohook: true
to package.json makes this a project-wide setting. It would be better to be able to override this per install, so he could create .npmrc
with [...]commitplease.nohook:true
, while everyone else on the project uses the hook.
That would also be a decent answer for parts of #67
As the title states I am using a project as a submodule which uses commitplease.
The basic structure is that I have a master project which has several Docker containers. The master project pulls several submodules including one which has commitplease as a dev dependency. When the container which has commitplease in tries to do an npm install
as build of the build container phase, the installation fails, I believe because submodules do not have a local .git folder, it is actually a reference to the submodule .git folder in the parent project.
The only workaround I have so far found is to remove commitplease as a dependency after updating the submodules and before building but this isn't an ideal situation.
Any help or guidance you could provide would be much appreciated, I have posted the nam error below for reference.
Thanks!
fatal: Not a git repository: ../.git/modules/customer_management_system
/root/cms/node_modules/commitplease/lib/sanitize.js:13
throw error
^
Error: Command failed: git config --get core.commentchar
fatal: Not a git repository: ../.git/modules/customer_management_system
at checkExecSyncError (child_process.js:483:13)
at Object.execSync (child_process.js:523:13)
at Object.<anonymous> (/root/cms/node_modules/commitplease/lib/sanitize.js:6:21)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
npm info lifecycle [email protected]~install: Failed to exec install script
npm WARN [email protected] No repository field.
npm ERR! Linux 4.4.15-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v6.4.0
npm ERR! nam v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node install'.
npm ERR! Make sure you have the latest version of node.js and nam installed.
npm ERR! If you do, this is most likely a problem with the commit please package
npm ERR! not with nam itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs commit please
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls commit please
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /root/cms/npm-debug.log
See https://npmjs.org/doc/misc/npm-scripts.html#NOTE-INSTALL-SCRIPTS-ARE-AN-ANTIPATTERN. It seems creating the *.gyp
file is preferred.
TBH I don't understand why gyp files are preferred so I'm leaving this issue as a place to discuss this.
http://contribute.jquery.org/commits-and-pull-requests/#commit-guidelines has an example -
Component: Short Description
I wonder if we should check for register of the first word, in this case, "Short"?
Should it be in upper-case though? Linguistically speaking, it should be a lower-case letter.
See https://github.com/brigade/overcommit
Sounds similar to husky.
Could we get commitplease into Python, Ruby, Go etc. projects? Could either do native implementations (porting the whole thing to Python) or just figuring out a way to run the existing code, but install it as a Python package (pip?). Nodejs is a reasonable system dependency, but not every project uses npm.
fwiw, I noticed that the regexes here could be simplified a bit
https://github.com/jzaefferer/commitplease/blob/master/lib/validate.js#L48
I noticed it mainly because of the '(sd)' vs '[sd]' semi-bug on "fix", but it doesn't really matter because they're optional -- as long as the line starts with fixSOMETHING it'll detect it and complain if it doesn't include a ticket ref. So the (e[sd]) is extra on most of those.
/^(clos[ei]|fix|resolve)/i
should do what you want. ([ei] incase someone says Closing #nnnnn)
Invalid commit message, please fix the following issues:
Commit message was:
Autocomplete: Do not set value on multi-line input
Fixes issue where contenteditable text was getting overwritten when
wrapping past the bottom or top of the autocomplete menu.
Fixes #9771
Closes gh-1184
In git, the commentchar can be configured. git config core.commentchar
returns the custom character or nothing, where nothing means the default #
character is used.
This requires sync exec, which I currently don't want to deal with (sync-exec module is a rather big dependency). Node 0.12 should ship with execSync, making this a lot easier.
Its also not something anyone has actually reported as a problem. When the first person actually runs into this issue, I can still address it.
Sometimes someone lands a PR with a bad name or email. It would be great to have an option to require authors in the format "Name1 Name2 [email protected]" with some level of validation. There are (rare) cases where a single name is allowed but perhaps that could be elided using two spaces or something. I don't think we ever want to have a bad email.
Since jscs is merging into ESLint, let's switch to ESLint, and while at it, switch to standard to stop maintaining linter configs.
The project which I'm trying to contribute to has commitplease enabled with default settings. I've tried git commit -v
but apparently failed to provide a component name. The resulting error message from commitplease dumped the entire previous contents of .git/COMMIT_EDITMSG
, which includes git's own comments and diff and floods my terminal output. Example:
$ git commit -v
Invalid commit message, please fix the following issues:
- First line (subject) must indicate the component
Commit message was:
{MY SUBJECT LINE}
{MY COMMIT MESSAGE BODY}
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
{100s OF LINES OF DIFF FOLLOWS}
What I expected: only my subject line and message to be outputted (the content that would actually get used as the commit message), and git's own comments and diff stripped away.
Now that I think of it, if the error is really just about the subject line, then the error output could just list the subject line I provided (since that's what needs fixing), and not even the commit body.
Related: #19
npm version patch
should work ;-)
Currently doesn't match the actual regex in use, see also 557d037#commitcomment-5062296
Hi Jörn,
On invalid commit messages, the commit is aborted by the hook. For me, it would be of more value if it didn't abort it. But, instead give me a warn message saying:
"Hey! The commit is invalid for reason. Please, git commit --amend
and fix it!"
Amending is faster for me... But, I don't know if this is doable.
Thanks!
PS: this is more of a question than a bug.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.