【问题标题】:Validate format of GitHub "Squash and Merge" commit messages验证 GitHub“Squash and Merge”提交消息的格式
【发布时间】:2017-06-20 02:17:47
【问题描述】:

我想建立一个 GitHub 项目来使用conventional-changelog standard version 来生成它的变更日志。我们使用squash and merge 工作流程将 PR 合并到我们的主要开发分支中。

有没有一种方法可以强制压缩提交的提交消息遵循特定格式?

理想情况下,这将与 GitHub UI 很好地配合使用,例如显示为失败的检查。我意识到我可以简单地编写一个浏览器扩展来强制执行此操作,但是从事该项目的每个人都需要安装该扩展,这对于开源项目的进入门槛太高了。

【问题讨论】:

  • 可能会使用某种 git hook 吗?

标签: git github githooks changelog


【解决方案1】:

目前尚不清楚您打算将其发布在 GitHub Public 还是 Enterprise 上。我还没有尝试在 GitHub Public 上实现这一点。

在 Enterprise 上,该过程是为您有兴趣保护的特定存储库创建一个预接收挂钩。请记住,除非您愿意上传新环境,否则您的 pre-receive 挂钩可以使用的工具将受到限制。

可以在以下位置找到最佳详细信息: https://help.github.com/enterprise/2.11/admin/guides/developer-workflow/creating-a-pre-receive-hook-script/

基本上流程看起来像:

#!/usr/bin/env bash
#
DEFAULT_BRANCH=$(git symbolic-ref HEAD)

while read oldrev newrev refname; do
  # We only care about these changes to master
  if [[ "${refname}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
    exit 0
  fi

  # branch or tag got deleted
  if [ "${newrev}" = "${zero_commit}" ]; then
    continue
  fi

  # branch or tag is being created
  if [ "${oldrev}" = "${zero_commit}" ]; then
    continue
  fi

  for COMMIT_HASH in `git rev-list ${oldrev}..${newrev}`;
  do
    # Add your COMMIT_HASH scrubbing process here
    # On failure exit 1
  done
done
exit 0

【讨论】:

  • 我在公共的GitHub上也需要这个,不知道有没有可能?
  • 很遗憾没有:/ 只有 github 企业支持自定义 per-receive 挂钩 stackoverflow.com/a/36896396/1516887
猜你喜欢
  • 1970-01-01
  • 2022-07-11
  • 2016-03-01
  • 2022-08-03
  • 2021-10-22
  • 2017-09-15
  • 2018-11-01
  • 2019-10-25
  • 1970-01-01
相关资源
最近更新 更多