GithubHelp home page GithubHelp logo

jpeer264 / node-semantic-git-commit-cli Goto Github PK

View Code? Open in Web Editor NEW
143.0 9.0 9.0 2.24 MB

A CLI for semantic git commits

Home Page: https://www.npmjs.com/package/semantic-git-commit-cli

License: MIT License

JavaScript 70.81% TypeScript 28.96% Shell 0.23%
semantic commit git cli emoji nodejs

node-semantic-git-commit-cli's Introduction

semantic-git-commit-cli

Backers on Open Collective Sponsors on Open Collective Build Status Build status Coverage Status

A CLI to keep semantic git commits. With emoji support 😄 👍

Why?

Many projects got different git commit rules. It is hard to remember them all. Usually you start with git commit -m ", and then? You have to think about the projects commit guidelines.

sgc will take care of the commit guidelines, so you can focus on the more important stuff: code

Installation

$ npm i -g semantic-git-commit-cli

or

$ yarn global add semantic-git-commit-cli

Usage

Forget the times when you used git commit -m "...", now just type:

$ sgc

or if you already have an alias for sgc, use following instead:

$ semantic-git-commit

Usage with parameters

Note: if any block is added it will get skipped in the questions. If there are still some questions open they will still be asked

Available parameters:

  • m | message: Add and skip the message block
  • t | type: Add and skip the type block (this has to be defined in the types as argKey)
  • s | scope: Add and skip the scope block

To skip some questions you can add parameters:

Following:

$ sgc -t feat -m some new features

Will generate: Feat: some new features

--

Following:

$ sgc -t feat -s myScope -m some new features

Will generate: Feat(myScope): some new features

Usage with semantic-release

Configure sgc for the following semantic-release options: analyzeCommits and generateNotes

First step, install the following plugins with

$ npm install --save-dev sr-commit-analyzer sr-release-notes-generator conventional-changelog-eslint

or

$ yarn add -D sr-commit-analyzer sr-release-notes-generator conventional-changelog-eslint

Then, create a release.config.js file in a config folder in the root folder of your project:

/* eslint-disable no-useless-escape */
module.exports = {
  analyzeCommits: {
    preset: 'eslint',
    releaseRules: './config/release-rules.js', // optional, only if you want to set up new/modified release rules inside another file
    parserOpts: { // optional, only you want to have emoji commit support
      headerPattern: /^(?::([\w-]*):)?\s*(\w*):\s*(.*)$/,
      headerCorrespondence: [
        'emoji',
        'tag',
        'message',
      ],
    },
  },
  generateNotes: {
    preset: 'eslint',
    parserOpts: { // optional, only you want to have emoji commit support
      headerPattern: /^(?::([\w-]*):)?\s*(\w*):\s*(.*)$/,
      headerCorrespondence: [
        'emoji',
        'tag',
        'message',
      ],
    },
  },
};

Then, update the semantic-release script to your package.json to this :

"scripts": {
    "semantic-release": "semantic-release -e ./config/release.config.js",
}

Commands

check

This will check all commits and will fail if your commits do not meet the defined config.

Flags

  • start: A commit SHA to start, in case you started using sgc later of your development
$ sgc check --start 84a1abd

Config

Just create a .sgcrc in your project root or you can add everything in your package.json with the value sgc

You can even create a global config. Just go to your users home and create a .sgcrc. The global config will be triggered if no project configurations are present.

The order and namings of the commit (this can vary with different settings):

<type>(<scope>)<delimiter> <message>

<body>

Options:

body

Type: boolean

Default: true

Asks if more info (body) should be added. This will open your default editor.

Example:

{
  "body": false
}

scope

Type: boolean

Default: false

Asks for the scope in parentheses of the commit.

Example:

{
  "scope": true
}

emoji

Type: boolean

Default: false

A boolean to enable emoji at the beginning of a commit message

Example:

{
  "emoji": true
}

delimiter

Type: string

Default: :

A string which is the delimiter between the type and the message.

Example:

{
  "delimiter": ":"
}

or type specific delimiters, which will overwrite the global one:

{
  "delimiter": ":",
  "types": [
    {
      "type": "Feat",
      "delimiter": " -"
    }, // will generate "Feat - message"
    {
      "type": "Fix",
    } // will generate "Fix: message"
  ]
}

lowercaseTypes

Type: boolean

Default: false

A boolean to lowercase types.

Example:

{
  "lowercaseTypes": true
}

initialCommit

Type: object

Default:

{
  "initialCommit": {
    "isEnabled": true,
    "emoji": ":tada:",
    "message": "Initial commit"
  }
}

Keys:

  • isEnabled - Whether an explicit initial commit should be used for the very first commit
  • emoji - An emoji which will be appended at the beginning of the commit (Emoji Cheat Sheet)
  • message - The commit message for the very first commit

types

Types will define your git commits. If types is not set in your own .sgcrc, the types of the global .sgcrc

Notice: If the type is false it will let you to manually add the type. This is usefull especially if you have a prefix named SGC- to reference these as a ticket number for your ticket tool

Keys

  • type (string or false) - This will be your commit convention and will be your start of your commit - e.g.: Feat:
  • prefix (optional) - This option is just valid, if type is false
  • description (optional) - The description to explain what your type is about
  • emoji (optional) - An emoji which will be appended at the beginning of the commit (Emoji Cheat Sheet)
  • argKeys | Array (optional) - Keys which will be accessed through the -t parameter

The .sgcrc:

{
    "types": [
      {
        "emoji": ":sparkles:",
        "type": "Feat:",
        "description": "Any description to describe the type",
        "argKeys": ["f", "feat", "feature"]
      }
    ]
}

or the package.json:

{
    "name": "Your application name",
    "version": "1.0.0",
    "sgc": {
        "types": [
            {
              "emoji": ":sparkles:",
              "type": "Feat:",
              "description": "Any description to describe the type",
              "argKeys": ["f", "feat", "feature"]
            }
        ]
    }
}

addScopeSpace

Type: boolean

Default: true

This rule just affects the commit message if scope is set to true

If set to false there will be no space between <type> and (<scope>)

Example:

{
  "addScopeSpace": false
}

rules

Available rules:

maxChar

Type: number

Default: 72

If a number is set, it will not allow to commit messages more than the given number. If it is set to -1 the rule is deactivated

Example:

{
  "rules": {
    "maxChar": -1
  }
}

minChar

Type: number

Default: 10

If a number is set, it will not allow to commit messages less than the given number. If it is set to -1 the rule is deactivated

Example:

{
  "rules": {
    "minChar": -1
  }
}

endWithDot

Type: boolean

Default: true

If it is set to false, it will not allow to commit messages with a dot at the

Example:

{
  "rules": {
    "endWithDot": false
  }
}

node-semantic-git-commit-cli's People

Contributors

aichbauer avatar dani-sc avatar dependabot[bot] avatar jpeer264 avatar jy95 avatar martinmuzatko avatar omar10594 avatar seniru avatar stephanschubert 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-semantic-git-commit-cli's Issues

Access Denied after updating to 3.2.0

Today i tried updating the sgc to version 3.2.0
after updating, i have a access denied issues.

─$ sgc -v zsh: permission denied: sgc

after downgrading to version 3.1.1, it's working again.

my stack is
-mac
-zsh
-node v10.15.1
-npm v6.9.0

anyone experince same issue ?

With Parameters "sgc -t feat" is broken

