Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

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 re goes: 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.

  • COMMIT becomes a regex literal, and the pattern between the slashes carries over. Only the named groups change: they lose Python’s P. Keep it, and JavaScript stops on a SyntaxError before printing a line. The flags follow the closing slash: m for multiline, as in Python, and g, without which matchAll() throws a TypeError. DATE ports the same way, with no flags.

  • TICKET and REFERENCE start from TEAM, so new RegExp() builds them from a template literal. String.raw keeps its backslashes, as Python’s raw f-string does. A plain template literal would turn \d into d, and every commit would land under “Other commits”. re.IGNORECASE becomes i, and REFERENCE adds g too, for your exercise.

  • Template literals have no format specs, so the zero padding moves into padStart(). Padding is for text, so String() turns each number into a string first.

  • matchAll() loops over the log as finditer() does, but it’s called on the string, with the pattern as its argument. Here, commit holds each match’s .groups, not the match. The subject’s match() takes the pattern the same way and returns an array, indexed as in Python, or null for no ticket. A null sends the commit to the others list with .push().

  • Python’s match() only matches at the start; this one searches anywhere, as search() does, so TICKET spells out ^. Without it, the revert would be listed as a ticket.

  • toUpperCase() lines up the lowercase key with the rest. Python’s sub() replaces every match, and replace() needs the g flag 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 its replace() needs no g. The first letter becomes a capital, with slice() for the rest.

  • The date turns around with replace() and DATE. Its replacement names each group with $<name>, where Python writes \g<name>: keep Python’s form, and the date column prints g<day>/g<month>. padEnd(36) pads the title as :<36 does.

  • After the loop, the port prints “Other commits:” and one line per other commit.

  • node --check reads the file without running it and prints nothing when there’s no syntax error. Of the five slips, it catches only the P: a regex literal is checked with the code, where Python’s re.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:

Language: Python
"""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()}")

And here’s the JavaScript port so far, release-notes/release-notes.js, without the “mentions” lines:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Every Friday, the team lead pastes the week’s git log into this Python script. It prints eleven lines for the team chat: the release tag, a line per ticket commit, and the other commits.

00:13 The tooling now runs on Node, so the script moves to JavaScript. Port it line by line and compare the output: most slips still run, printing lines that look right and aren’t.

00:25 Five spots need care. The lines listing mentioned tickets are your exercise.

00:32 The docstring becomes a JSDoc block, and the import goes. The settings keep their capitals as constants. The log’s triple quotes turn into backticks. The port drops Python’s backslash, so the template literal keeps the first line break.

00:48 That’s harmless: no pattern matches an empty line.

00:53 COMMIT becomes a regex literal, and the pattern between the slashes carries over. Only the named groups change: they lose the P that Python puts in them.

01:04 Keep it, and JavaScript stops on a SyntaxError before printing a line. The flags follow the closing slash: m for multiline, and g, without which matchAll() throws a TypeError instead of looping.

01:19 DATE ports the same way, with no flags. TICKET and REFERENCE start from the team setting, so new RegExp() builds them from a template literal.

01:30 String.raw keeps its backslashes, as Python’s raw f-string does. A plain template literal would turn backslash d into a d, and every commit would land under Other commits.

01:43 Python’s ignore-case flag becomes i. REFERENCE adds g as well, for your exercise. Template literals have no format specs, so the zero padding moves into a padStart() call.

01:58 Padding is for text, so String() turns each number into a string first. The tag prints as Python’s does, with a zero in front of the day.

02:10 matchAll() loops over the log as finditer() does, but it’s called on the string, with the pattern as its argument. Here, commit holds each match’s .groups, not the match.

02:22 The subject’s match() tries the ticket pattern the same way round, returning an array, or null when there’s no ticket. A null sends the commit to the others list.

02:33 Python’s match() only matches at the start; this one searches anywhere, as search() does. So TICKET spells out the caret.

02:41 Without it, the revert would be listed as a ticket.

02:47 toUpperCase() lines up the lowercase key with the rest. Python’s sub() replaces every match, and replace() needs the g flag to do the same.

02:57 Without it, the payout report’s title keeps a double space. The full stop only matches once, at the end, so its replace() drops it with no g.

03:09 Then the first letter becomes a capital, with slice() for the rest.

03:15 The date turns around with replace() and the DATE pattern. Its replacement names each group with a dollar sign, where Python writes backslash g.

03:24 Keep Python’s form, and the date column prints the group names instead of the dates. padEnd(36) pads the title as Python’s spec does, and console.log() prints the line.

03:39 After the loop, the port prints the heading, then loops over the others list, one line per commit. The lines listing mentioned tickets stay in Python, for your exercise.

03:52 node --check reads the file without running it and prints nothing: no syntax errors. Which of the five slips would node --check catch?

04:04 Your turn: pause the video and predict.

04:12 Only the P in the named groups. A regex literal is checked with the code, but Python’s re.compile() fails only when it runs. The other four run.

04:26 Python prints its eleven lines, and the port’s nine all match. Only the two mentions lines are missing.

04:34 A regex-heavy script ports line by line: the patterns carry over, and what changes is around them. Spell out the flags and anchors, and use String.raw to build patterns from settings.

04:47 Next up: the exercise Finish the Release Notes. You’ll add the lines listing the tickets each other commit mentions, so both scripts print the same section, for this week’s log and for last week’s.

Become a Member to join the conversation.