• Stars
    star
    174
  • Rank 211,449 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿช€ A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook plugin!

ramsey/conventional-commits

A PHP library for creating and validating commit messages.

Source Code Download Package PHP Programming Language Read License Build Status Codecov Code Coverage Psalm Type Coverage

About

ramsey/conventional-commits is a PHP library for creating and validating commit messages according to the Conventional Commits specification. It also includes a CaptainHook action!

This project adheres to a code of conduct. By participating in this project and its community, you are expected to uphold this code.

Installation

Install this package as a development dependency using Composer.

composer require --dev ramsey/conventional-commits

Usage

To use the conventional-commits console command to help you prepare commit messages according to Conventional Commits, enter the following in your console:

./vendor/bin/conventional-commits prepare

You can also validate the commit message using the following command:

./vendor/bin/conventional-commits validate "[commit message]"

If you don't provide a commit message in the command line, the command will prompt you for it.

To see all the features of the console command, enter:

./vendor/bin/conventional-commits

CaptainHook Action

To use ramsey/conventional-commits with CaptainHook as part of your commit-msg and/or prepare-commit-msg Git hooks, be sure to require CaptainHook as a development dependency.

Check out the CaptainHook documentation for more information on installing and configuring CaptainHook.

Validating Commit Messages

To use the CaptainHook action to validate commit messages according to the Conventional Commits specification, add the following to the commit-msg property in your captainhook.json file:

{
    "commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit"
            }
        ]
    }
}

Preparing Commit Messages

You can set up this library to prompt you to prepare commit messages when you use git commit!

To use the CaptainHook action to prepare commit messages according to the Conventional Commits specification, add the following to the prepare-commit-msg property in your captainhook.json file:

{
    "prepare-commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Ramsey\\CaptainHook\\PrepareConventionalCommit"
            }
        ]
    }
}

Configuration

Configuring ramsey/conventional-commits offers control over a few more aspects of commit messages, such as letter case (i.e. lower, upper), allowed types and scopes, required footers, and more.

We look for configuration in one of two places:

  • composer.json
  • captainhook.json

โš ๏ธ Please note: if your composer.json file is not in the same location as the vendor/ directory, we might have trouble locating it. Feel free to open an issue, and we'll work with you to see if we can find a solution.

Configuration Properties

Configuration for ramsey/conventional-commits consists of the following properties:

Property Description
typeCase The letter case to require for the type. By default, any letter case is acceptable.
types An array of accepted types (in addition to "feat" and "fix"). By default, any type is acceptable.
scopeCase The letter case to require for the scope. By default, any letter case is acceptable.
scopeRequired Whether a scope is required. By default, scope is not required.
scopes An array of accepted scopes. By default, any scope is acceptable.
descriptionCase The letter case to require for the description. By default, any letter case is acceptable.
descriptionEndMark A character to require at the end of the description. By default, any character is allowed. Use an empty string to indicate a punctuation character is not allowed at the end of the description.
bodyRequired Whether a body is required. By default, a body is not required.
bodyWrapWidth An integer indicating the character width to auto-wrap the body of the commit message. By default, the commit body does not auto-wrap.
requiredFooters An array of footers that must be provided. By default, footers are not required.

When specifying configuration, if you wish to use the default behavior for a property, it is not necessary to list the property in your configuration.

Recognized letter cases are:

Identifier Name Example
ada Ada case The_Quick_Brown_Fox
camel Camel case theQuickBrownFox
cobol COBOL case THE-QUICK-BROWN-FOX
dot Dot notation the.quick.brown.fox
kebab Kebab case the-quick-brown-fox
lower Lower case the quick brown fox
macro Macro case THE_QUICK_BROWN_FOX
pascal Pascal case TheQuickBrownFox
sentence Sentence case The quick brown fox
snake Snake case the_quick_brown_fox
title Title case The Quick Brown Fox
train Train case The-Quick-Brown-Fox
upper Upper case THE QUICK BROWN FOX

Configuration in composer.json

If you choose to put your configuration in composer.json, place it within the extra property, namespaced under ramsey/conventional-commits, like this:

