sensei
sensei

Reputation: 7562

How to set up conventional commits in net core solution?

I use (conventional commits with husky package to make sure commit names are following proper format with my Angular front end apps. How can I set up this in microsoft net core solution, based that I need package.json for this to work?

Upvotes: 3

Views: 2209

Answers (1)

Enver
Enver

Reputation: 53

You can use a dotnet tool directly from the command line and added to the project through a NuGet package.

Using versionize: Nuget Package, source of Versionize

..Or set a trigger for pre-commit or post-commit hook, with your own In the hidden .git/hooks, you can create your own commit-msg to enforce the conventional commit message using a regular expression.

This could be your bash script in the commit message file:

#!/usr/bin/env bash
if ! head -1 "$1" | grep -qE "^(feat|fix|ci|chore|docs|test|style|refactor)(\(.+?\))?: .{1,}$"; then
    echo "Aborting commit. Your commit message is invalid." >&2
    exit 1
fi
if ! head -1 "$1" | grep -qE "^.{1,50}$"; then
    echo "Aborting commit. Your commit message is too long." >&2
    exit 1
fi

You can automate the copies of the message commit on the MSBuild project copy task.

<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
    <ItemGroup>
        <_CustomFiles Include="..\automation\commit-msg" />
    </ItemGroup>
    <Copy SourceFiles="@(_CustomFiles)" DestinationFolder="./../.git/hooks" />
</Target>

Credits: https://link.medium.com/UweMKDjZ1cb

Upvotes: 4

Related Questions