Skip to content

Tolerate bad options in a repo's patchback.yml - #76

Draft
aiolibsbot wants to merge 1 commit into
sanitizers:masterfrom
aiolibsbot:koan/tolerant-repo-config
Draft

aiolibsbot wants to merge 1 commit into
sanitizers:masterfrom
aiolibsbot:koan/tolerant-repo-config

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Sep 16, 2026 •

Copy link
Copy Markdown

What

Unknown and ill-typed options in a repo's .github/patchback.yml now fall back to
their defaults and get reported in the check run, instead of taking the App down for
that repo.

Why

get_patchback_config() splatted the parsed YAML straight into
PatchbackConfig(**raw). One key the App doesn't recognise — a typo, or an option
from a newer patchback — raised TypeError out of the webhook handler, and it did so
before the check run and tracking comment exist. The repo just silently stopped
getting backports, with nothing for its maintainers to look at.

Mistyped values were worse, because they were accepted. YAML reads
target_branch_prefix: 1.0 as a float and a bare backport_branch_prefix: line as
None; both were interpolated verbatim into branch names.

This is the general form of the failure mode #75 fixes for one field: a repo's config
is untrusted input, and no single line of it should be able to disable backporting.

How

  • patchback/config_schema.py — coerce_config_mapping(raw, field_types) returns
    usable kwargs plus human-readable warnings. Unknown keys get a
    difflib-based "did you mean" hint; ill-typed ones are dropped so the default
    applies. bool is checked in both directions, since it subclasses int and YAML
    turns yes/on into booleans.
  • Driven off attr.fields() rather than a hand-written schema, so options added
    later — including the ones in Label the original PR once a backport lands #74 and Make the backport PR title configurable #75 — are covered with no extra work.
  • Kept dependency-free so it stays testable without the App runtime; config.py does
    the one line of attrs introspection.
  • PullRequestReporter appends the warnings to every summary it renders. That's one
    place covering all six exit paths of process_pr_backport_labels, failures
    included — which are the runs a broken config is most likely to produce.

Testing

20 new tests (tests/test_config_schema.py, tests/test_github_reporter.py), stdlib
only, passing. The loader wiring was also exercised end-to-end against real attrs.

Not done: README/docs for the config file, since #57 is rewriting it — the behaviour is
documented in the module docstring for now.


Overlaps #74 and #75 in config.py / event_handlers.py, but only as adjacent
argument appends — every conflict resolves to "keep both lines". Independent of #72
and #73, and deliberately re-uses the pytest.ini + CI workflow they introduce rather
than adding its own.


Quality Report

Changes: 6 files changed, 410 insertions(+), 10 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan

`get_patchback_config()` splatted the parsed `.github/patchback.yml`
straight into `PatchbackConfig(**raw)`. A single key the App does not
know -- a typo, or an option from a newer patchback -- raised
`TypeError` out of the webhook handler, and it did so *before* the check
run and the tracking comment exist. The repo simply stopped getting
backports with nothing anywhere for its maintainers to look at.

Mistyped values were worse because they were accepted: YAML reads
`target_branch_prefix: 1.0` as a float and a bare `backport_branch_prefix:`
line as `None`, so both got interpolated verbatim into branch names.

Unknown and ill-typed options now fall back to their defaults and come
back as warnings, which `PullRequestReporter` appends to every summary it
renders -- the failure paths included, since those are the runs a broken
config is most likely to produce.

The validation is driven off `attr.fields()` rather than a hand-written
schema, so options added later are covered without further work. It lives
in a dependency-free module to stay testable without the App runtime.

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.

2 participants