{
    "extra": {
        "ramsey/conventional-commits": {
            "config": {
                "typeCase": null,
                "types": [],
                "scopeCase": null,
                "scopeRequired": false,
                "scopes": [],
                "descriptionCase": null,
                "descriptionEndMark": null,
                "bodyRequired": false,
                "bodyWrapWidth": null,
                "requiredFooters": []
            }
        }
    }
}

๐Ÿ“ The properties in this example represent the default values.

Configuration in captainhook.json

If you choose to put your configuration in captainhook.json, you must provide it for each action you configure, like this:

{
    "commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit",
                "options": {
                    "config": {
                        "typeCase": null,
                        "types": [],
                        "scopeCase": null,
                        "scopeRequired": false,
                        "scopes": [],
                        "descriptionCase": null,
                        "descriptionEndMark": null,
                        "bodyRequired": false,
                        "bodyWrapWidth": null,
                        "requiredFooters": []
                    }
                }
            }
        ]
    },
    "prepare-commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Ramsey\\CaptainHook\\PrepareConventionalCommit",
                "options": {
                    "config": {
                        "typeCase": null,
                        "types": [],
                        "scopeCase": null,
                        "scopeRequired": false,
                        "scopes": [],
                        "descriptionCase": null,
                        "descriptionEndMark": null,
                        "bodyRequired": false,
                        "bodyWrapWidth": null,
                        "requiredFooters": []
                    }
                }
            }
        ]
    }
}

However, if you provide your configuration in composer.json, it is not necessary to also provide it in captainhook.json.

๐Ÿšจ If using the Git commit hook functionality of Captain Hook, any configuration provided in captainhook.json will override configuration in composer.json.

โš ๏ธ When using the standalone command (i.e. ./vendor/bin/conventional-commits), only configuration in composer.json will apply, unless providing the --config option.

Configuration in a Separate File

You may also store your configuration in a separate file. For example, you may store it in conventional-commits.json, like this:

{
    "typeCase": "kebab",
    "types": [
        "ci",
        "deps",
        "docs",
        "refactor",
        "style",
        "test"
    ],
    "scopeCase": "kebab",
    "scopeRequired": false,
    "scopes": [],
    "descriptionCase": "lower",
    "descriptionEndMark": "",
    "bodyRequired": true,
    "bodyWrapWidth": 72,
    "requiredFooters": ["Signed-off-by"]
}

When stored in a separate file, we won't know where to look for your configuration, unless you tell us, so you must still provide a small amount of configuration in either composer.json or captainhook.json, so we can find it.

Here's what this looks like in composer.json:

{
    "extra": {
        "ramsey/conventional-commits": {
            "configFile": "./conventional-commits.json"
        }
    }
}

And here's what this looks like in captainhook.json:

{
    "commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit",
                "options": {
                    "configFile": "./conventional-commits.json"
                }
            }
        ]
    },
    "prepare-commit-msg": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Ramsey\\CaptainHook\\PrepareConventionalCommit",
                "options": {
                    "configFile": "./conventional-commits.json"
                }
            }
        ]
    }
}

Contributing

Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.

Coordinated Disclosure

Keeping user information safe and secure is a top priority, and we welcome the contribution of external security researchers. If you believe you've found a security issue in software that is maintained in this repository, please read SECURITY.md for instructions on submitting a vulnerability report.

Copyright and License

The ramsey/conventional-commits library is copyright ยฉ Ben Ramsey and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.

More Repositories

1

uuid

โ„๏ธ A PHP library for generating universally unique identifiers (UUIDs).
PHP
12,301
star
2

collection

๐Ÿ—‚๏ธ A PHP library for representing and manipulating collections.
PHP
1,051
star
3

uuid-doctrine

โ„๏ธ๐Ÿ—„๏ธ Allow the use of a ramsey/uuid UUID as Doctrine field type.
PHP
874
star
4

array_column

Provides functionality for array_column() to projects using PHP earlier than version 5.5.
PHP
373
star
5

php-library-starter-kit

๐Ÿ—๏ธ A tool to quickly set up the base files of a PHP library project.
PHP
238
star
6

