Extract duplicate expires preprocessing logic into shared helper#14899
Extract duplicate expires preprocessing logic into shared helper#14899
Conversation
…elper Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR successfully extracts duplicate expires field preprocessing logic from parseIssuesConfig and parseDiscussionsConfig into a shared helper function preprocessExpiresField() in config_helpers.go. The refactoring eliminates ~38 lines of duplicate code by consolidating identical logic for parsing, normalizing, and handling the expires configuration field.
Changes:
- Added
preprocessExpiresField()helper function that handles expires field parsing (integers, strings, boolean false), normalization to hours, in-place updates toconfigData["expires"], and logging - Updated
parseIssuesConfigandparseDiscussionsConfigto use the new helper, replacing ~20 lines of duplicate code in each function with a single function call - Added comprehensive unit tests (118 lines) covering all scenarios: valid formats (integers, string specs), explicit disablement (false), invalid values, edge cases (nil configData, missing field)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/workflow/config_helpers.go | Added preprocessExpiresField() helper function with complete documentation, proper nil handling for logger parameter, and logic identical to original implementation |
| pkg/workflow/create_issue.go | Replaced 20-line duplicate preprocessing block with single call to preprocessExpiresField(configData, createIssueLog) |
| pkg/workflow/create_discussion.go | Replaced 20-line duplicate preprocessing block with single call to preprocessExpiresField(configData, discussionLog) |
| pkg/workflow/config_parsing_helpers_test.go | Added comprehensive TestPreprocessExpiresField with 10 test cases covering all value types, edge cases, and validation of both return value and in-place mutation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🔍 PR Triage ResultsCategory: refactor | Risk: medium | Priority: 45/100 Scores Breakdown
📋 Recommended Action: batch_reviewRationale: Good refactoring PR with medium priority. Can be efficiently reviewed alongside other refactoring PRs. Batch: Review Focus:
Triaged by PR Triage Agent on 2026-02-11
|
parseIssuesConfigandparseDiscussionsConfigcontained identical ~20 line blocks for expires field preprocessing (parsing, normalization to hours, disablement handling, logging).Changes
Added
preprocessExpiresField()helper inpkg/workflow/config_helpers.gofalsefor disablement)configData["expires"]in-placeUpdated
parseIssuesConfigandparseDiscussionsConfigNet: -38 lines duplicate code, +34 lines shared helper, +118 lines tests
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.