question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a configuration template for validating against the conventionalcommits.org spec?

See original GitHub issue

I just came across gitlint via searching for a golang implementation of https://conventional-changelog.github.io/commitlint/#/, which validates against the https://www.conventionalcommits.org/en/v1.0.0-beta.3/ spec.

It looks like gitlint is pretty configurable; I was wondering whether anyone had created a .gitlint config that made it validate against the CC spec? If not - would one be welcome?

(I’d prefer to use a golang based tool, personally, since the environment is simpler to deploy and maintain for engineers - copy a binary, run it, vs maintain a node and npm setup.)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jorisrooverscommented, Jul 8, 2019

Added ‘revert’ keyword in e95fe6122fae5930534f46dfc15dcd3bb7cf8059

Gitlint 0.12.0 with support for this will be released over the next few days. Closing this issue.

2reactions
danielgtaylorcommented, Mar 29, 2019

I’ve been using this to enforce conventional commits:

.gitlint

[general]
ignore=body-is-missing

# Load custom conventional commit rules.
extra-path=gitlint-rules.py

gitlint-rules.py

import re
from typing import List

from gitlint.git import GitCommit
from gitlint.options import ListOption
from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation

_rule_re = re.compile(r"[^(]+?(\([^)]+?\))?: .+")


class ConventionalCommit(LineRule):
    """This rule enforces the spec at https://www.conventionalcommits.org/."""

    # A rule MUST have a human friendly name
    name = "title-conventional-commits"

    # A rule MUST have an *unique* id, we recommend starting with UL (for
    # User-defined Line-rule), but this can really be anything.
    id = "UL1"

    # A line-rule MUST have a target (not required for CommitRules).
    target = CommitMessageTitle

    # A rule MAY have an option_spec if its behavior should be configurable.
    options_spec = [
        ListOption(
            "types",
            ["fix", "feat", "chore", "docs", "style", "refactor", "perf", "test"],
            "Comma seperated list of allowed commit types.",
        )
    ]

    def validate(self, line: str, commit: GitCommit) -> List[RuleViolation]:
        violations = []

        for commit_type in self.options["types"].value:
            if line.startswith(commit_type):
                break
        else:
            violations.append(
                RuleViolation(
                    self.id,
                    f"Title does not start with one of "
                    f"{', '.join(self.options['types'].value)}: {line}",
                )
            )

        if not _rule_re.match(line):
            violations.append(
                RuleViolation(
                    self.id,
                    f"Title does not follow ConventionalCommits.org format "
                    f"like 'type(optional-scope): description': {line}",
                )
            )

        return violations

Then just run gitlint and it should get picked up. What do you think? Would something like this be worth adding as an optional (default off) title rule? Having to put this in a separate file in each repo is kind of a pain, so getting it officially added to gitlint or supporting plugins via pip install ... would be better!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conventional Commits
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an...
Read more >
What about work in progress commits · Issue #38 - GitHub
examle: i'm work on feature and dont know my code is correct or no, but i must go home. i will push a...
Read more >
Setup and Customize Conventional Commits and Semantic ...
CommitLint validates commits to see if matches the standard formatting of a conventional commit. In this example, I'm going to use Commitizen ......
Read more >
A specification for structured commit messages | Hacker News
On come on, this entire "spec" can be summarized in two sentences. It can be validated with a 13 character regex.
Read more >
ramsey/conventional-commits - Packagist
ramsey/conventional-commits is a PHP library for creating and validating commit messages according to the Conventional Commits specification. It also ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found