Engineering 1 min read
How Afara reads ticket keys from branch names
The pre-push hook only checks branches that name a ticket. Telling "PAY-981" from "release-2024" turned out to need some care.
Afara Engineering, Engineering team
afara init installs a pre-push hook so work doesn’t reach the remote without Afara having seen it. The hook needs to know which ticket a branch belongs to, and the only place that information reliably lives is the branch name.
What we recognise
| Branch | Ticket |
|---|---|
chu-1-onboarding |
CHU-1 |
alice/PAY-981-refunds |
PAY-981 |
418-fix-totals |
#418 |
issue-418, gh-418, fix/issue_418 |
#418 |
What we don’t
The hard part is the false positives. release-2024 looks like a ticket key. So do hotfix-3, feature-12 and v-2, and a dependency bot’s lodash-4.17.21 has two candidates in one name. Afara keeps a list of common words that are never ticket prefixes, refuses version-shaped numbers, and skips dependency-bot branches entirely. A branch with no recognisable key isn’t checked at all.
What the check does
For each branch being pushed, the hook looks at the commits new to the remote, skipping merges, commits before the baseline and commits that touch no source files. If all of them have been generated, the push goes through. If not, it stops and prints the exact commands to run.
A few promises we made ourselves:
- The check is offline and adds no noticeable time to a push.
- Commits are never blocked, only pushes. Tags and branch deletions are never checked.
- Your own pre-push hook is kept and runs first.
git push --no-verifyskips it, once, with no questions.