Hello,
i tried to run the sgc with -t block, but it's spitting out errors
(node:6951) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'includes' of undefined at Object.when (/Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/dest/questions.js:86:46) at /Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/run-async/index.js:49:25 at new Promise (<anonymous>) at /Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/run-async/index.js:26:19 at /Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/inquirer/lib/ui/prompt.js:130:32 at Observable._subscribe (/Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/rxjs/internal/observable/defer.js:10:21) at Observable._trySubscribe (/Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/rxjs/internal/Observable.js:44:25) at Observable.subscribe (/Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/rxjs/internal/Observable.js:30:22) at Object.subscribeToResult (/Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/rxjs/internal/util/subscribeToResult.js:12:23) at MergeMapSubscriber._innerSub (/Users/ignasius/.nvm/versions/node/v12.18.2/lib/node_modules/semantic-git-commit-cli/node_modules/rxjs/internal/operators/mergeMap.js:82:53) (node:6951) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:6951) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

i'm using
nvm v0.35.3
node v12.18.2
npm v6.14.5

thanks.

Add tests

@dani-sc @rudolfsonjunior

we need more tests, especially for lib/sgcPrompt.js. Anybody experience in testing inquirer prompts?

Commit improvements

  • Shorten commit descriptions
  • validate limit commit message (maybe 50/72 chars)

Drop Node v4 support

I see more and more libraries who dropping v4 support. Also if we update inquirer we are kinda forced to drop v4 support.

cc @aichbauer

EDIT:
Also we are shortly before our sgc@3 release. So this might be also the right time.

Readme: Installation with Yarn

Should be

yarn global add semantic-git-commit-cli

If you use add before global, you will get the global dependency installed on the current project (and this dependency as well).
screen shot 2017-09-19 at 11 39 41 am

sgc find config

With command sgc which-config it should show where the applied config is located.

Option to manually type the prefix

We got prefixes like fix feat etc. But sometime you need to prefix your issue based on a ticket, e.g. SGC-14. Maybe we can add the option, if there are no types, then we can type them in manually as input prompt.

Allow multiple scopes

Scope type: 'single' | 'multiple' . Default: 'single'.

Multiple scope format: Feat(scope1, scope2)

Use rawlist for "type" prompt

This would enable a keyboard shortcut to jump to a type (screenshot below). What are the maintainers' thoughts on this? Maybe it could be behind a config option? Happy to put in a PR if this idea has merit.

image

Edit: I want to add - thanks for this great tool, I was thinking of creating something like the rebase-editor but for commits, but you beat me to it!

Style: Using the same writing style for `.sgcrc`

Currently we have two different writing styles in our .sgcrc

  "lowercaseTypes": false,
  "initial-commit": {
    "isEnabled": true,
    "emoji": ":tada:",
    "message": "Initial commit"
  },

As you see we use camelcase (e.g. lowercaseTypes) and separating them with a - (e.g. initial-commit).

Maybe we should use camelcase for everything?

Adding body starts out with undefined and loses title line

To reproduce:

  • choose the commit type
  • type short commit message
  • choose y for whether to add a body to the commit message

Expected:

My editor comes up with the first line filled out with what I'd already typed, and lets me type in the body I want.

Actual behavior:

Editor comes up with undefined as the content. I thought the title line was added behind the scenes, but after typing the body and saving, only the body was present in the commit message, not the type or title message.

Version:

v3.2.1

Option for alternative config path

