---

title: CODEOWNERS与变更审查治理(路径-责任-门禁)最佳实践

keywords:

  • CODEOWNERS
  • 路径匹配
  • 责任人
  • 审查门禁
  • 审计

description: 以 CODEOWNERS 定义路径到责任人的映射,并在关键路径变更时强制审查与门禁,记录审计与到期例外。

categories:

  • 文章资讯
  • 编程技术

---

实现示例

type Rule = { pattern: string; owners: string[] }
type Change = { path: string; author: string }

function match(pattern: string, path: string): boolean {
  const rx = new RegExp('^' + pattern.replace(/[.+^${}()|[\]\\]/g, r => '\\' + r).replace(/\*/g, '.*') + '$')
  return rx.test(path)
}

function ownersFor(rules: Rule[], path: string): string[] {
  const hits = rules.filter(r => match(r.pattern, path))
  if (hits.length === 0) return []
  const last = hits[hits.length - 1]
  return last.owners
}

function requireReview(rules: Rule[], changes: Change[]): { need: { path: string; owners: string[] }[] } {
  const need: { path: string; owners: string[] }[] = []
  for (const c of changes) {
    const o = ownersFor(rules, c.path)
    if (o.length > 0 && !o.includes(c.author)) need.push({ path: c.path, owners: o })
  }
  return { need }
}

审计与运行治理

  • 记录关键路径变更与责任人;未满足审查门禁阻断合并。
  • 例外需到期与审批人;产线默认拒绝未审批项。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部