Skip to content

Make the backport PR title configurable - #75

Draft
aiolibsbot wants to merge 1 commit into
sanitizers:masterfrom
aiolibsbot:koan/configurable-backport-pr-title
Draft

aiolibsbot wants to merge 1 commit into
sanitizers:masterfrom
aiolibsbot:koan/configurable-backport-pr-title

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Sep 16, 2026 •

Copy link
Copy Markdown

What: adds a backport_pr_title_template option to .github/patchback.yml, with a restricted, non-str.format substitution engine.

Why: #25 asks for shorter, readable backport titles (release-drafter output, changelogs). @webknjaz's concern there was that user-defined templates are potentially harmful and that this "needs a few restricted substitutions" — that constraint is what the design below is built around.

How:

  • patchback/pr_title.py — stdlib-only (re). Only {name} spellings matching \w+ are substituted, and only when name is on an explicit allowlist: pr_number, pr_title, target_branch, base_branch, merge_commit_sha, merge_commit_sha_short. Everything else is left in the title verbatim and never evaluated, so the format-string escapes that make str.format dangerous on untrusted input — {x.__class__.__init__.__globals__}, {x[0]}, {x!r}, {x:10000000} — are inert text here, not a capability. Rendered titles are whitespace-collapsed so a YAML block template cannot smuggle newlines into a title.
  • Bad templates fail at render time, not config-parse time: an unknown placeholder rejected during get_patchback_config() would let one typo disable backporting repo-wide. Instead the handler falls back to the default template and appends the error to the check-run summary — the cherry-pick has already been pushed by then, so losing the backport over a title is the worse outcome.
  • The default is the exact title format shipped so far, so repos that set nothing see no change.

Testing: 19 tests in tests/test_pr_title.py, run with python -m pytest. They cover the default reproducing the historical title byte-for-byte, both title shapes @ssbarnea proposed in #25, every allowlisted name being renderable, the five format-string injection shapes staying literal, unknown placeholders being reported together and by name, empty/whitespace-only results, and newline collapsing. The module imports no third-party code, so the suite needs nothing but pytest.

Skipped: no title length cap (GitHub already bounds pr_title, and current titles are uncapped too) — add one if long templates show up in practice. No {{ escape hatch, since no allowlisted name can be produced accidentally. Config options still aren't documented in README.md; #57 is rewriting it, so that belongs there.

Closes #25


Quality Report

Changes: 4 files changed, 264 insertions(+), 3 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan

Adds a `backport_pr_title_template` option to `.github/patchback.yml`,
defaulting to the exact title format shipped so far, so nothing changes
for repos that do not set it.

Substitution is deliberately not `str.format`: a format string read from
repo config could walk attributes (`{x.__class__.__init__.__globals__}`)
or subscript values. Instead, only `{name}` spellings matching `\w+` are
replaced, and only when the name is on an explicit allowlist — anything
else, including every `str.format` escape, is left in the title verbatim
and never evaluated.

A template that names unknown placeholders or renders into an empty
title raises `ValueError` at render time rather than being rejected at
config-parse time. Rejecting the config would let one typo disable
backporting repo-wide; instead the handler falls back to the default
template and surfaces the error in the check run summary, after the
cherry-pick has already been pushed.

Closes sanitizers#25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify PR titles, maybe making them configurable

1 participant