composer-install

๐ŸŽ A GitHub Action to streamline installation of PHP dependencies with Composer.
Shell
215
star
7

composer-repl

๐Ÿš A REPL for PHP built into Composer (using PsySH)
97
star
8

macos-vagrant-box

Scripts to generate Vagrant boxes for macOS
Shell
96
star
9

devtools

๐Ÿงฐ A Composer plugin to aid PHP library and application development.
64
star
10

uuid-console

A console application for generating UUIDs with ramsey/uuid.
PHP
39
star
11

identifier

A PHP library for generating and working with identifiers, including UUIDs, ULIDs, and Snowflakes
PHP
38
star
12

vagrant-php-src-dev

Uses Vagrant to provision a basic virtual environment for hacking on the PHP core.
Puppet
37
star
13

jenkins-php

A meta package for the PHP Quality Assurance Toolchain tools required by the Template for Jenkins Jobs for PHP Projects, http://jenkins-php.org/
35
star
14

php-rfcs

PHP
34
star
15

http-range

A PHP library for parsing and handling HTTP range requests.
PHP
30
star
16

laravel-oauth2-instagram

A Laravel 5 service provider for league/oauth2-instagram
PHP
29
star
17

beatles

The Beatles programming language
24
star
18

devtools-lib

๐Ÿงฐ๐Ÿ“š The library behind ramsey/devtools, allowing for extension of the ramsey/devtools Composer plugin.
PHP
21
star
19

twig-codeblock

Syntax highlighting for Twig with the {% codeblock %} tag.
PHP
19
star
20

oauth2-example

Full Laravel source application for example in "Mastering OAuth 2.0" articles and talks.
PHP
17
star
21

vnderror

application/vnd.error builder/formatter for PHP 5.3+
PHP
17
star
22

php-museum-exhibits

HTML
15
star
23

ext-ecma_intl

A PHP implementation of the ECMAScript 2023 Internationalization API Specification (ECMA-402)
C
9
star
24

gitea-environment

Shell
9
star
25

math

This package is abandoned. Try brick/math instead: https://github.com/brick/math
PHP
8
star
26

dotfiles

The dotfiles I use on my systems
Vim Script
8
star
27

coding-standard

๐Ÿงผ A common coding standard for @ramsey's PHP libraries.
PHP
7
star
28

pdo_oci8

PHP userspace classes for Oracle to mimic the PDO interface while wrapping the oci8 functions.
PHP
7
star
29

str-begins-ends

Provides functions to test whether a string begins or ends with a certain substring.
PHP
5
star
30

rhumsaa-uuid

NO LONGER MAINTAINED. Use ramsey/uuid instead.
PHP
5
star
31

jupyter-php-docker

Dockerfile
4
star
32

MantisBT-HipChat

HipChat integration for Mantis bug tracker
PHP
3
star
33

sculpin-codeblock

A Sculpin bundle for using the ramsey/twig-codeblock extension for defining blocks of code for syntax highlighting (with Pygments) and more.
PHP
2
star
34

php-icu-testing

Dockerfile
2
star
35

http2-php-playground

PHP
2
star
36

uuid-benchmark

Benchmark tests for ramsey/uuid
PHP
2
star
37

website

My personal website and blog
PHP
2
star
38

docker-pennmush

A Docker image for PennMUSH, a MUD-style server.
Shell
2
star
39

docker-jupyter-php

Shell
2
star
40

composer-repl-lib

๐Ÿš๐Ÿ“š The library behind ramsey/composer-repl, allowing for extension of the ramsey/composer-repl Composer plugin and non-plugin use of the repl command.
PHP
2
star
41

composer-plugin-issue

This repo illustrates a problem I discovered with using Composer plugins.
1
star
42

gimmebutton

A Gimme Bar toolbar button for Firefox
Shell
1
star
43

api-toolbox

Examples used in my "A Toolbox for APIs & Integrations" presentation.
PHP
1
star
44

base

Arbitrary base conversion and encoding/decoding for all the bases that are belong to us.
PHP
1
star
45

matrix-environment

Shell
1
star