GithubHelp home page GithubHelp logo

ramsey / conventional-commits Goto Github PK

View Code? Open in Web Editor NEW
174.0 5.0 19.0 372 KB

:yo_yo: A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook plugin!

License: MIT License

PHP 98.41% Shell 1.59%
captainhook php conventional-commits commit-msg commit conventional plugin hook git

conventional-commits's Introduction

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

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.

conventional-commits's People

Contributors

dependabot[bot] avatar hussainweb avatar lewiscowles1986 avatar llupa avatar ramsey 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  avatar  avatar

conventional-commits's Issues

Support excluding merge commits

It would be great if we could easily (and maybe even by default) exclude merge commits from the requirement.

Quick merge

When doing a merge of 2 branches that use proper commit messages, the automated merge commit message doesn't really matter and shouldn't be subject to the strict structure of conventional commits.

Background/problem

I want to merge

Proposal/solution

Add an ignore pattern that matches the auto generated merge commit messages.

Alternatives

Write a merge: commit message for every merge.

Incompactible class with Symphony 6

Hello,

I installed your package along with CaptainHook and tried to run your conventional commits validator and I got this error.

Snímek obrazovky 2022-02-13 v 0 09 23

Some methods in Ramsey\CaptainHook\Input class are not compactible with the InputInterface from Symphony.

PHPStan fails for the current codebase

Description

PHPStan reports errors when run manually or during a CI run. I saw this first when working on #58 but then I reproduced this on the main branch as well. That is the reason I am creating a new issue and a PR.

Steps to reproduce

  1. Make sure you are on the latest dependencies with composer update
  2. Run composer dev:analyze:phpstan

Expected behavior

We should see a message from PHPStan saying [OK] No errors.

Screenshots or output

See output below or on one of the recent CI runs.

❯ composer dev:analyze:phpstan
> phpstan analyse --ansi
Note: Using configuration file /Users/hw/work/php/conventional-commits/phpstan.neon.dist.
 96/96 [β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“] 100%

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   src/ConventionalCommits/Configuration/DefaultConfiguration.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  88     Offset 'bodyWrapWidth' on array{typeCase?: string|null, types?: array<string>, scopeRequired?: bool, scopeCase?: string|null, scopes?: array<string>, descriptionCase?: string|null, descriptionEndMark?: string|null,
         bodyRequired?: bool, ...} on left side of ?? always exists and is not nullable.
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   tests/ConventionalCommits/Configuration/DefaultConfigurationTest.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  38     Call to method PHPUnit\Framework\Assert::assertSame() with array{typeCase: null, types: array{}, scopeCase: null, scopeRequired: false, scopes: array{}, descriptionCase: null, descriptionEndMark: null, bodyRequired:
         false, ...} and array{typeCase?: string|null, types?: array<string>, scopeRequired?: bool, scopeCase?: string|null, scopes?: array<string>, descriptionCase?: string|null, descriptionEndMark?: string|null, bodyRequired?:
         bool, ...} will always evaluate to false.
  88     Call to method PHPUnit\Framework\Assert::assertSame() with array{typeCase: 'kebab', types: array{'foo', 'bar', 'baz-qux'}, scopeCase: 'lower', scopeRequired: true, scopes: array{'component', 'unit', 'foo'},
         descriptionCase: 'sentence', descriptionEndMark: '.', bodyRequired: true, ...} and array{typeCase?: string|null, types?: array<string>, scopeRequired?: bool, scopeCase?: string|null, scopes?: array<string>,
         descriptionCase?: string|null, descriptionEndMark?: string|null, bodyRequired?: bool, ...} will always evaluate to false.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Environment details

  • version of this package: main
  • PHP version: 8.1.10
  • OS: macOS

Additional context

None

Allow failure for PHPStan?

In my recent PR #31 it seems stan vomited. If the repo is not yet ready, perhaps PHPStan could be configured to report only; or continue-on-error for that step could be set to true?

Example code

continue-on-error: true

Alternative solutions:

I Could PR after running locally with --generate-baseline, so that this never should get worse; but existing errors I think get ignored.

CaptainHook plugin is broken with symfony 6

The CaptainHook plugin don't work as expected when used with symfony 5 packages, the bug is related to the implementation
of InputInterface in Ramsay\CaptainHook\Input.php, as the class is not defining return types in some functions that the interface does.

I just opened a pull request with the fix.

Improve captainhook validation error message

Right now, all errors are the same:

 [ERROR] Invalid Commit Message                                                 
         The commit message is not properly formatted according to the          
         Conventional Commits specification. For more details, see              
         https://www.conventionalcommits.org/en/v1.0.0/

It would be nice to echo the parser error, so we have a hint of what we did wrong. Example:

 [ERROR] Invalid Commit Message: 'asdf' is not one of the valid types 'feat, fix, refactor, ...'
         The commit message is not properly formatted according to the          
         Conventional Commits specification. For more details, see              
         https://www.conventionalcommits.org/en/v1.0.0/

Return type error when executing prepear command

Description

Steps to reproduce

  1. Install this package.
  2. Execute ./vendor/bin/conventional-commits prepare

Expected behavior

Successfully execute the command.

Screenshots or output

{projectpath} is my project root. It is a fresh new Laravel 9 project.

$ ./vendor/bin/conventional-commits prepare

Fatal error: Uncaught TypeError: Ramsey\ConventionalCommits\Console\Command\BaseCommand::getComposer(): Return value must be of type Composer\Composer, Composer\PartialComposer returned in {projectpath}/vendor/ramsey/conventional-commits/src/ConventionalCommits/Configuration/FinderTool.php:100
Stack trace:
#0 {projectpath}/vendor/ramsey/conventional-commits/src/ConventionalCommits/Configuration/FinderTool.php(139): Ramsey\ConventionalCommits\Console\Command\BaseCommand->getComposer(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput), Object(Symfony\Component\Filesystem\Filesystem))  
#1 {projectpath}/vendor/ramsey/conventional-commits/src/ConventionalCommits/Configuration/FinderTool.php(84): Ramsey\ConventionalCommits\Console\Command\BaseCommand->loadConfigFromComposer(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 {projectpath}/vendor/ramsey/conventional-commits/src/ConventionalCommits/Console/Command/BaseCommand.php(56): Ramsey\ConventionalCommits\Console\Command\BaseCommand->findConfiguration(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput), NULL)
#3 {projectpath}/vendor/symfony/console/Command/Command.php(291): Ramsey\ConventionalCommits\Console\Command\BaseCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 {projectpath}/vendor/symfony/console/Application.php(989): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))     
#5 {projectpath}/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand(Object(Ramsey\ConventionalCommits\Console\Command\PrepareCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 {projectpath}/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))       
#7 {projectpath}/vendor/ramsey/conventional-commits/bin/conventional-commits(69): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput))
#8 {projectpath}/vendor/ramsey/conventional-commits/bin/conventional-commits(70): {closure}(Array)      
#9 {projectpath}/vendor/bin/conventional-commits(97): include('/data/dev/loong...')
#10 {main}
  thrown in {projectpath}/vendor/ramsey/conventional-commits/src/ConventionalCommits/Configuration/FinderTool.php on line 100

Environment details

  • version of this package: 1.3.0
  • PHP version: 8.1.3
  • OS: Linux (Ubuntu 20.04.4) (WSL)
  • Composer version: 2.1.12

Additional context

./vendor/bin/conventional-commits works fine and output the help message.

Feature request: "ignores" option

My feature title

"ignores" option

Background/problem

I want to leave some commit messages without description.

E.g. when the style is fixed with php-cs-fixer I don't want to look what it did and describe it.
I prefer just to use short message "style".

However, your package does not allow to do this.

Proposal/solution

Add "ignore" option that would contain an array with exclusions. E.g.

{
  "ignore": ["refactor", "style"]
}

Alternatives

Additional context

There is similar npm package "commitlint" for javascript projects.
It accepts ignore function.
Certainly, json configuration may not accept function.
But at least it can accept fixed list of exclusions.

Configurable Preceding Symbol

Configurable Preceding Symbol

Possibility to set the precending symbol in the configuration

Background/problem

When using e.g. Jira the Issue preceding symbol is depending on the Jira project and is something like MYPRO-. It would be nice to have the possibility to configure the preceding symbol to have the possibility to use the Jira Project Key instead of the #.

Proposal/solution

  • add precendingSymbol to configuration schema
  • add # as default value to Configuration
  • use precendingSymbol configuration value in IssueIdentifierQuestion

Alternatives

Additional context

Would love to help with that feature and contribute, but before just start coding I would like to ask if this is something you want to have as a feature. Also the naming of the configuration key should be discussed. Perhaps IssuePrefix or IssueKey is better.

Track information from twitter on OSX failure

This is a general thread for people from Twitter to share anything concrete they have found relating to the OSX lowest failures for PHP8.1

Description

CI fails on OSX with PHP 8.1 in GitHub actions...

Steps to reproduce

  1. Fork repo
  2. Enable GitHub actions
  3. Push either an empty commit or a bump commit (no code changes, just markdown)

Expected behavior