Right now, the only locations to provide configuration is at path.join(cwd, '.sgcrc'), path.join(homedir, '.sgcrc') (user's machine home directory), or inside package.json in a sgc property.
According to the getConfig method, we should be able to pass in a alternative path. However it doesn't seem to be used at all when called from the cli module.

It be nice to be able to be able to pass in the alternative path so the end user can choose where to place their config file.

Rename prefix to type

@rudolfsonjunior how about changing the name in the config prefix to type:

from:

{
  "emoji": "",
  "prefix": "Look on this line",
  "description": ""
}

to:

{
  "emoji": "",
  "type": "Look on this line",
  "description": ""
}

Test global .sgcrc not removed

The test for the global .sgcrcdoes not remove the global .rgcrcafter the test. so it always runs into the global .sgcrc and never touches the .sgcrc_default.

So the tests for the .sgcrc_default are not passing anymore

Turn `.sgcrc` from JSON into JS?

Babel, PostCSS and many other tools use sth like babel.config.js to support dynamic configurations. It would be possible to import/determine the valid types depending on the environment, for example.

Parameters

Is there any way to pass scope and message as arguments?

Custom Rules

What you think about custom rules?

By now rules are just enabled or disabled, but what if somebody wants his own rule? I though about following:

{ // .sgcrc
  ...
  "rules": {
    "max-char": 72,
    "custom": [
      {
        "forbidTrailingDot": (input, config) => ({
          message: () => '',
          check: () => {
          }
        })
      }
    ]
  },
  ...
}

Unfortunately this is not possible with JSON. But this feature would still be good, you think it's generally a good idea to have custom rules?

Suggest previous prefix

Default of "prefix" should be the last typed value.

Use case:

I am working on an issue number 93 but have multiple commits. I do not want to type "93" all the time when I applied a specific "prefix" type.

Exit after "Initial commit" No

After I pressed at the "Initial commit" on no, it will exit sgc. I actually expected, that I come to the normal sgc prompt

Feat: make maxChar visible

Right now there is no way to detect if a message is longer than maxChar. We should add a feature that allows us to show every character over maxChar in a different color, e.g. red. Or we could add functionality like (12/72).

Lowercase commit tags

Hi,

I ran into a problem with sgc-cli. I am using this action as part of my CI and they use these types as a base. Unfortunately, the don't allow tags to start with a capital letter. Would it be possible to add an option to change that if needed? Cheers.

extends mode

How about something like eslint. They got an extends in their config. This allows us to import commit standards from anybody. It could look like this:

...
"extends": "this-config"
...

Where over our extends will look into node_modules for a package named sgc-config-this-config. It is still allowed to overwrite those extends.

What you think about it @aichbauer ?

sgc retry

If a commit fails, e.g. because of commit hooks, then currently shows Please resolve first and type 'git commit -m ...'. sgc retry can automatically commit with the latest commit message.

  • save in a tempdir
  • find it again with the hash of the project name

Test for checking param choices!

We should consider writing a test that checks if we have a question from type: 'list'. that checks if we provide a param named choices.

Inherit mode

Use case:
If you just want just to overwrite, e.g., the rules you have to write the .sgcrc all over again.

Possible solution:
In those special cases it would be good to have a inherit mode. So if you just want to change "emojies: true" to "emojies: false" you can write the config as follows:

{
  "emojies": false,
  "inherit": true
}

If you just want to inherit the default types you can write it as follows:

{
  "emojies": false,
  "inherit": "types"
}

or

{
  "emojies": false,
  "inherit": [
    "types"
  ]
}

Option definition:

Type: boolean | array | string
Default: false

Non-responsive

Powershell becomes non-responsive after running sgc, specifying a type and a commit message. The commit goes through fine though the window hangs and needs to be closed out forcefully.

Windows 10/x64 Moved from Node 8 to Node 10 recently

Delimiter

Add delimiter instead of to add it in the commit type:

Type: String

  • default: :
  • options e.g.: -, (whitespace), ...

Show commit message length if too long

Currently, if the commit message entered is too long, this message is shown:

The commit message is not allowed to be longer as 72. Consider writing a body.

It would be nice if it would also outline how long the message is currently, e.g.

The commit message is not allowed to be longer as 72, but is 85. Consider writing a body.

Breaking Changes

  • Change emojies to the correct plural emoji
  • Set the default for emoji to false
  • Remove init from the list, and implement it as "just at the beginning"

Option to lowercase types

I had a use case, where I wanted the types and descriptions the same. But I wanted them lowercase.

Maybe we can add an option: lowercaseTypes to lowercase them.
What you think about that @aichbauer

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.