mcpField
M
mergify-config

mergify-config

github.com/mergifyio开发3273 次安装1 天前更新
代码仓库

关于 mergify-config

mergify-config 面向维护 Mergify 规则的开发者,提供配置校验与拉取请求模拟。它可按官方 JSON Schema 检查配置,并使用本地文件预览规则将触发的操作。

主要功能

  1. 01按 JSON Schema 校验配置
  2. 02模拟拉取请求上的操作
  3. 03自动检测标准位置的配置文件
  4. 04使用 --config-file 指定文件

适用场景

  1. 01在 CI 中检查配置
  2. 02提交前测试规则变更
  3. 03查看 GitHub 拉取请求的预期操作

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mergifyio/mergify-cli --skill mergify-config

安装后在 Claude Code 中输入/mergify-config确认已加载。

详细介绍

Mergify 配置管理

概述

mergify config 命令组提供用于根据官方架构验证 Mergify 配置文件,以及使用本地配置文件模拟 Mergify 在特定拉取请求上会执行哪些操作的工具。

命令

mergify config validate                              # Validate the configuration file
mergify config simulate PULL_REQUEST_URL             # Simulate actions on a PR

配置文件检测

Mergify CLI 会按以下标准位置的顺序自动检测配置文件,以第一个存在的文件为准:

  • .mergify.yml,然后是 .mergify.yaml
  • .mergify/config.yml,然后是 .mergify/config.yaml
  • .github/mergify.yml,然后是 .github/mergify.yaml

每个位置都会读取这两种扩展名;如果某个位置同时存在两种文件,则优先使用 .yml。如果仓库中有多个配置文件,CLI 会在标准错误输出中发出警告,列出正在使用的文件和被忽略的文件。引擎采用相同的顺序,因此 CLI 读取的文件与生产环境读取的文件一致。

使用 --config-file / -f 覆盖:

mergify config -f path/to/config.yml validate

验证配置(validate)

根据从 https://docs.mergify.com/mergify-configuration-schema.json 获取的官方 JSON 架构验证 Mergify 配置文件。

# Validate auto-detected config file
mergify config validate

# Validate a specific file
mergify config -f .mergify.yml validate

输出:

  • 如果有效:打印成功消息并以代码 0 退出
  • 如果无效:打印错误数量及每个错误的路径和消息,然后以代码 1 退出

在 CI 中使用:

- name: Validate Mergify config
  run: mergify config validate

模拟操作(simulate)

使用本地配置文件模拟 Mergify 在特定拉取请求上会执行哪些操作。这样,你就可以在提交前测试配置更改。

mergify config simulate https://github.com/owner/repo/pull/123

必需参数:

  • PULL_REQUEST_URL -- 要进行模拟的拉取请求的完整 GitHub URL

选项:

  • --token / -t(环境变量:MERGIFY_TOKEN)-- Mergify 凭据。如果没有,则使用 mergify auth login 保存的凭据;再没有,则使用 GITHUB_TOKEN / gh auth token,但这两种凭据已弃用于 Mergify API。
  • --api-url / -u(环境变量:MERGIFY_API_URL)-- Mergify API URL(默认值:https://api.mergify.com)

**输出:**显示标题和详细的 Markdown 摘要,说明 Mergify 使用本地配置对该 PR 会执行哪些操作。

编写和编辑配置

帮助用户编写、编辑或理解 Mergify 配置文件时,始终先获取相关文档页面。不要依赖记忆——配置格式、可用操作和条件语法会随时间变化。

文档索引

获取 https://docs.mergify.com/llms.txt,以查看包含所有可用页面及其说明的完整文档索引。

关键参考页面

编写任何配置之前,请先获取与用户请求相关的页面:

主题URL
文件格式和结构https://docs.mergify.com/configuration/file-format
条件语法和属性https://docs.mergify.com/configuration/conditions
数据类型(时长、模板)https://docs.mergify.com/configuration/data-types
配置共享与复用https://docs.mergify.com/configuration/sharing
工作流自动化概览https://docs.mergify.com/workflow
所有可用操作https://docs.mergify.com/workflow/actions
编写你的第一条规则https://docs.mergify.com/workflow/writing-your-first-rule
合并队列规则https://docs.mergify.com/merge-queue/rules
合并队列设置https://docs.mergify.com/merge-queue/setup
队列优先级规则https://docs.mergify.com/merge-queue/priority
合并保护https://docs.mergify.com/merge-protections/setup
自定义保护规则https://docs.mergify.com/merge-protections/custom-rules
合并保护示例https://docs.mergify.com/merge-protections/examples
命令和限制https://docs.mergify.com/commands
JSON Schemahttps://docs.mergify.com/mergify-configuration-schema.json

对于各个操作(assign、backport、close、comment、copy、dismiss_reviews、 edit、github_actions、label、merge、queue、rebase、request_reviews、review、 squash、update),请获取相应操作页面: https://docs.mergify.com/workflow/actions/<action_name>。

工作流
  1. 阅读用户现有的配置(如果有),了解当前状态
  2. 获取相关文档页面,了解用户需要的功能
  3. 根据文档编写或更新配置
  4. 验证:运行 mergify config validate 检查错误
  5. 模拟(可选):针对真实 PR 运行 mergify config simulate <PR_URL>,验证规则是否按预期运行

常见模式

推送前测试配置更改
# Edit your .mergify.yml locally, then:
mergify config validate
mergify config simulate https://github.com/myorg/myrepo/pull/42
# If both look good, commit and push
CI 验证门禁
jobs:
  validate-mergify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install mergify-cli
        run: pip install mergify-cli
      - name: Validate Mergify config
        run: mergify config validate

评论

支持 Markdown