Either fails for all OS's or passes for all 🀷 or at least readable messages on why not.

Screenshots or output

I made a gist so I could track differences. It was quite interesting to see just how many there were.

https://gist.github.com/Lewiscowles1986/ef49ea071a68d5d36b43114d4346021f/revisions

This is the latest GitHub actions run https://github.com/Lewiscowles1986/conventional-commits/runs/4694763377?check_suite_focus=true

But I tried several suggestions and theories I had. This is for-sure a weird issue.

Environment details

GitHub action has a lot of context captured.

Additional context

Please see the actions for output.

lower case converter wrong validation

I think this is kind a bug but I am not sure if it could be the valid implementation of a lower case converter

Maybe is more related to jawira/case-converter than with that package.

Steps to reproduce

If we config the package to use "descriptionCase": "lower", if we try to commit the following commit type(scope): 1.1.1 to release a new version, the commit message validation will fail as it detect that the versioning is not in lower format

Screenshots or output

Image showing error

Add this library in conventionalcommits.org.

My feature title

Add this library in conventionalcommits.org.

Background/problem

I want many people to use this library.
If this library's name's written in conventionalcommits.org, more many people can know and use this library.
https://www.conventionalcommits.org/

Proposal/solution

In about page, add this library's name and description to Tooling for Conventional Commits
https://www.conventionalcommits.org/en/about/

For example...

  • conventional-commits: A PHP library for creating and validating commit messages according to the Conventional Commits specification.

conventional-commits/conventionalcommits.org#434

Build and release PHAR

Provide PHAR releases for conventional-commits

Right now, the documented way to install this would be to use composer require --dev. I would also like the option of downloading a PHAR file for this.

Background/problem

The dependencies of this package are quite strict which would not let me add this package where I would want to use this. For example, different versions of Drupal depend on different releases of Symfony packages and the version requirements here are quite strict. I can avoid this to an extent with cgr or composer global require --dev but there is a chance of conflicts anyway.

Next, there is a hard dependency on CaptainHook but I would want to use this with GrumPHP. It doesn't make sense to include both in a project. Another way could be to move captainhook to suggests instead of require but that's a big change and might need rewriting and testing.

A third way could be to break the package into supporting libraries and I could use that library in GrumPHP. Again, it's a lot of work.

Considering all this, I think creating a PHAR file is the easiest way out of all of these problems.

Proposal/solution

I suggest building and making PHAR files available and I can help with a PR if you're open to this. Of course, I can only contribute with the way to create PHAR files and I believe the maintainers will need to add it to releases or make it available to Phive, for example. My thought is to use https://github.com/box-project/box but I am open to other methods as well.

Alternatives

Already described in the background above.

Additional context

Already described in the background above.

Integration with grumphp

It would be great to integrate this package with grumphp

Integration with Grumphp

none

Grumphp have a tedious way to handle this commig-messages

Proposal/solution

Integrate to a custom hook like in CaptainHook

Alternatives

Additional context

Captain hook plugin

The README mentions a Captain hook plugin, but the composer.json lists CaptainHook as a dependency.

I think either the README should reflect the CaptainHook library is a hard dependency, or it should be listed as a suggested dependency instead.

Let me know if you agree and I'll implement a PR. Personally I think, if possible, it would be best to list CaptainHook as an optional dependency.

Use PHP with Behat rather than expect

I noticed the functional tests use expect command line utility. I Was surprised by this as Behat can be used for the same purpose.

My feature title

Use Behat instead of expect

Background/problem

This would avoid the need to install expect onto a system.

Proposal/solution

Use Behat and keep tests to PHP

Alternatives

Leave things as they are, or use another cucumber DSL

Additional context

While I was checking out a PHP 8.1 issue you'd reported and asked for help with, this surprised me

bash: expect: command not found

That error was actually swallowed and instead I saw

$ ./tests/bash-test ./tests/functional-tests.sh
bash-test v0.3.0 by Campanda GmbH and contributors.

functional-tests.sh


[FAILURE] Output for failed test config_01:


  βœ— _test_expect config_01


[FAILURE] Output for failed test config_02:


  βœ— _test_expect config_02


[FAILURE] Output for failed test config_03:


  βœ— _test_expect config_03


[FAILURE] Output for failed test config_04:


  βœ— _test_expect config_04


[FAILURE] Output for failed test config_05:


  βœ— _test_expect config_05


[FAILURE] Output for failed test config_with_defaults:


  βœ— _test_expect config_with_defaults


[FAILURE] Output for failed test prepare_basic:


  βœ— _test_expect prepare_basic


[FAILURE] Output for failed test prepare_with_alt_config_and_many_errors:


  βœ— _test_expect prepare_with_alt_config_and_many_errors


