Learning center

How do you measure what a rule would block before enforcing it?

Run the ruleset in Evaluate mode for a few weeks, then sort each event it would have blocked by what it cost. The classes are wanted blocks, fixable friction and false positives. Evaluate mode is a GitHub Enterprise feature. Without it, read rule insights for active rules and estimate from history instead.

What Evaluate mode records#

A ruleset has an enforcement status. On GitHub Enterprise Cloud, the documentation lists three: Active, Disabled and Evaluate, where Evaluate means "your ruleset will not be enforced, but you will be able to monitor which actions would or would not violate rules on the 'Rule Insights' page." Using ruleset enforcement statuses The REST API reference states the plan condition plainly: "evaluate is only available with GitHub Enterprise." Create a repository ruleset The documentation for other plans lists only Active and Disabled.

The Rule Insights page shows a timeline of actions "checked against one or more rulesets" that passed, failed or were bypassed, and "If a ruleset is running in 'Evaluate' mode, you can see actions that would have passed or failed if the ruleset had been active." You can filter by ruleset, branch, actor and time period. Viewing insights for rulesets

The rule suites API returns the same events as data. Its list endpoint filters by evaluate_status, where evaluate returns "only rule suites resulting from rulesets in evaluate mode," by rule_suite_result (pass, fail, bypass or all), and by time_period, which goes up to month. Fetching one rule suite returns rule_evaluations, each with its enforcement (active, evaluate or deleted ruleset), its result and its rule_type. REST API endpoints for rule suites

Pulling the would-have-failed events#

Repository and organization rulesets can run in Evaluate mode at the same time, so scope the count to the one under trial. Find its ID first; the ID below is made up:

gh api repos/acme/payments-api/rulesets --jq '.[] | [.id, .name, .enforcement] | @tsv'
export RULESET_ID=4211

These commands then list a month of evaluate-mode rule suites for a fictional repository, acme/payments-api, and write one line for each suite that the trial ruleset evaluated: how many of its rules failed, and which:

gh api --paginate \
  "repos/acme/payments-api/rulesets/rule-suites?evaluate_status=evaluate&rule_suite_result=all&time_period=month&per_page=100" \
  --jq '.[].id' > suites.txt

while read -r id; do
  gh api "repos/acme/payments-api/rulesets/rule-suites/$id" --jq '
    [.rule_evaluations[] | select(.rule_source.id == ($ENV.RULESET_ID | tonumber))]
    | select(length > 0)
    | [(map(select(.result == "fail")) | length),
       (map(select(.result == "fail") | .rule_type) | join(","))]
    | @tsv'
done < suites.txt > trial.tsv

wc -l < trial.tsv                                   # suites the trial ruleset evaluated
awk -F'\t' '$1 > 0' trial.tsv | wc -l               # suites it would have failed
awk -F'\t' '$1 > 0 {print $2}' trial.tsv | tr , '\n' | sort | uniq -c

The export keeps passing suites too, because you need the total to compute a rate. Each rule evaluation names its rule_source, so the loop keeps only evaluations from the trial ruleset and skips suites it did not evaluate; another ruleset in Evaluate mode then changes neither the total nor the failures. The time_period filter stops at a month, so for a longer trial, run the export monthly and keep the files.

A worked friction calculation#

The numbers in this section are invented to show the arithmetic. They come from no real repository.

Suppose acme/payments-api wants to add required signed commits and required linear history to main and its release branches. It runs the ruleset in Evaluate mode for four weeks. The export shows 412 evaluated rule suites, and 57 of them would have failed. Someone then opens each of the 57 and classifies it:

ClassSuitesWhat happenedCost if enforced
Wanted block3Unsigned commits pushed to a release branch from a shared account, so nobody could tell who made themThe point of the rule: each commit is tied to the key of whoever committed it
Fixable friction46Unsigned commits from people without a signing key, and merge commits made locally and pushed to a release branchAuthor rewrites and pushes again
False positive8A deploy bot that pushes unsigned commits through the APIPushes fail until the bot is fixed or exempted

Fixable friction is the large class and the one to price. If the team estimates that rewriting and re-pushing takes an author about 15 minutes the first time and two minutes after their signing key is set up, and 19 distinct people account for the 46 events, the first-month cost is about 19 × 15 + 27 × 2 = 339 minutes, or under six hours, falling to under an hour a month afterward. The false positives have a one-time cost: fix the bot's signing or put it on the bypass list. The three wanted blocks are what the team is paying for.

The table changes the conversation. "Signed commits will slow everyone down" becomes "46 rewrites in the first month, from 19 people, most of them once." The decision can rest on whether three blocked commits from a shared account justify roughly six hours, and on whether a narrower target, release branches only, would keep the three blocks and drop most of the friction.

What the measurement does not show#

Evaluate mode counts what a rule would have stopped. It does not show whether a stopped action was harmful. That classification is human work, and the trial is only as good as the time someone spends on it.

It also measures behavior under a rule nobody can feel. Once the rule is active, people adapt: they set up signing keys, stop pushing merge commits, or ask for bypass. Friction after enforcement can differ from the trial in either direction, and bypasses become a new cost to track. Rule insights covers that too, since it lists bypassed actions, and the bypass list guide covers how to keep them visible.

Finally, rule insights records rule evaluations, which is not every kind of review policy. Whether a required check flakes or how long reviewers take to approve are questions for your CI data and for the review attention cost guide.

Without GitHub Enterprise#

On other plans, a ruleset is either Active or Disabled, and a disabled ruleset is not evaluated. Three substitutes remain. You can estimate from history: for linear history, count recent merge commits on the branch with git log --merges --since="4 weeks ago" main. You can enable the rule on a narrow target first, such as one release branch, and read its failures in rule insights, which is documented for all plans, with the dashboard view on GitHub Team and GitHub Enterprise Cloud. Viewing the rule insights dashboard Or you can widen in stages, reading the failures at each step.

The decision#

Before you enforce a new rule on a busy branch, measure it for at least two weeks, longer if releases are less frequent than that. Classify every would-have-failed event. Enforce when the wanted blocks justify the friction, narrow the target when they do not, and fix false positives at their source before you switch the ruleset to Active. The guide to signed commits covers the most common source of fixable friction in this example.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading