Repository navigation
Tolerate bad options in a repo's patchback.yml - #76
Draft
aiolibsbot wants to merge 1 commit into
Draft
aiolibsbot wants to merge 1 commit into
aiolibsbot wants to merge 1 commit into
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Unknown and ill-typed options in a repo's
.github/patchback.ymlnow fall back totheir 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 intoPatchbackConfig(**raw). One key the App doesn't recognise — a typo, or an optionfrom a newer patchback — raised
TypeErrorout of the webhook handler, and it did sobefore 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.0as a float and a barebackport_branch_prefix:line asNone; 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)returnsusable kwargs plus human-readable warnings. Unknown keys get a
difflib-based "did you mean" hint; ill-typed ones are dropped so the defaultapplies.
boolis checked in both directions, since it subclassesintand YAMLturns
yes/oninto booleans.attr.fields()rather than a hand-written schema, so options addedlater — 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.
config.pydoesthe one line of attrs introspection.
PullRequestReporterappends the warnings to every summary it renders. That's oneplace covering all six exit paths of
process_pr_backport_labels, failuresincluded — 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), stdlibonly, 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 adjacentargument appends — every conflict resolves to "keep both lines". Independent of #72
and #73, and deliberately re-uses the
pytest.ini+ CI workflow they introduce ratherthan 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