Code Monkey home page Code Monkey logo

simple-commit-message's Introduction

simple-commit-message

Simple commit message wizard and validator; works with commitizen and pre-git

NPM

ci status semantic-release renovate-app badge manpm standard-style

Purpose

This module can:

  • parse simple commit message of the type type(scope): message
  • validate a given message if it fits the above simple format
  • guide the user with questions in order to form well formatted message

Valid commit messages

Simplest

major: breaking change in API
minor: this is a new feature
fix: an example fix message

Synonyms

For convenience you can use synonyms:

  • "break: ..." is synonym to "major: ..."
  • "feat: ..." is synonym to "minor: ..."
  • "patch: ..." is synonym to "fix: ..."

Scopes

You can optionally put a scope for the commit. For example if you added a new feature to the log feature of the module

feat(log): added colors!

Similarly, you can add scope to each type

major(scope): breaking change in API
minor(something): this is a new feature
fix(login): an example fix message

Skip release

If you just want to commit code, but not publish a new version from CI, you have several choices.

chore(tests): writing more tests
WIP: work in progress, not ready yet

note if you have local commit message validation as a Git hook, for example using pre-git skip the message check using git commit -n option.

Comments

The commit message can have lines that start with # character. These lines will be ignored.

Install and use

npm install --save simple-commit-message

Then use the following methods

var simple = require('simple-commit-message')
simple.name // "simple"
// returns an object with parsed info
const result = simple.parse(message)
/*
  {
    firstLine, // first message line
    type,      // "major", "feat", "fix", "chore" or undefined
    scope,     // inside of round braces
    subject    // message after :
*/
// returns true / false, prints errors to given log function or console.error
simple.validate(message, log)
// message wizard built on top of inquirer
simple.prompter(inquirer, cb)
// returns true if the commit message is public ("feat", etc)
simple.isPublic(
  simple.parse("feat(foo): add foo feature").type
) // true

See inquirer for details.

As plugin for semantic-release

This module can function as analyzeCommits plugin for semantic-release. Just add to the configuration file

{
  "analyzeCommits": "simple-commit-message"
}

Versions

  • 1 ... 3.x compatible with semantic-release v8
  • 4 compatible with semantic-release v11

Wizard

This module comes with included "bin" script that runs the wizard and asks you the questions. To use, add a script to your package, for example name it "commit"

{
    "scripts": {
        "commit": "simple-commit-message"
    }
}

Then instead of git commit use the command npm run commit and answer questions.

Related

Debugging

To see the commit processing logic locally, run

GH_TOKEN=aaa NPM_TOKEN=fff $(npm bin)/semantic-release pre || true && git checkout .npmrc

This will trigger local commit analysis without publishing.

To see debug log messages run this plugin with DEBUG=simple environment variable.

Small print

Author: Gleb Bahmutov © 2015

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2015 Gleb Bahmutov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

simple-commit-message's People

Contributors

bahmutov avatar rbardini avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

simple-commit-message's Issues

Vulnerable `debug` package

Hey there! 👋

I use this package in few places, and in one of them NSP reports that debug is older version that has ReDDoS vulnerability.

I am seeing that here is no debug as dependency but for some reason the NSP report mention that package, so.. don't know.

https://nodesecurity.io/orgs/tunnckocore-dev/projects/b8ccbfa6-282e-4360-aee5-1497dc059e6b/4

Probably some of your deps uses old debug? Don't know. How can we fix such issues? Probably to install debug in my package temporary?

simple-commit-message does not ignore comment line i.e. lines that start with '#'

We have a commit message template we add to projects so devs know the format of the commit message when writing their commit messages.

This commit message should not fail since '#' should be ignored:

# Type(<scope>): <subject>
chore: add git hooks for testing before pushing
# <body>
# <footer>

