Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new pattern option #266

Conversation

sebastianlarisch
Copy link

This PR adds new option pattern which can be used in actions, e.g. prepare-commit-msg hook. It allows to not just prepend the subject of the commit msg with the ticket number, but also allows to add delimiters (here a colon) or other text.

Example:

Branch: feature/ABC-123-my-refactoring-branch
Commit-Message (before hook): "Some refactoring"
Commit-Message (after hook): "ABC-123: Some refactoring"

{
    "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\InjectIssueKeyFromBranch",
    "options": {
          "regex": "(([A-Z]+-[0-9]+))",
          "pattern": "$1:",
          "into": "subject",
          "mode": "prepend",
          "force": false
    }
}

Copy link
Collaborator

@sebastianfeldmann sebastianfeldmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Thanks

@sebastianfeldmann sebastianfeldmann merged commit ead171f into captainhookphp:main Jan 16, 2025
6 checks passed
@sebastianfeldmann
Copy link
Collaborator

I cleaned up a mess I created there as well and moved some comment detection functionality to the git library.

During this I found a magic space appearing even if prefix is empty.
I fixed that and now if you want that space you have to explicitly configure it.

So if you do not configure a pattern and no prefix or suffix I still add the "magic" space.
But if you configure anything you now have to take care of all the spaces.

So you need to include the space in the pattern config as seen below.

{
    "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\InjectIssueKeyFromBranch",
    "options": {
          "regex": "(([A-Z]+-[0-9]+))",
          "pattern": "$1: ",
          "into": "subject",
          "mode": "prepend",
          "force": false
    }
}

@sebastianfeldmann
Copy link
Collaborator

I just released version5.24.3 with your addition.

Thanks again 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants