在Azure DevOps Git中强制分支命名约定 [英] Force a branch naming convention in Azure DevOps Git

查看:223
本文介绍了在Azure DevOps Git中强制分支命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将Azure DevOps中托管的Git用于所有源代码.到目前为止,我们已经使用Git Hooks确保团队成员遵循分支命名约定{branchtype}/{username}/{friendlyname}/{workitemtype}{workitemid}.

We use Git hosted in Azure DevOps for all of our source code. So far we have used Git Hooks to ensure that team members follow a branch naming convention {branchtype}/{username}/{friendlyname}/{workitemtype}{workitemid}.

示例:

  • dev/dparkar/addauth/ta123456
  • hf/jsmith/memoryleak/bu11111

分支命名约定使我们可以清楚地了解它是常规开发分支还是修补程序分支,以及与之关联的工作项.

The branch naming convention allow us to clearly understand whether it's a regular development branch or a hotfix branch and which work item it is associated with, among other things.

要在本地设置Git Hooks,要求团队成员在开始贡献之前在本地运行脚本.这很好,因为脚本除了设置Git Hooks之外还进行了其他设置.但是我们不再需要其他设置,因此我们希望完全删除该脚本.

To setup Git Hooks locally, team members were required to run a script locally before starting to contribute. This was fine as the script was doing additional setup besides just setting up Git Hooks. But we don't need that additional setup anymore and therefore we are looking to remove the script completely.

有没有办法在服务器端强制使用分支命名约定?

Is there a way to force branch naming conventions on the server side?

我注意到有拉请求状态服务器,但想知道是否仅需要在Azure DevOps中配置一些OOTB.

I noticed there is documentation for Pull Request Status Server, but was wondering if there is something OOTB which just needs to be configured in Azure DevOps.

推荐答案

git钩子有两种:

  • 客户端挂钩,适用于本地git repo.
  • 服务器端挂钩,适用于远程仓库(如您所用的VSTS git repo).
  • Client-side hooks, works for the local git repo.
  • Server-side hooks, works for the remote repo (VSTS git repo as you used).

有关git hooks的更多详细信息,您可以参考自定义Git- git book中的Git Hooks .

More details about git hooks, you can refer Customizing Git - Git Hooks in git book.

目前,VSTS git repo仅支持客户端挂钩(例如预推送挂钩,预提交挂钩等).

For now, only client-side hooks (such as pre-push hook, pre-commit hook etc) are supported for VSTS git repo.

服务器端挂钩暂时不可用(但已在我们的积压中)用于VSTS git repo,您​​也可以在

The Server-side hooks is not available for now (but already in our backlog) for VSTS git repo, you can also find it in this user voice. Once server-side hooks are available in future, such as you can use pre-receive hook (or post-receive hook) to check and force convert branch name in remote repo.

此外,您问题中的链接使用的是VSTS web钩子,它与git钩子完全不同.当然,您可以检查并通过Web挂钩强制转换分支名称,但是您可以在其他网站上接收信息并转换分支名称.详细步骤如下:

Besides, the link in your question is using VSTS web hook which is quite different from git hooks. And of course you can check and force convert branch name by web hook, but you additional website to receive information and convert branch name. Detail steps as below:

在VSTS服务中添加Web钩子钩子选项卡->通过代码推送事件触发->输入您自己的网站网址->测试->确保它可以成功连接->完成.

Add a web hook in VSTS service Hooks Tab -> Trigger by code push event -> input your own website url -> Test -> make sure it can connect successful -> Finish.

将新更改推送到VSTS git repo后,将触发Web挂钩,并将信息发送到您的网站.然后,您可以在网站中检查并转换分支名称,然后再次推送.

Once new changes are pushed to VSTS git repo, the web hook will be triggered, and send information to your website. Then you can check and convert branch name in your website and push again.

这篇关于在Azure DevOps Git中强制分支命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