How we write commits and pull requests in the backend (be-*) repositories. Where branches
come from and where PRs go are covered in Branching and Promotion.
Follow these on every PR into dev, sit, a pre-prod branch or master. They’re being rolled
out as an automatic check (see How the rules are checked).
| What | Rule | Example |
|---|---|---|
| Branch | story/<TICKET>, bug/<TICKET> or hotfix/<TICKET>, cut from the latest master |
story/LM-12345 |
| PR target | Your PR goes into dev. Automation takes the change to sit and pre-prod |
story/LM-12345 → dev |
| PR title | <TICKET>: <summary>, same ticket as the branch, no environment prefix |
LM-12345: Add export filter for datasets |
| PR description | Jira link, what changed and why, how it was tested, impact | See the template and example |
| Commit message | <TICKET>: <imperative summary> |
LM-12345: Fix null region in cost query |
| Branch history | Only this ticket’s commits on top of master. Nothing from dev, sit or another ticket |
|
Merging into dev |
Squash and merge, then add the squash commit to the ticket’s Deployment Instructions (for now) | See Merging into dev |
<TICKET>: <imperative summary><TICKET>: <imperative summary>Start every commit subject with the Jira key of the branch’s ticket, a colon and a space, then a short summary in the imperative mood:
LM-12345: Add export filter for datasets ✓
LM-12345: Added export filter ✗ past tense
Fixes export filter ✗ no ticket
[LM-12345] add export filter / LM-12345 || ... ✗ old formats
Imperative means “Fix bug”, not “Fixed bug” or “Fixes bug”. A good subject completes the
sentence “If merged, this commit will…”. This also matches the messages Git writes itself for
git merge and git revert. Merge commits (e.g. merging origin/master into your branch)
don’t need the ticket prefix.
Express a single thought with each commit. That can be a very small commit (a typo fix) or a large one (moving many modules to another package). A reviewer should be able to hold the commit in their head. If you’re writing “change this and that”, split the commit.
Commits that both restructure code and change behaviour are hard to review. Put the refactoring in its own commit.
After each commit the tests should pass and the code should be safe to deploy. Don’t
half-implement something in one commit and fix it in the next. To land a failing test before its
fix, mark it pytest.mark.xfail.
Title: <TICKET>: <imperative summary>, using the same ticket as the branch. Write the
summary the way you’d write a commit subject: when the PR is squash-merged into dev, the title
should become the commit message (see Squash and merge into dev). Don’t add DEV:, SIT: or PROD:: one branch goes to every
environment, and the target branch already says which one.
LM-12345: Add export filter for datasets ✓
DEV: LM-12345: Add export filter for datasets ✗ environment prefix
LM-12345: Added export filter for datasets ✗ past tense
story/LM-12345 ✗ branch name, no summary
LM-12346: Add export filter for datasets ✗ ticket doesn't match branch story/LM-12345
Description: use this template. Keep it short, but fill in every section.
## Jira
https://aitl.atlassian.net/browse/LM-12345
## What and why
What this PR changes, and the reason for it. Link related PRs in other repositories.
## How it was tested
- Local run (LocalStack, local DBs): what you ran and checked
- Unit and integration tests: added, updated or run
- SQL: checked against the Master, Dev and SIT dumps, or "No database change"
## Impact
- Database changes or migrations:
- Config, environment variables or secrets:
- Other services or clients affected:
"None" is a valid answer for any line, but don't delete the line.
Every section maps to something the branching process already asks for: the testing section covers the local and SQL checks before the PR, and “Impact” covers the database item in the release readiness checklist.
A filled-in example:
## Jira
https://aitl.atlassian.net/browse/LM-12345
## What and why
Adds an optional `region` filter to `GET /datasets/export`. Users exporting for a single
region currently download the whole dataset and filter it in Excel. The frontend change is
in fe-ai#412.
## How it was tested
- Local run (LocalStack, local DBs): exported with and without `region`, and with an
unknown region (returns 400)
- Unit and integration tests: added `test_export_region_filter.py`; existing export tests pass
- SQL: new `WHERE region_id = %s` query run against the Master, Dev and SIT dumps; row
counts match a manual filter
## Impact
- Database changes or migrations: new index `idx_dataset_region_id` (migration `0042`)
- Config, environment variables or secrets: None
- Other services or clients affected: None; the parameter is optional, so existing callers
are unchanged
Merge PRs into dev with Squash and merge, so each PR lands as a single commit. Before you
confirm, check the commit title GitHub suggests and make it match the PR title
(<TICKET>: <summary>). GitHub only suggests the PR title when the PR has more than one commit;
for a single-commit PR it suggests that commit’s message instead. PRs from a
sub-branch into its ticket branch (e.g. story/LM-12345-api → story/LM-12345) keep normal
merge commits.
⚠️ Temporary workaround. For now, automation takes your change to
sit, and to pre-prod for production, by cherry-picking the commit(s) listed in the ticket’s Deployment Instructions. After testing on Dev, move the ticket to Ready for SIT, add the squash commit’s URL to the Deployment Instructions, then move it to SIT-Release: that’s what the automation picks up. The format and an example are in Branching and Promotion. The release automation pipeline is being changed to pick up the PRs itself. After that you won’t need to add the commit. All developers will be notified when it’s live, and this page updated.
Big PRs are hard to review, attract endless comments, conflict more and are riskier to deploy. If a PR runs past a few hundred lines, split it, for example into separate tickets, or into sub-branches of the ticket branch (see Branching and Promotion). It’s never too late to break up a PR that has become hard to review.
Open PRs as drafts so the repository owner isn’t tagged too early. Mark them “ready for review” once you believe they could go to production. Asking for early feedback on a draft is fine.
Before asking for a review:
ruff check and the pre-commit hooks. Setup is in Setting up Ruff.Exceptions: failures that already exist on master and are unrelated to your change, or when you
need the reviewer’s help with the failure. In both cases keep the PR in draft if it isn’t
production-ready, and say why the tests fail in the description.
If a time-sensitive PR is coming, tell the repository owner ahead of time. The more complex the change, the more notice they need.
Respond to every comment so the reviewer knows you’ve seen it. Often a 👍 is enough.
Say what changed since the last review, so the reviewer doesn’t reread everything:
dev: you may amend or fixup commits, but leave a
PR comment listing what changed.dev: don’t rewrite history (no rebase, amend or
force-push), because that causes duplicate commits and false conflicts on the next PR. Add new
commits, and tell the reviewer which commit to review from.For example:
Ready for another look. Changes since your last review (from commit a1b2c3d):
- Moved the region lookup into `get_region_id()`, as suggested
- Return 400 instead of 500 for an unknown region; added a test for it
- Not changed: kept the filter optional, since existing callers don't send it (see thread above)
Show your full name on the GitHub account you use for work, so commits and PRs can be traced to a person. If you’d rather not show it on a personal profile, create a separate work account.
These checks are being rolled out. Follow the rules now; the checks will catch anything missed.
pr-guardrails check will validate the branch name, target, title,
description, commit messages and branch history, and list anything to fix in the check’s
summary. At first it only warns. Later, rule errors will block the merge.master and raise a new PR.Questions about a rule or a failing check: ask the repository owner or DevOps.