Coder Social home page Coder Social logo

gherciu / commitlint-jira Goto Github PK

View Code? Open in Web Editor NEW
187.0 3.0 29.0 872 KB

✔️❌ commitlint-jira checks if your commit messages meet the Jira conventional commit format.

License: MIT License

JavaScript 11.08% TypeScript 88.92%
commitlint jira jira-commitlint commitizen commitlint-config commitlintplugin

commitlint-jira's Introduction

commitlint-jira

commitlint-jira checks if your commit messages meet the Jira conventional commit format.

GitHub Multipack

For Tips and Advanced Usage you can read this Blog Post

Getting started.

Install dependencies
npm install --save-dev @commitlint/cli commitlint-plugin-jira-rules commitlint-config-jira
  • commitlint-config-jira - is a recomended config who contain preconfigured rules for jira commits messages style. See all rules in description below
  • commitlint-plugin-jira-rules - is a plugin that implement all jira commits messages style rules and validate commit messages
Configure commitlint to use jira commits messages style config
// commitlint.config.js
module.exports = {
  plugins: ['commitlint-plugin-jira-rules'],
  extends: ['jira'],
}
To lint commits before they are created you can use husky's 'commit-msg' hook

Run the following in your terminal to create the proper hook.

npx husky add .husky/commit-msg 'commitlint --edit $1'

For version 4 and under of Husky use the following syntax instead in your package.json.

// package.json
{
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }
}
You can use pre-commit as an alternative to husky

You need to have the pre-commit package manager installed. Follow the installation guideline.

  1. Add the following to your .pre-commit-config.yaml

    - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
      rev: <latest tag>
      hooks:
          - id: commitlint
            stages: [commit-msg]
            additional_dependencies: ['commitlint-plugin-jira-rules', 'commitlint-config-jira']
    
  2. Install the commit-msg hook in your project repo

    pre-commit install --hook-type commit-msg

Rules

jira-task-id-empty - this rule check if commit message task id is not empty.

// If your task do not have an id use a conventional task id e.g: IB-0000
// ❌ Bad commit messages
git commit -m"My commit message body"
git commit -m":My commit message body"
// ✅ Good commit messages
git commit -m"IB-2121, IB-21: My commit message body"
git commit -m"IB-0000: My commit message body"

jira-task-id-max-length - this rule check if jira task id length is loonger that the provided value.

// Preconfigured and recommended value in commitlint-config-jira is 9 chars
// ❌ Bad commit messages
git commit -m"IB-2121212121212121: My commit message body"
// ✅ Good commit messages
git commit -m"IB-2121: My commit message body"
git commit -m"IB-21: My commit message body"

jira-task-id-min-length - this rule check if jira task id length is shorter that the provided value.

// Preconfigured and recommended value in commitlint-config-jira is 3 chars
// ❌ Bad commit messages
git commit -m"I1: My commit message body"
// ✅ Good commit messages
git commit -m"IB-2121: My commit message body"
git commit -m"IB-21: My commit message body"

jira-task-id-case - this rule check if taskId is in provided case.

// Preconfigured and recommended value in commitlint-config-jira is "uppercase"
// ❌ Bad commit messages
git commit -m"ib-21: My commit message body"
// ✅ Good commit messages
git commit -m"IB-2121, IB-21: My commit message body"
git commit -m"IB-21: My commit message body"

jira-task-id-separator - this rule check if taskId header and footer is separated with provided value.

// Preconfigured and recommended value in commitlint-config-jira is "-"
// ❌ Bad commit messages
git commit -m"IB/21: My commit message body"
git commit -m"IB_21 :My commit message body"
// ✅ Good commit messages
git commit -m"IB-2121, IB-21: My commit message body"
git commit -m"IB-21: My commit message body"

jira-task-id-project-key - this rule check if commit message task id starts with specific project key.

// Accept a string or an array of strings, by default is disabled
// For example ["PRJ1", "PRJ2"]
// ❌ Bad commit messages
git commit -m"IB-21: My commit message body"
// ✅ Good commit messages
git commit -m"PRJ1-21, PRJ1-22: My commit message body"
git commit -m"PRJ2-21: My commit message body"

jira-commit-status-case - this rule check if commit status is in provided case.

// Preconfigured and recomended value in commitlint-config-jira is "uppercase"
// ❌ Bad commit messages
git commit -m"[wip]IB-21: My commit message body"
// ✅ Good commit messages
git commit -m"[WIP]IB-21: My commit message body"

jira-commit-message-separator - this rule check if commit message separator match provided separator.

// Preconfigured and recomended value in commitlint-config-jira is ":"
// ❌ Bad commit messages
git commit -m"IB-21/ My commit message body"
git commit -m"IB-21 - My commit message body"
git commit -m"IB-21% My commit message body"
// ✅ Good commit messages
git commit -m"IB-21: My commit message body"

Customise/Override commitlint-jira-config rules

For Tips and Advanced Usage you can read this Blog Post

// commitlint.config.js
module.exports = {
  plugins: ['commitlint-plugin-jira-rules'],
  extends: ['jira'],
  rules: {
  // to Customise/Override a rule
+  'jira-task-id-max-length': [2, 'always', 10]
  // to turn off a rule
+ 'jira-task-id-max-length': [0]
  },
}

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Or you can sponsor via Open Collective

Open Collective

Author

@Gherciu/commitlint-jira Released under the MIT License.
Authored and maintained by GHERCIU GHEORGHE with help from contributors (list).

If you like this repository star⭐ and watch👀 on GitHub

commitlint-jira's People

Contributors

ashblue avatar dependabot[bot] avatar gherciu avatar jagers avatar kenime avatar web-flow avatar yukinoda 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

commitlint-jira's Issues

[Feature request] Add support for `<ignored text>` to improve the compatibility with Conventional Commits

The basic Jira Smart Commits syntax is:

<ignored text> <ISSUE_KEY> <ignored text> #<COMMAND> <optional COMMAND_ARGUMENTS>

Conventional Commits syntax is:

<type>[scope]: <description>

In fact both formats are compatible, there are even Comittizen plugins that support that e.g. https://github.com/digitalroute/cz-conventional-changelog-for-jira

It would be great if commitlint-jira also supported this syntax. The only thing that's missing is the support for <ignored text>. The <ignored text> prefix in the Jira format is what <type>[scope]: is in the Conventional Commits format.

Real life example:

feat(api)!: JRA-34 send an email to the customer when a product is shipped

In this case:

  • feat(api)!: is <ignored text> in Jira format and <type>[scope]: in the Conventional Commits format
  • JRA-34 send an email to the customer when a product is shipped is a <description> in the Conventional Commits format, while in Jira forma it's the <ISSUE_KEY> and <ignored text> in the Jira format.

turning off jira-commit-message-separator causes an exception

While trying to turn off the "jira-commit-message-separator" rule based on the example in the README, I receive an exception.

module.exports = {
  plugins: ["commitlint-plugin-jira-rules"],
  extends: ["jira"],
  rules: {
    "jira-commit-message-separator": 0,
  },
};

**frontend\node_modules@commitlint\cli\lib\cli.js:124
throw err;
^

Error: config for rule jira-commit-message-separator must be array, received 0 of type number
at Object. (frontend\node_modules@commitlint\lint\lib\index.js:119:19)
at process._tickCallback (internal/process/next_tick.js:68:7)**

Suggestion: Add an example for disabling the rule in the README.

Update thrown errors order

The first error should be ":" missing commit_separator --> then "empty task id" --> then "status" --> then rest

It will improve DX

Setting jira-task-id-project-key Rule

In commitlint.config.js, I'm trying to set the task id project key to enforce using UP. I've tried:

module.exports = {
plugins: ['commitlint-plugin-jira-rules'],
extends: ['jira'],
rules: {
'jira-task-id-project-key': ['UP'],
}
}

and

module.exports = {
plugins: ['commitlint-plugin-jira-rules'],
extends: ['jira'],
rules: {
'jira-task-id-project-key': 'UP',
}
}

In package.json I have:

"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-push": "npm run test:ci"
}
}

Running git commit -m 'UP-1: hey'

I get:

tim2020mbp:scripts tim$ git commit -m 'UP-1: hey'
husky > commit-msg (node v14.5.0)
/Users/tim/projects/ae/ae-up-ui/node_modules/@commitlint/cli/lib/cli.js:131
throw err;
^

Error: level for rule jira-task-id-project-key must be number, received 'UP' of type string
at lint (/Users/tim/projects/ae/ae-up-ui/node_modules/@commitlint/lint/lib/lint.js:84:15)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 0)
husky > commit-msg hook failed (add --no-verify to bypass)

LIbs in package.json
"@commitlint/cli": "^9.1.1",
"commitlint-config-jira": "^1.4.1",
"commitlint-plugin-jira-rules": "^1.4.0",

trim error when testing non-passing commits

When attempting to test a non-passing commit, instead of displaying the error, the actual process errors out on a trim() command

git commit -m "test"
husky > commit-msg (node v8.16.0)
/Volumes/dev/api-cpadmin/node_modules/@commitlint/cli/lib/cli.js:119
	throw err;
	^

TypeError: Cannot read property 'trim' of undefined
    at d (/Volumes/dev/api-cpadmin/node_modules/commitlint-plugin-jira-rules/build/index.js:1:3159)
    at a (/Volumes/dev/api-cpadmin/node_modules/commitlint-plugin-jira-rules/build/index.js:1:3963)
    at results.filter.map.entry (/Volumes/dev/api-cpadmin/node_modules/@commitlint/lint/lib/index.js:151:17)
    at Array.map (<anonymous>)
    at Object.<anonymous> (/Volumes/dev/api-cpadmin/node_modules/@commitlint/lint/lib/index.js:131:7)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
husky > commit-msg hook failed (add --no-verify to bypass)

'jira-task-id-empty' is being emitted when the commit message separator is not ":"

'jira-task-id-empty' is being emitted when the commit message separator is not ":"

Sample commit message:
TEST-001 jira commit lint

commitlint.config.js

module.exports = {
  plugins: ['commitlint-plugin-jira-rules'],
  extends: ['jira'],
  rules: {
    'jira-commit-message-separator': [2, 'always', ' ']
  }
};

result:
the commit message must provide minimum one task id followed by (:) symbol, if task not have an id use a conventional task id e.g: "IB-0000: My commit message" [jira- task-id-empty]

Using commitlint-jira with git-cz

Hello thanks a lot for this awesome package. I am using git-cz for some meaningful commits with some neat emojis but also want to attach JIRA tickets inside the Commits. So my Commit format would be -

🎸 feat: PP-64: Added Linting to the Project.

But when I followed the README I get various errors like jira-task-id-case, jira-commit-status-case, jira-task-id-separator. I tried a number of combinations by adding and removing rules but no luck.

@Gherciu, Sir please can you help me with the setup if I were to achieve the above commit message format. Thanks

'jira-task-id-empty' is being emitted when the commit message contains URLs

'jira-task-id-empty' is being emitted when there is a URL inside the commit message.
here is a sample commit message:

TEST-1: #done #time 10h Testing commitlint
https://mytracker.atlassian.net/browse/TEST-1
#comment Testing if it works or not

this will break into the commit message into 3 task ids:
1: "TEST-1" -> CORRECT
2: "#done #time 10h Testing commitlint↵https" -> SHOULDN'T EXIST
3: "//mytracker.atlassian.net/browse/TEST-1↵#comment Testing if it works or not" -> SHOULDN'T EXIST

I propose adding this regex to the filter function: taskId.search(/[A-Z]+-[0-9]+/) == 0, it should fix the issue.

'jira-task-id-empty' is thrown when the commits are made using the git vi editor

Hi usually teams rather than giving the inline commit message, use the vi editor which is opened by just typing git commit.

Whenever the vi editor is opened it begins with hash comments something like this

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch configure/commitlint
# Changes to be committed:
#       modified:   src/index.js
#
# Changes not staged for commit:
#       modified:   commitlint.config.js
#       modified:   package-lock.json
#       modified:   package.json
MIG-2103: update package.json

Whenever we commit like this, the commitlint-jira is unable to recognize the task id as it is at the end. The commitlint-jira plugin is taking hashes (comments) into consideration and thus giving the wrong result.

Custom COMMIT_MESSAGE_SEPARATOR

Is there a way to configure the commit separator in commitlint.config.js? For example I'd like mine to be ': ' (with a space after).

Task ID must be provided.

Want to say a big thank you for this plugin.
So I just started using this package today, however, I've been getting this issue for a commit message of this format.

[TRANSITION]COMP-83: my commit message

What do I do?

Subject case rule is ignored

Hello,

I have found that overriding subject-case with [2, "always", "sentence-case"] no errors are reported.

For example,

git commit -m "EX-12: subject case" -- should throw error
git commit -m "EX-12: Subject case" -- should pass

Maybe we can add new rule for this? or fix ti?

Thanks.

not able to run local test

Screenshot 2019-10-11 20:49:26

while running the local test for rules in commitlint-jira-e2e-tests facing issues

Procedure followed:
npm run watch:packages
cd packages/commitlint-jira-e2e-tests
echo hello | commitlint

Not compatible with commitlint

Hi, thanks for writing this awesome plugin.
does this plugin support following format

IB-2021: fix(ui): fixed some ui related work

I'm getting type may not be empty [type-empty] error

Not strict equality for Jira task id project key in commit message

I found the issue if set the Jira task id project key, commit lint checks that the commit message must begin with the project id key, but not strictly equal to it
'jira-task-id-project-key': [2, 'always', 'KB'],
Example:
git commit "KB-1: add commitlint-jira" // passed
git commit "KBB-1: add commitlint-jira" // also passed, but KBB is not equal to KB

Custom jira-task-id

Hello,
After reading the documentation and testing several solutions, i need hello.
My objectif is to obtain this valid commit :
[DM-189] : commit text

Do you have any idea how to achieve this result?

Thank you in advance for your answers and your help.

Jérémie

Respect Angular conventions

Hello,

I am wondering if this repository is still maintained. I hope so, because I wanted ask if you could support JIRA IDs at the end or even at second position of a commit message.
I am asking because I would like to also use it together with angular commit conventions to end up with a commit like

  • feat: great thing JIRAID-1234 or
  • feat: great thing (JIRAID-1234)

this would allow subsequent tooling like semantic-release and Changelog generation based on commits to deliver even nicer results.

Using Jira Ticket with type

Hello! I need create this template on commitlint: [XXX-123] type: subject
what rules can i put in order to reach this standard?

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.