Porting the Release Notes Script
In this lesson, you ported the team lead’s Python release notes script to JavaScript, all but the lines that list the tickets other commits mention, then checked the port’s output against Python’s, line by line.
- Every Friday, the lead’s script turns the week’s git log into eleven lines for the team chat: the release tag, a line per ticket commit, and the other commits. The team’s tooling now runs on Node, so the script moves to JavaScript. Most porting slips still run, printing wrong lines: five spots need care.
- The docstring becomes a JSDoc block, and
import regoes: regular expressions are built into JavaScript. The settings keep their capitals as constants, one per line. The log’s triple quotes turn into backticks. The port drops Python’s backslash, so the template literal keeps the first line break. That’s harmless: no pattern matches an empty line. COMMITbecomes a regex literal, and the pattern between the slashes carries over. Only the named groups change: they lose Python’sP. Keep it, and JavaScript stops on a SyntaxError before printing a line. The flags follow the closing slash:mfor multiline, as in Python, andg, without whichmatchAll()throws a TypeError.DATEports the same way, with no flags.TICKETandREFERENCEstart fromTEAM, sonew RegExp()builds them from a template literal.String.rawkeeps its backslashes, as Python’s raw f-string does. A plain template literal would turn\dintod, and every commit would land under “Other commits”.re.IGNORECASEbecomesi, andREFERENCEaddsgtoo, for your exercise.- Template literals have no format specs, so the zero padding moves into
padStart(). Padding is for text, soString()turns each number into a string first. matchAll()loops over the log asfinditer()does, but it’s called on the string, with the pattern as its argument. Here,commitholds each match’s.groups, not the match. The subject’smatch()takes the pattern the same way and returns an array, indexed as in Python, ornullfor no ticket. Anullsends the commit to the others list with.push().- Python’s
match()only matches at the start; this one searches anywhere, assearch()does, soTICKETspells out^. Without it, the revert would be listed as a ticket. toUpperCase()lines up the lowercase key with the rest. Python’ssub()replaces every match, andreplace()needs thegflag to do the same: without it, the payout report’s title keeps a double space. The full stop can only match once, at the end, so itsreplace()needs nog. The first letter becomes a capital, withslice()for the rest.- The date turns around with
replace()andDATE. Its replacement names each group with$<name>, where Python writes\g<name>: keep Python’s form, and the date column printsg<day>/g<month>.padEnd(36)pads the title as:<36does. - After the loop, the port prints “Other commits:” and one line per other commit.
node --checkreads the file without running it and prints nothing when there’s no syntax error. Of the five slips, it catches only theP: a regex literal is checked with the code, where Python’sre.compile()fails only when it runs. The other four run. The port prints the same nine lines as Python’s, which adds the two “mentions” lines.
Here’s the lead’s Python script, release_notes.py:
"""Print the week's release notes from the git log."""
import re
TEAM = "PAY"
YEAR, MONTH, DAY = 2026, 11, 6
LOG = """\
0d9a6c3 2026-11-06 PAY-2330: Payout report totals off by a cent
e8b2f13 2026-11-05 Revert "PAY-2288: Cache exchange rates"
7e3f5b8 2026-11-05 Bump stripe from 14.2.0 to 14.3.0
c2d4a61 2026-11-04 PAY-2317: Add the SEPA mandate to receipts
51f7e90 2026-11-03 Merge branch 'fix/pay-2304-retry-payments'
3ab08d2 2026-11-03 pay-2304: retry failed card payments.
9c1e4b7 2026-11-02 PAY-2291: Show refunds in their own currency
"""
COMMIT = re.compile(
r"^(?P<sha>\w+) (?P<date>\S+) (?P<subject>.+)$", re.MULTILINE
)
TICKET = re.compile(rf"({TEAM}-\d+): (.+)", re.IGNORECASE)
DATE = re.compile(
r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})"
)
REFERENCE = re.compile(rf"{TEAM}-\d+", re.IGNORECASE)
print(f"Release payments-{YEAR}.{MONTH:02d}.{DAY:02d}")
others = []
for commit in COMMIT.finditer(LOG):
ticket = TICKET.match(commit["subject"])
if ticket is None:
others.append(commit)
else:
key = ticket[1].upper()
title = re.sub(r"\s+", " ", ticket[2]).strip()
title = re.sub(r"\.+$", "", title)
title = title[0].upper() + title[1:]
date = DATE.sub(r"\g<day>/\g<month>", commit["date"])
print(f"{date} {key} {title:<36}{commit['sha']}")
print("Other commits:")
for commit in others:
print(f" {commit['sha']} {commit['subject']}")
for key in REFERENCE.findall(commit["subject"]):
print(f" mentions {key.upper()}")