Configuration

At the root of your repository, add a codefather.ts or codefather.json file.

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.

type CodefatherConfig {
  /** List of users authorized to modify any files in your repository. */
  caporegimes?: {name: string}[];
  /** Rules that apply to protected files and folders */
  rules: CodefatherRule[];
  /** Options to refine the output */
  options?: {
    /** If true, the codefather face will appear in the terminal. Defaults to true. */
    showAscii?: boolean;
    /** If true, all the pull request committers will be checked against the authorized users. Only used in a GitHub Action context. Defaults to true. */
    vouchForAllCommitters?: boolean;
  };
  /** Options to auto assign reviewers on Github */
  codeReviews?: {
    /** If true, goodfellas responsible for modified files will be assigned on relevant pull requests, except the committers. Defaults to true. */
    autoAssignGoodfellas: boolean;
    /** If true, caporegimes will be assigned on every pull request, except the committers. Defaults to false. */
    autoAssignCaporegimes: boolean;
  };
  /** Group users into teams. Crew names and composition are flexible in CLI mode but should match your github teams if used in a Github Action */
  crews?: Record<string, {name: string}[]>;
}

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

type CodefatherRule {
  /** List of the files or folders that can only be modified by a given list of users */
  match: Array<RegExp | string>;
  /** List of users authorized to modify the list of files or folders. */
  goodfellas: {name: string}[];
  /** List of authorized user crews (teams). The crews must be defined at the root of your config when used in CLI mode. */
  crews?: string[];
  /** The message displayed if an unauthorized user tries to modify a protected file. If empty, a random message will be generated. */
  message?: string;
  /** If true, a warning will be issued and the script will not throw an error. False by default. */
  allowForgiveness?: boolean;
}

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

 git config --global user.username "DonCorleone"

You can verify the current value like this:

git config user.username # return DonCorleone

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 any file in the repository: **

  • 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.

Last updated