Skip to content

Validate pr template regexes up front, and stop recursive matches panicking - #855

Merged
michaeljguarino merged 2 commits into
mainfrom
robust-pr-regexes
Dec 2, 2026
Merged

michaeljguarino merged 2 commits into
mainfrom
robust-pr-regexes

Conversation

@plural-copilot

@plural-copilot plural-copilot Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

A pull request automation whose regex was (image: (.*) failed every pull request it created, and the user only saw an opaque error in console. Two problems in pkg/pr:

  • Regexes compiled lazily, mid-apply. Regex replacements ran first and file updates per file during the directory walk, so an invalid pattern failed halfway through, after earlier files had already changed. The error was Go's bare error parsing regexp: ..., naming neither the field nor which replacement it came from.
  • The recursive match strategy panicked. An invalid regex after the first panicked out of ReplaceAllFunc instead of returning an error.

Changes

  • Apply compiles every regex the updates use (regexReplacements[].regex, files, regexes), rendered the way applying them renders them, after Lua (which can change the spec) and before anything is written. Errors name the field and the pattern, e.g.
    updates.regexReplacements[1].regex "(image: (.*)" isn't a valid regular expression: missing closing )
  • recursiveReplace returns a nested error instead of panicking.
  • No behavior change for valid automations. Templating of regexes and file patterns works exactly as before, now through one shared helper.

Test Plan

  • New TestApplyRejectsInvalidRegexes covers each field, a templated regex checked as rendered, PCRE-only syntax RE2 rejects, and an invalid regex after the first in a recursive match. Every case asserts the working tree is untouched.
  • go test ./pkg/pr/ passes; golangci-lint reports 0 issues.

Console ships the CLI as a release binary (CLI_VERSION in its Dockerfile), so it picks this up once a release includes it and the pin is bumped. The console side is in pluralsh/console#4775.

🤖 Generated with Claude Code

…icking

An automation's regexes were compiled lazily while applying it: regex
replacements first, file updates per file during the walk. An invalid one
failed halfway, after earlier files had changed, with Go's bare "error
parsing regexp" naming neither the field nor the replacement. With the
recursive match strategy, an invalid regex after the first panicked out of
ReplaceAllFunc.

* Apply compiles every regex the updates use (regexReplacements, files and
  regexes, rendered the way applying them renders them) after Lua and before
  anything is written, and reports e.g.
  updates.regexReplacements[1].regex "(image: (.*)" isn't a valid regular
  expression: missing closing )
* recursiveReplace returns a nested error instead of panicking

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The changes affect PR-template application in working directories.

The PR appears safe to merge, with a non-blocking request to test the recursive error fix directly.

Findings

  1. P2 Recursive error fix goes untested ▶

Summary

This PR checks update regexes after Lua runs and before file changes begin.

  • PR automation checks update regexes before it changes files.
  • Recursive matches return nested regex errors instead of panicking.

The only finding is a missing direct test for the recursive error fix. No blocking behavior or security issue was found.

Reviews (1) · Last reviewed commit: "Validate pr template regexes up front, a..." · Reviewed by Greptile

Comment thread pkg/pr/validate_test.go Resolved
Apply rejects invalid regexes up front now, so TestApplyRejectsInvalidRegexes
never reaches recursiveReplace. Call it directly with a matching first
pattern and an invalid second one: it returns the error without panicking
and leaves the input unchanged (the test fails against the old panic).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaeljguarino michaeljguarino added the bug-fix This pull request fixes a bug label Dec 2, 2026
@michaeljguarino
michaeljguarino merged commit 7cf3124 into main Dec 2, 2026
15 of 16 checks passed
@michaeljguarino
michaeljguarino deleted the robust-pr-regexes branch December 2, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix This pull request fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant