Repository navigation
[code-simplifier] refactor(reactions): extract parseBoolReactionField helper - #31856
Conversation
…duplication The three identical boolean-field parsing blocks in parseReactionConfig (issues, pull-requests, discussions) are replaced by a shared helper function, eliminating the DRY violation while preserving all behaviour. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/q optimize |
|
🎩 Mission equipment ready! Q has optimized your workflow. Use wisely, 007! 🔫 |
There was a problem hiding this comment.
Pull request overview
This PR refactors parseReactionConfig by extracting the repeated boolean-field parsing logic for reaction target flags into a shared helper, aiming to reduce duplication while preserving behavior.
Changes:
- Replaced three duplicated parsing blocks (
issues,pull-requests,discussions) with calls to a newparseBoolReactionFieldhelper. - Added
parseBoolReactionFieldto centralize defaulting-to-true behavior and consistent type error reporting.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/reactions.go |
Extracts a helper to DRY up boolean target parsing in parseReactionConfig while keeping the same defaults and error behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd based on the refactor nature of this PR — extracting a shared helper warrants verifying the helper's contract is tested directly.
Key Themes
- Missing unit test for the new helper:
parseBoolReactionFieldis now the single source of truth for all three boolean fields, but it has no dedicated unit test. The behaviour (absent→true, non-bool→error) is currently only verified indirectly throughparseReactionConfigintegration paths.
Positive Highlights
- ✅ Excellent DRY refactor — three near-identical 7-line blocks collapsed to three 3-line call sites
- ✅ Helper signature is minimal and easy to reason about
- ✅ Error messages preserve field-name interpolation, keeping them identical to the originals
- ✅ Default-
true-on-absence semantics are clearly documented in the function comment - ✅ PR description is thorough and the testing checklist shows the author verified behaviour was preserved
Verdict
COMMENT — The refactor is clean and correct. The one suggestion (add a small unit test for parseBoolReactionField) is a low-effort improvement that would make the helper's contract self-documenting. Not blocking.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · ● 3.7M
|
|
||
| // parseBoolReactionField reads a boolean field from a reaction config map. | ||
| // Returns true if the key is absent (defaults to enabled), or the parsed bool value. | ||
| func parseBoolReactionField(m map[string]any, key string) (bool, error) { |
There was a problem hiding this comment.
[/tdd] parseBoolReactionField is a newly extracted helper with its own logic (absent-key default, type assertion, error formatting), but it has no dedicated unit tests. Since it is now the single authoritative source for all three boolean fields, a small table-driven test would make the contract explicit and guard against future drift.
Consider adding to reactions_test.go:
func TestParseBoolReactionField(t *testing.T) {
tests := []struct {
name string
m map[string]any
key string
want bool
wantErr bool
}{
{"absent key defaults to true", map[string]any{}, "issues", true, false},
{"explicit true", map[string]any{"issues": true}, "issues", true, false},
{"explicit false", map[string]any{"issues": false}, "issues", false, false},
{"non-bool value", map[string]any{"issues": "yes"}, "issues", false, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseBoolReactionField(tt.m, tt.key)
if tt.wantErr {
assert.Error(t, err, "expected error for non-bool value")
} else {
assert.NoError(t, err)
assert.Equal(t, tt.want, got)
}
})
}
}This keeps the helper's semantics explicit and protects against accidental behaviour changes.
Code Simplification - 2026-05-13
This PR simplifies recently modified code to improve clarity, consistency, and maintainability while preserving all functionality.
Files Simplified
pkg/workflow/reactions.go- Extracted shared helper to eliminate three identical boolean-field parsing blocksImprovements Made
Reduced Duplication (DRY)
The
parseReactionConfigfunction contained three nearly identical blocks for parsing theissues,pull-requests, anddiscussionsboolean fields:Extracted into a shared helper:
Changes Based On
Recent changes from:
22cc7fb- Add immediate centralized command reactions and propagate desired reaction context (Add immediate centralized command reactions and propagate desired reaction context #31847)Testing
go test -run TestReaction ./pkg/workflow/)make build)make fmt)TestCommentOutProcessedFieldsInOnSection,TestWasmGolden_CompileFixtures) exist onmainand are unrelated to this changeReview Focus
Please verify:
truewhen the key is absentkey)parseReactionConfigAutomated by Code Simplifier Agent - analyzing code from the last 24 hours