Refactor: extract JsonFileHelper to eliminate duplicate JSON persistence code#159
Open
Copilot wants to merge 2 commits into
Open
Refactor: extract JsonFileHelper to eliminate duplicate JSON persistence code#159Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…nce code Co-authored-by: sunzhuoshi <592211+sunzhuoshi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate JSON file load/save methods in history/service classes
Refactor: extract JsonFileHelper to eliminate duplicate JSON persistence code
Mar 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors JSON file persistence in the AgentSupervisor WinForms app by centralizing the repeated Load/Save JSON file I/O logic into a single helper, reducing duplication across history/service classes.
Changes:
- Added
JsonFileHelperwith genericLoad<T>/Save<T>methods for JSON file persistence and consistent error logging. - Updated
NotificationHistory,ReviewRequestHistory, andReviewRequestServiceto delegate JSON persistence toJsonFileHelper. - Removed now-unused
using System.Text.Jsondirectives from the refactored classes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/JsonFileHelper.cs | Introduces centralized generic JSON load/save helpers with consistent error logging. |
| src/NotificationHistory.cs | Replaces inline JSON file persistence with JsonFileHelper calls. |
| src/ReviewRequestHistory.cs | Replaces inline JSON file persistence with JsonFileHelper calls (list-to-HashSet remains equivalent). |
| src/ReviewRequestService.cs | Replaces inline JSON file persistence with JsonFileHelper calls for review request details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Three classes (
NotificationHistory,ReviewRequestHistory,ReviewRequestService) each duplicated the same ~30-line Load/Save pattern for JSON file persistence — ~90 lines of structural repetition across 6 methods.Changes
src/JsonFileHelper.cs: Generic static helpers centralizing all JSON file I/O:Load<T>(fileName, errorContext, defaultValue)— existence check, deserialize, fallback to default on missing file or errorSave<T>(fileName, data, errorContext)— serialize withWriteIndented, write to file, log on errorNotificationHistory,ReviewRequestHistory,ReviewRequestService: Inline Load/Save bodies replaced withJsonFileHelpercalls; unusedusing System.Text.Jsonremoved from eachBefore / After
Locking strategy in callers is unchanged.
Original prompt
This section details on the original issue you should resolve
<issue_title>Duplicate Code: JSON File Persistence Load/Save Pattern in History/Service Classes</issue_title>
<issue_description>Analysis of recent commits
Assignee:
@copilotSummary
Three classes (
NotificationHistory,ReviewRequestHistory, andReviewRequestService) contain nearly identicalLoad()andSave()methods for JSON-based file persistence. This results in ~90 lines of structurally duplicated code across 6 methods in 3 files, all following the exact same pattern.Duplication Details
Pattern: JSON File Load
src/NotificationHistory.cs(lines 18–33)src/ReviewRequestHistory.cs(lines 15–30)src/ReviewRequestService.cs(lines 69–84)Pattern: JSON File Save (with lock)
src/NotificationHistory.cs(lines 36–50)src/ReviewRequestHistory.cs(lines 33–49)src/ReviewRequestService.cs(lines 86–99)Impact Analysis
Refactoring Recommendations
Extract a generic
JsonFileStore(T)utility classsrc/Persistence/JsonFileStore.csLoad(T)(string filePath)andSave(T)(string filePath, T data)methods with consistent error handlingAlternatively, extract a
PersistenceHelperstatic classLoadJson(T)andSaveJson(T)helpersImplementation Checklist
JsonFileStore(T)orPersistenceHelperutilityNotificationHistory.Load()/NotificationHistory.Save()ReviewRequestHistory.Load()/ReviewRequestHistory.Save()ReviewRequestService.Load()/ReviewRequestService.Save()Analysis Metadata
.csfiles💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.