Skip to content

Rugal/commitlinter-maven-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Status

Maven Central License Javadocs CircleCI codecov

Usage

This plugin lints your git commit message according to the rules you defined.
It basically reads commit message from git repository, matches it with the Regex you provided, before linting each capture group according to your rules.

<plugin>
  <groupId>ga.rugal.maven</groupId>
  <artifactId>commitlinter-maven-plugin</artifactId>
  <version>THE-VERSION-YOU-LIKE</version>
</plugin>

Then run command:

mvn commitlinter:validate

This will report nothing as we haven't configure any linting rules.

Show case

asciicast

Parameters

Parameter Type Description Default
captureGroups CaptureGroup[] List of CaptureGroups []
captureGroup.caseFormat enum The case format we want to lint NONE
captureGroup.max Integer The maximum length of this capture group Integer.MAX
captureGroup.min Integer The minimum length of this capture group 0
captureGroup.tense enum The tense of the initial word of this capture group NONE
failOnError Boolean Whether to fail maven build on linting error false
gitFolder String The git repository folder .git
head String The pointer of git HEAD
matchPattern Regex The regex to match commit message (.*)
skip Boolean Whether to skip linting false
testCommitMessage String The commit message to test with ""

caseFormat

case sample
UPPERCASE THIS IS UPPER CASE/THIS_IS_UPPER_CASE_TOO
LOWERCASE this is lower case/this_is_lower_case_too
UPPERCAMELCASE ThisIsUpperCamelCase
LOWERCAMELCASE thisIsLowerCamelCase
KEBABCASE this-is-kebab-case
SNAKECASE this_is_snake_case
SENTENCECASE This is sentence case
NONE ANY_case-you Like

tense

case sample
PRESENT add new feature/create a function
PAST added new feature/created a function
THIRD_PARTY adds new feature/creates a function
NONE any format you like

Simple Example

Please always make sure to wrap the capture group with () so the Regex matcher can capture it.

With Basic Configuration

<plugin>
  <groupId>ga.rugal.maven</groupId>
  <artifactId>commitlinter-maven-plugin</artifactId>
  <version>THE-VERSION-YOU-LIKE</version>
  <configuration>
    <matchPattern>([\w\s]+-\d+:\s)(.*)</matchPattern>
    <failOnError>true</failOnError>
    <captureGroups>
      <captureGroup>
        <max>10</max>
        <min>2</min>
        <caseFormat>LOWERCASE</caseFormat>
      </captureGroup>
      <captureGroup>
        <max>20</max>
        <tense>PRESENT</tense>
        <caseFormat>LOWERCASE</caseFormat>
      </captureGroup>
    </captureGroups>
  </configuration>
</plugin>

This configuration will match the git commit message with Regex, then lint them with the rules defined above.

Bind With Lifecycle

This will bind validate goal in validate phase of Maven lifecycle.

<plugin>
  <groupId>ga.rugal.maven</groupId>
  <artifactId>commitlinter-maven-plugin</artifactId>
  <version>THE-VERSION-YOU-LIKE</version>
  <executions>
    <execution>
      <id>validate</id>
      <phase>validate</phase>
      <configuration>
        <matchPattern>([\w\s]+-\d+:\s)(.*)</matchPattern>
        <failOnError>true</failOnError>
        <captureGroups>
          <captureGroup>
            <caseFormat>LOWERCASE</caseFormat>
          </captureGroup>
          <captureGroup>
            <caseFormat>LOWERCASE</caseFormat>
          </captureGroup>
        </captureGroups>
      </configuration>
      <goals>
        <goal>validate</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Credit

  • The creation of this plugin is inspired by commitlint