Configuration

At the root of your repository, add a codefather.ts or codefather.json file (you can also use npx codefather-init):

import type { CodefatherConfig } from "@donedeal0/codefather";

export default {
  caporegimes: [{ name: "solozzo" }, { name: "lucabrasi" }],
  rules: [
    {
      match: ["package.json", "src/core/**", /^src\/app\/.*\.css$/],
      goodfellas: [{ name: "solozzo" }, { name: "tomhagen" }],
      crews: ["clemenzaPeople"],
      allowForgiveness: false,
    },
    {
      match: ["src/models/**"],
      goodfellas: [{ name: "mike" }, { name: "sonny" }],
      allowForgiveness: true,
      message: "Custom message to tell you to NOT TOUCH THE MODELS!",
    },
  ],
  options: {
    showAscii: true,
    vouchForAllCommitters: true,
  },
  codeReviews: {
    autoAssignGoodfellas: true,
    autoAssignCaporegimes: true,
  },
  crews: {
    clemenzaPeople: [{ name: "paulieGatto" }, { name: "lucabrasi" }],
  },
} satisfies CodefatherConfig;

⚙️ Here's how it works.

The CodefatherConfig allows you to control which users can modify parts of your codebase, and to refine the behavior of codefather.

A Rule defines which users can change a set of files.

Name format

The names should match the GitHub usernames (e.g., tomhagen). In CLI mode, your name will be retrieved from your Git configuration. You can set it like this:

You can verify the current value like this:

In a Github Action, codefather will use Github's API, so you don't have to worry about the git config.

How to write rules

  • Match all files in a folder (recursively): src/myfolder/

  • Match a specific file: src/myfolder/file.ts

  • Match files by extension in a folder (glob): src/folder/*.css

  • Match files by extension in a folder (regex): /^src\/folder\/.*\.css$/

  • Match any file in any subfolder: src/**

  • Match dotfiles: .env

  • Use * for single-level matches, ** for recursive matches

ℹ️ More examples are available in the test files. Codefather's matching patterns follow classic file matcher rules, like GitHub CODEOWNERS.

Pre-commit

If you have HUSKY installed, you can add the npm run codefather command in the .husky/pre-commit file.

Last updated