首页 > 解决方案 > 如何在网络核心解决方案中设置常规提交?

问题描述

我使用(带有 husky 包的常规提交,以确保提交名称在我的 Angular 前端应用程序中遵循正确的格式。我如何在 microsoft net core 解决方案中设置它,基于我需要 package.json 才能工作?

标签: gitgithubasp.net-corecommit

解决方案


您可以直接从命令行使用 dotnet 工具,并通过 NuGet 包添加到项目中。

使用版本化: Nuget 包版本化的来源

..或者为 pre-commit 或 post-commit 钩子设置触发器,在你自己的 hidden.git/hooks中,你可以创建自己的 commit-msg 以使用正则表达式强制执行常规提交消息。

这可能是提交消息文件中的 bash 脚本:

#!/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

您可以在 MSBuild 项目复制任务上自动执行消息提交的副本。

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

学分: https ://link.medium.com/UweMKDjZ1cb


推荐阅读