A diff risk summariser
Why it matters Reviewers skim. A one-line summary at the top of a pull request ("touches a migration, weakens tests") tells them where to slow down, and it is the same every time, unlike asking a chat to "review this diff".
Your team writes down its review rules and wants a tool that applies them to a unified diff (the output of git diff). Each file in the diff is a section that starts with a diff --git a/OLD b/NEW line. Header lines follow (index, ---, +++, new file mode, deleted file mode, rename from/to, similarity index, Binary files ... differ). After the first @@ line of a section, every line is content: + added, - removed, a space for context.
Real diffs are messier than the textbook one. A pure rename has no ---/+++ lines and no content. A binary file has neither. A deleted file's +++ line says /dev/null. And a removed SQL comment, -- old note, appears in the diff as --- old note.
Write risk_summary(diff). A file's path is NEW from its diff --git line, or OLD if the section has a deleted file mode line. Paths have no spaces. Return a dict from category to the sorted list of paths in it (leave out empty categories):
schema: a directory in the path is namedmigrations, or the file name ends in.sql.secrets: an added line containspassword,secret,api_keyortoken, in any case.tests-weakened: a test file (name starts withtest_, or a directory is namedtests) that is deleted, or has more removed than added lines containingassert.dependencies: the file name isrequirements.txt,pyproject.toml,package.jsonorpackage-lock.json.config: the file name ends in.yml,.yaml,.inior.env, or issettings.py.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.