首页 > 其他分享 >在.net项目中添加Husky.Net提交验证

在.net项目中添加Husky.Net提交验证

时间:2023-04-09 21:33:06浏览次数:50  
标签:commit 添加 husky dotnet Husky net Net

参考:C# 项目添加 husky - jesn - 博客园 (cnblogs.com)

官方文档:Getting Started | Husky.Net (alirezanet.github.io)

什么是Husky.net?

Husky是一款git hook(钩子)工具,让我们在git commit之前可以做一些操作,例如,代码格式化,重生生成,提交规范检查等,而Husky.net便是适用于.net平台的Husky,同时可以通过C#编写检查脚本

1.安装Husky.net

1.1当前项目安装 (推荐使用这种方式)

cd <Your project root directory>

dotnet new tool-manifest

dotnet tool install Husky

1.2全局安装

Dotnet tool install –global Husky

2.在项目中添加Husky.net

2.1进入项目根目录

 

2.2打开cmd

 

2.3cmd依次输入

dotnet new tool-manifest

dotnet tool install Husky

 

2.4然后输入

dotnet husky install

 

项目中即会添加husky文件

 

3添加一个hook

3.1依次输入

dotnet husky add pre-commit -c “echo ‘Husky.Net is awesome!’“

git add .husky/pre-commit”

 

3.2测试hook

Git提交一次

 

输出Husky.Net is awesome!表示刚才的hook添加成功

4添加commit-lint git提交检查

4.1添加commit-lint.csx检查脚本

 

内容如下

 

 

using System.Text.RegularExpressions;

 

private var pattern = @"^(?=.{1,90}$)(?:build|feat|ci|chore|docs|fix|perf|refactor|revert|style|test)(?:\(.+\))*(?::).{4,}(?:#\d+)*(?<![\.\s])$";

private var msg = File.ReadAllLines(Args[0])[0];

 

if (Regex.IsMatch(msg, pattern))

   return 0;

 

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("Invalid commit message");

Console.ResetColor();

Console.WriteLine("e.g: 'feat(scope): subject' or 'fix: subject'");

Console.ForegroundColor = ConsoleColor.Gray;

Console.WriteLine("more info: https://www.conventionalcommits.org/en/v1.0.0/");

 

return 1;

 

4.2添加commit-msg文件,目录为.husky/commit-msg

 

将其中的内容修改为

 

#!/bin/sh

. "$(dirname "$0")/_/husky.sh"

 

dotnet husky run --name "commit-message-linter" --args "$1"

echo

echo Great work!

标签:commit,添加,husky,dotnet,Husky,net,Net
From: https://www.cnblogs.com/SaoJian/p/17301106.html

相关文章

  • .NET Core 离线 生成 Tron 波场私钥和地址笔记
    NuGet引入依赖库PM>Install-PackageTron.Wallet.Net随机生成私钥和对应的地址usingTron.Wallet.Net;namespaceConsoleApp1{internalclassProgram{staticasyncTaskMain(string[]args){vartronECKey=TronECKey.GenerateKey(TronN......
  • internet域名架构的实现
    环境根域:192.168.3.109com服务器:192.168.3.110hxg.com服务器主:192.168.3.108​ 从:192.168.3.107apache主机(www.hxg.com):192.168.3.104转发服务器:192.168.3.101本地DNS服务器:192.168.3.102测试客户端:192.168.3.103配置www.hxg.com主机安装apache$y......
  • ASP.NET Core如何知道一个请求执行了哪些中间件?
    第一步,添加Nuget包引用需要添加两个Nuget包分别是:Microsoft.AspNetCore.MiddlewareAnalysis和Microsoft.Extensions.DiagnosticAdapter,前者是分析记录中间件核心代码实现后者是用来接收日志输出的,由于是用的DiagnosticSource方式记录日志,所以需要使用DiagnosticListener对象的Sub......
  • .NET Core MongoDB数据仓储和工作单元模式封装
    前言     上一章我们把系统所需要的MongoDB集合设计好了,这一章我们的主要任务是使用.NETCore应用程序连接MongoDB并且封装MongoDB数据仓储和工作单元模式,因为本章内容涵盖的有点多关于仓储和工作单元的使用就放到下一章节中讲解了。仓储模式(Repository )带来的好处是一......
  • Drone+.Net 6 实践
    1.[.drone.yml]kind:pipelinetype:dockername:deploymentplatform:os:linuxarch:amd64steps:-name:buildimage:mcr.microsoft.com/dotnet/sdk:6.0volumes:-name:dotnet-buildpath:/mnt/dotnet/appcommands:......
  • abp(net core)+easyui+efcore实现仓储管理系统——模块管理升级(六十)
    Abp(netcore)+easyui+efcore实现仓储管理系统目录abp(netcore)+easyui+efcore实现仓储管理系统——ABP总体介绍(一)abp(netcore)+easyui+efcore实现仓储管理系统——解决方案介绍(二)abp(netcore)+easyui+efcore实现仓储管理系统——领域层创建实体(三) abp(netcore)+eas......
  • Do you know the bitwise sum sample demonstrated in "Neural Networks and Deep Lea
    Doyouknowthebitwisesumsampledemonstratedin"NeuralNetworksandDeepLearning"byautor MichaelNielsen?Yes,Iamfamiliarwiththebitwisesumexampledemonstratedin"NeuralNetworksandDeepLearning"byMichaelNielsen......
  • 85-云原生操作系统-分层镜像构建并部署业务到Kubernetes集群生产案例
    在生产环境中业务迁移至Kubernetes环境都需要提前规划机房kubernetes集群部署基本步骤:机房环境搭建基础服务搭建系统迁移数据库迁移测试及联调使用服务及版本Pod地址规划端口使用统计业务迁移Nginx+Tomcat+NFS实现动静分离实现步骤:Centos基础环境镜像制作#准备安装包[root@K8s-a......
  • 回顾.NET系列:Framework、Net Core、Net 过往
    目录一、个人最近工作变化二、Framework、NetCore、.NET时过境迁Framework:爱你定格在4.8.NetFoundation:.Net变革大脑重新统一的.NET一、个人最近工作变化我经历了可能很多技术人都会经历的过程,从一名纯粹的技术人员转型成为了一名技术管理我已经不再单纯了,经历了从做好自......
  • internet网络服务
                       ......