/danger-kotlin-commit-lint

Danger Kotlin Plugin for linting commit messages in PRs/MRs

Primary LanguageKotlinApache License 2.0Apache-2.0

Maven Central

danger-kotlin commit lint plugin

This is a plugin for danger-kotlin that checks if commit messages align with recommendations specified eg. here

Installation

Put

@file:DependsOn("io.github.ackeecz:danger-kotlin-commit-lint:x.y.z")

to the top of your Dangerfile

Usage

There is a single method CommitLintPlugin.check that will perform validations on the commits.

Due to a design of danger-kotlin plugin SDK it does not have access to commits directly and for that reason you need to pass messages to the plugin manually.

register CommitLintPlugin

    danger(args) {
        CommitLintPlugin.check(commits = git.commits.map { gitCommit ->
            Commit(CommitMessage.fromRawMessage(gitCommit.message), gitCommit.sha ?: "")
        })
    }

Rules specification

You can enable only some rules by passing them to the check function. By default, there are these rules:

Name Description
SUBJECT_LENGTH Length of the subject is less than 50 characters
BODY_LENGTH Length of the body is less than 72 characters
SUBJECT_BODY_NEW_LINE Subject and body is separated with newline
SUBJECT_CAPITALIZE Subject should start with capital letter
SUBJECT_MULTIPLE_WORDS Subject have more than one word
SUBJECT_ENDS_WITH_PERIOD Subject does not ends with a period

If you want to disable some rules you can do

CommitLintPlugin.check(commits, Rule.values().toList() - Rule.SUBJECT_CAPITALIZE)

GitMoji first

GitMoji characters are skipped in the beginning for SUBJECT_CAPITALIZE and SUBJECT_MULTIPLE_WORDS rules.