Git: Generate release notes

Produce the changelog section that release tools write for a new version.

What to build

A program that writes the release notes for the commits since the last release.

Requirements

  • Use the version rules of the previous exercise. Sections, in this order and only if not empty: ### BREAKING CHANGES (subjects with !, and BREAKING CHANGE: body lines, whose text after the colon and space is the entry), ### Features (feat), ### Bug Fixes (fix), ### Performance (perf). A feat with ! appears in both BREAKING CHANGES and Features.
  • Print ## vX.Y.Z (DATE) then the sections with - ENTRY lines, or only no release needed.

Input

Line 1: the current version. Line 2: the release date. Line 3: n. Then n lines, each a subject or a body line starting with BREAKING CHANGE:.

Output

The release notes.

Constraints

n ≤ 200.

Example

Input:

v1.4.2
2026-11-13
4
feat(search): add filters
fix: handle empty query
docs: explain the API
perf(db): add an index

Output:

## v1.5.0 (2026-11-13)
### Features
- add filters (search)
### Bug Fixes
- handle empty query
### Performance
- add an index (db)

Why it works

Grouping by type and listing breaking changes first tells users exactly what a release means for them, and it all comes from information already in the commits.

Examples

Example 1 · Input
v1.4.2
2026-11-13
4
feat(search): add filters
fix: handle empty query
docs: explain the API
perf(db): add an index
Expected output
## v1.5.0 (2026-11-13)
### Features
- add filters (search)
### Bug Fixes
- handle empty query
### Performance
- add an index (db)
Example 2 · Input
v1.4.2
2026-11-13
1
chore: update tools
Expected output
no release needed

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Parse each subject; collect breaking entries, features, fixes and performance entries in the order they appear.

Hint 2

An entry is the description followed by ` (SCOPE)` when there is a scope; compute the version as in the previous exercise.

Solution

Show one correct solution (try it yourself first)
import re

PATTERN = re.compile(r"^(\w+)(?:\(([a-z0-9-]+)\))?(!)?: (.+)$")
major, minor, patch = map(int, input().strip().lstrip("v").split("."))
date = input().strip()
sections = {"breaking": [], "feat": [], "fix": [], "perf": []}
for _ in range(int(input())):
    line = input()
    if line.startswith("BREAKING CHANGE:"):
        sections["breaking"].append(line.split(":", 1)[1].strip())
        continue
    m = PATTERN.match(line)
    if not m:
        continue
    kind, scope, bang, description = m.groups()
    entry = description + (f" ({scope})" if scope else "")
    if bang:
        sections["breaking"].append(entry)
    if kind in sections:
        sections[kind].append(entry)
if sections["breaking"]:
    version = f"v{major + 1}.0.0"
elif sections["feat"]:
    version = f"v{major}.{minor + 1}.0"
elif sections["fix"] or sections["perf"]:
    version = f"v{major}.{minor}.{patch + 1}"
else:
    version = None
if version is None:
    print("no release needed")
else:
    print(f"## {version} ({date})")
    for key, title in [("breaking", "BREAKING CHANGES"), ("feat", "Features"), ("fix", "Bug Fixes"), ("perf", "Performance")]:
        if sections[key]:
            print(f"### {title}")
            for entry in sections[key]:
                print(f"- {entry}")

Lesson: Pull requests and conventional commits →