# Type should be one of the following:
# * feat (new feature)
# * fix (bug fix)
# * docs (changes to documentation)
# * style (formatting, missing semi colons, etc; no code change)
# * refactor (refactoring production code)
# * test (adding missing tests, refactoring tests; no production code change)
# * chore (updating grunt tasks etc; no production code change)
# Scope is just the scope of the change. Something like (admin) or (teacher).
# Subject should use impertivite tone and say what you did.
# The body should go into detail about changes made.
# The footer should contain any tool issue references or actions.

# For a full example of how to write a good commit message, check out
# https://github.com/sparkbox/how_to/tree/master/style/git

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch chore/reset_to_clean_src
# Changes to be committed:
#       modified:   package.json
#       modified:   yarn.lock

yet it does with this:

INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" ! was: # Type(<scope>): <subject>
chore: add git hooks for testing before pushing
# <body>
# <footer>

Very strange case (when bumping major) - problem with the body?

Can't think for some more meaningful title, sorry.

In last hour and two, i'm updating one of my repos, so i included semantic-release, simple-commit-message and github-post-release.

I pushed a fix type commit with Yes answer of Is this major breaking change? question.

2017-08-06-12 45 09_1280x1024_scrot
2017-08-06-12 45 05_1280x1024_scrot

And from the console

Line 1 will be cropped at 100 characters.
All other lines will be wrapped after 100 characters.

? Select the type of change that you're committing: fix:      A bug fix
? Denote the scope of this change (db, api, cli, etc.):
 refactor
? Write a short, imperative tense description of the change:
 require Node >= 7 (because koa-send@4); simplify
? Provide a longer description of the change:
 rewrite from scratch; fix bugs; update build process, npm scripts & boilerplate stuff
? List issues this commit resolves (fixes #2, closes #14):
 fixes #4, resolves #5
? Is this a major breaking change:
 Yes
? Should this be published under different tag?
  This will let users still install the current latest,
  but eary adapters can `npm install <name>@<tag>`
 latest
formed the following commit message
======================================================================================================================
fix(refactor): BREAKING CHANGE: require Node >= 7 (because koa-send@4); simplify

BREAKING CHANGE
rewrite from scratch; fix bugs; update build process, npm scripts & boilerplate stuff
TAG: latest

fixes #4, resolves #5
----------------------------------------------------------------------------------------------------------------------
? Do you want to commit? Yes

And as you see, semantic release published patch version, instead of major. Initially, it was absolutely shock for me, because in first look everything looks okey. But when you look more carefully you may see that the body's BREAKING CHANGE does not have color (:), which i believe caused semantic release to not understand really that this is major change.

For first time i'm bumping major with this package, instead of commitizen. Probably you too? Because if i remember correctly the important thing is that it must be BREAKING CHANGE: in the body. It's not important for semantic-release and (previously used by me) standard-version -- adding it to the title is just a stylistic thing for the users to see it more easy.

All this caused me a bit headache, because need to back to the prev commit, delete release/tag and unpublish that version from npm.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm dependency-check Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • fix(deps): update dependency debug to v4.3.5
  • fix(deps): update dependency word-wrap to v1.2.5
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update dependency ubuntu to v22
  • 🔐 Create all rate-limited PRs at once 🔐

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v2
  • bahmutov/npm-install v1
  • cycjimmy/semantic-release-action v2
  • ubuntu 20.04
npm
package.json
  • check-more-types 2.24.0
  • debug 4.3.4
  • ggit 2.4.12
  • hr 0.1.3
  • inquirer 6.5.2
  • inquirer-confirm 2.0.7
  • largest-semantic-change 1.1.0
  • lazy-ass 1.6.0
  • semver 5.7.1
  • word-wrap 1.2.3
  • ban-sensitive-files 1.9.18
  • dependency-check 3.4.1
  • deps-ok 1.4.1
  • git-issues 1.3.1
  • next-update-travis 1.7.1
  • pre-git 3.17.1
  • ramda 0.28.0
  • rocha 2.5.10
  • semantic-release 17.4.7
  • snap-shot 2.17.0
  • standard 12.0.1

  • Check this box to trigger a request for Renovate to run again on this repository

Seems like "Is this major breaking change?" does nothing (almost)

More specifically said, it does, but that adding of BREAKING CHANGE to body and title seems almost useless. Or at least not make sense to output that prompt every time for every kind of type.

Not to mention that the wizard (the prompts) doesn't have break / major and etc. It would be good to at least have major because it seems that semantic-release don't care about the wordings, but care only about major type, which is awful, but anyway.

Wizard seems to fail on node 8?

Hey! Great modules by you! :)

But i feel this fails from node 8

/usr/bin/env: ‘node --harmony’: No such file or directory

if manually edit the bin file and remove the --harmony flag it works. Strange.

Fix release

Currently getting the following error when trying to release a new version, see https://travis-ci.org/bahmutov/simple-commit-message

[13:32:09] [semantic-release] › ✖  Failed step "analyzeCommits" of plugin "simple-commit-message"
[13:32:09] [semantic-release] › ✖  An error occurred while running semantic-release: { TypeError: cb is not a function
    at analyzeCommits (/home/travis/build/bahmutov/simple-commit-message/node_modules/simple-commit-message/src/analyze-commits.js:34:3)
    at simple (eval at <anonymous> (/home/travis/build/bahmutov/simple-commit-message/node_modules/simple-commit-message/src/index.js:12:17), <anonymous>:2:25)
    at validator (/home/travis/build/bahmutov/simple-commit-message/node_modules/semantic-release/lib/plugins/normalize.js:34:30)
    at pReduce (/home/travis/build/bahmutov/simple-commit-message/node_modules/semantic-release/lib/plugins/pipeline.js:37:40)
    at Promise.all.then.value (/home/travis/build/bahmutov/simple-commit-message/node_modules/p-reduce/index.js:16:10)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7) pluginName: 'simple-commit-message' }
{ TypeError: cb is not a function
    at analyzeCommits (/home/travis/build/bahmutov/simple-commit-message/node_modules/simple-commit-message/src/analyze-commits.js:34:3)
    at simple (eval at <anonymous> (/home/travis/build/bahmutov/simple-commit-message/node_modules/simple-commit-message/src/index.js:12:17), <anonymous>:2:25)
    at validator (/home/travis/build/bahmutov/simple-commit-message/node_modules/semantic-release/lib/plugins/normalize.js:34:30)
    at pReduce (/home/travis/build/bahmutov/simple-commit-message/node_modules/semantic-release/lib/plugins/pipeline.js:37:40)
    at Promise.all.then.value (/home/travis/build/bahmutov/simple-commit-message/node_modules/p-reduce/index.js:16:10)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7) pluginName: 'simple-commit-message' }npm ERR! code ELIFECYCLE

Add "minor" type

It makes sense to allow feature versions as

minor(something): add something feature

Postinstall script interferes with semantic-release config

Hi, I had a really annoying debug session :/

If installing simple-commit-message with semantic-release and configuring semantic-release in a .releaserc file the post-install script of this plugin modifies the package.json file each time I am doing an npm install (which is every build, as it thinks there is no release configured).
The problem now is that the release config in the package.json takes precedence over the .releaserc config and in this way uses the standard configuration every build.

In order to solve this problem there are multiple ways:

  1. (My favorite) Remove the Postinstall script.

    • Just provide a configuration example in the README.md as every other plugin or package.
    • Adding a "release" option isn't that hard. (Maybe I can refactor the postinstall script into a cmd command, so it is still easy to install)
  2. Make it agnostic to .releaserc files.

    • Maybe there are some other config formats I or We couldn't think of, than we will start over again.
  3. At least provide a Environment variable to not execute the postinstall script.

Please choose one of the above actions and I will try my best to provide a PR for it. Thanks!

Support for Uppercased and all oTHeR-cased prefixes?

Hello! We're using the plugin in our projects and noticed that sometimes it's not triggering a release because the prefix is not lowercased. Did you consider supporting MAJOR:, Major: and MaJoR: kinds of cases? I think it should be a small thing to implement. I'm actually a bit surprised that nobody asked about that before (as far as I can see)... Please let me know about your opinion on this topic. Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.