[FAILURE] Output for failed test prepare_with_invalid_type:


  βœ— _test_expect prepare_with_invalid_type


[FAILURE] Output for failed test prepare_with_long_desc_and_more_values:


  βœ— _test_expect prepare_with_long_desc_and_more_values

 10 of 10 tests failed.

real    0m4.192s
user    0m0.363s
sys     0m1.096s

I Couldn't find a FeatureContext or similar php file. So I went digging into what was happening and saw this.

How do I validate a commit message using the executable instead of CaptainHook?

How do I validate a commit message using the executable instead of CaptainHook?

While working on #40, I realized that even if there is a PHAR, I can't use it to actually validate a commit message. These are the only commands I see on the executable and none of them help in validating a message.

  completion  Dump the shell completion script
  config      Configures options for creating Conventional Commits
  help        Display help for a command
  list        List commands
  prepare     Prepares a commit message conforming to Conventional Commits

I think there is a place for a new command validate that would do the job. I am happy to write a PR but I wanted to check if I have not missed something obvious here.

Feature request: "extend" field to extend json configuration template

My feature title

"extend" field to extend json configuration template

Background/problem

Proposal/solution

This will allow to share configuration between multiple projects.

E.g. template configuration may contain universal scopes and each project can add individual scopes.

Alternatives

Additional context

there is similar npm package "commitlint" and it allows to extend configuration.

Feature request: scopeCase option that will compare to scopes with case sensitivity

My feature title

"case-sensitive-match" option for scopeCase.

Background/problem

When I provide "scopes" array I prefer scope to be checked case sensitively.

I could use "kebab" scopeCase, but I want to use scopes with dots in some cases.

Proposal/solution

"case-sensitive-match" option for scopeCase.

Alternatives

Allow "scopeCase" to accept array, e.g.:

{
  "scopeCase": ["dot", "kebab"]
}

Additional context

realpath fails when run from within a Phar file

Description

This is related to #25.

The PHP function realpath does not work when trying to resolve relative paths within the Phar file. This is mentioned in the documentation as well.

The function realpath() will not work for a file which is inside a Phar as such path would be a virtual path, not a real one.

There are three places I could find where this function is used. Two of them are in the path of FinderTool::findComposerJson but this is already addressed by changes in #29. The second place is in FinderTool::validateConfig in finding schema.json.

Steps to reproduce

This is reproducible after the changes in #29 and a box configuration file that includes schema.json. When run on a project which contains a configuration file (such as this very package (https://github.com/ramsey/conventional-commits)), the script crashes with an error:

PHP Fatal error:  Uncaught ValueError: Path cannot be empty in phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Configuration/FinderTool.php:173

This is because realpath returns false and it gets cast to an empty string.

Expected behavior

The script should not crash.

Screenshots or output

Stack trace
PHP Fatal error:  Uncaught ValueError: Path cannot be empty in phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Configuration/FinderTool.php:173
Stack trace:
#0 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Configuration/FinderTool.php(173): file_get_contents('')
#1 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Configuration/FinderTool.php(127): Ramsey\ConventionalCommits\Console\Command\BaseCommand->validateConfig(Object(stdClass))
#2 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Configuration/FinderTool.php(160): Ramsey\ConventionalCommits\Console\Command\BaseCommand->loadConfigFromFile('conventional-co...')
#3 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Configuration/FinderTool.php(84): Ramsey\ConventionalCommits\Console\Command\BaseCommand->loadConfigFromComposer(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Console/Command/BaseCommand.php(56): Ramsey\ConventionalCommits\Console\Command\BaseCommand->findConfiguration(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput), NULL)
#5 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/vendor/symfony/console/Command/Command.php(299): Ramsey\ConventionalCommits\Console\Command\BaseCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/vendor/symfony/console/Application.php(978): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/vendor/symfony/console/Application.php(295): Symfony\Component\Console\Application->doRunCommand(Object(Ramsey\ConventionalCommits\Console\Command\PrepareCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/vendor/symfony/console/Application.php(167): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/bin/conventional-commits(68): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput))
#10 phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/bin/conventional-commits(69): {closure}(Array)
#11 /Users/hw/work/php/conventional-commits/bin/conventional-commits.phar(14): require('phar:///Users/h...')
#12 {main}
  thrown in phar:///Users/hw/work/php/conventional-commits/bin/conventional-commits.phar/src/ConventionalCommits/Configuration/FinderTool.php on line 173

Environment details

  • version of this package: main branch
  • PHP version: 8.0.14
  • OS: macOS Monterey

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.