
WHAT IS IT?
Codefather protects your codebase by controlling who can change what. Set authorization levels, lock down files, and enforce your rules—offline via CLI or online with GitHub Actions.
ℹ️ The documentation is also available on our website!
FEATURES
Files and folders protection | ✅ | ✅ |
Github Action | ✅ | ✅ |
Auto-assign reviewers | ✅ | ✅ |
Supports teams | ✅ | ✅ |
CLI + pre-commit | ✅ | ❌ |
Roles hierarchy | ✅ | ❌ |
Custom messages | ✅ | ❌ |
Godfather vibe | ✅ | ❌ |
SCREENSHOTS
INSTALLATION
npm install @donedeal0/codefather --save-dev
USAGE
Codefather has 4 commands:
codefather
codefather-init
codefather-init -- --json
codefather-github
You can either add a script shortcut in your package.json
(recommended):
"scripts": {
"codefather": "codefather",
}
Or directly run the commands with npx
:
npx codefather
npx codefather-init
CONFIG
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", emailPrefix: "luca.brasi" },
],
rules: [
{
match: ["package.json", "src/core/**", /^src\/app\/.*\.css$/],
goodfellas: [
{ name: "solozzo" },
{ name: "@tomhagen", emailPrefix: "tom.hagen" },
],
crews: ["clemenzaPeople"],
allowForgiveness: false,
},
{
match: ["src/models/**"],
goodfellas: [
{ name: "mike", emailPrefix: "michael.corleone" },
{ name: "sonny", emailPrefix: "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 {
caporegimes?: GitUser[];
rules: CodefatherRule[];
options?: {
showAscii?: boolean;
vouchForAllCommitters?: boolean;
};
codeReviews?: {
autoAssignGoodfellas: boolean;
autoAssignCaporegimes: boolean;
};
crews?: Record<CrewName, GitUser[]>;
}
A Rule
defines which users can change a set of files.
type CodefatherRule {
match: Array<RegExp | string>;
goodfellas: GitUser[];
crews?: CrewName[];
message?: string;
allowForgiveness?: boolean;
}
A GitUser
is a developer in your codebase:
type GitUser = {
name?: string;
emailPrefix?: string;
};
You can use either the name, the email, or both, depending on your preference. The name should match your GitHub username (e.g. @tom.hagen
). If you prefer the email, it should also be tied to your Github account.
For security reasons, only the email prefix is allowed in your config (e.g. johnny.fontane@jazz.com
should be johnny.fontane
).
In CLI mode, the name and email are retrieved from your Git config. You can set them like this:
git config --global user.username "DonCorleone"
git config --global user.email "vito.corleone@nyc.com"
You can verify the current values like this:
git config user.username
git config user.email
In a Github Action, codefather
will use Github's API, so you don't have to worry about the git config.
A CrewName
is the name of a developers team
type CrewName = string;
GITHUB ACTION
Add this code in your .github/workflows/codefather.yml
(the file name is up to you). The GITHUB_TOKEN
will be automatically injected by Github.
name: Codefather Validation
on:
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: write
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Run Codefather
run: npx codefather-github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
🛡️ ENFORCE REVIEWS
To enforce reviews from codeowners (goodfellas, caporegimes and crews), consider enabling branch protection in your repository settings. To do it:
- Go to
settings
- Click on
Branches
on the left sidebar
- Select
Add classic branch protection rule
- Check
Require a pull request before merging
Require approvals
- You're now under the protection of the Codefather.
GLOSSARY
Codefather uses the Godfather's lingo. Although you don't need to know it to use the library, here are the definition of the special words used in the config file:
caporegime
: a captain who leads a group of mafia members. It's a tech-lead.
goodfella
: an appellation for a mobster (like "wise-guy" or "made man"). It's a developer.
CODEFATHER VIBE
We believe open source libraries should be both useful and entertaining. The Don will amuse you with over 100 personalized reactions to your commits—whether you trespassed the rules, flirted with the limits, or respected the codebase like an honorable developer.
This being said, if you don't like the gangster movie atmosphere and still want to use codefather
, you can absolutely opt-out by providing your own custom messages and hiding the Don's face in the terminal.
CREDITS
DoneDeal0 | talk.donedeal0[at]gmail.com
SUPPORT
If you or your company uses Codefather, please show your support by becoming a sponsor! Your name and company logo will be displayed on the README.md
.
Premium support is also available. https://github.com/sponsors/DoneDeal0
CONTRIBUTING
Issues and pull requests are welcome!