-
Notifications
You must be signed in to change notification settings - Fork 336
Move review preferences from project settings to local preferences #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
98b4106
fix(recap): surface real auth/network errors instead of "sign in" hint
peyton-alt da6a6d4
fix(recap): surface keyring read errors with targeted message
peyton-alt 1a4fcb1
Merge branch 'main' into review-fix-2
peyton-alt 5052942
fix(review): store review config in local preferences
peyton-alt df11c92
fix(review): clarify local preference messaging
peyton-alt 5a9b063
review: harden migration against data loss and partial writes
peyton-alt 484acb0
review: stop nagging on every invocation and skip irrelevant flows
peyton-alt 15be354
review: tighten settings boundary and surface load-path failures
peyton-alt 6f70c5f
Merge remote-tracking branch 'origin/main' into pr-1181-review
peyton-alt 48684bf
review: harden atomic write fsync + bail migration on local-override …
peyton-alt ebde19d
Merge remote-tracking branch 'origin/main' into review-fix-local
peyton-alt 6c7c233
settings: update test for loadMergedSettings new signature after main…
peyton-alt 7b578c4
jsonutil: fsync parent dir after rename + add WriteFileAtomic tests
peyton-alt e4267cd
jsonutil: silence gosec/errcheck on best-effort parent-dir fsync
peyton-alt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| package review | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
|
|
||
| "github.com/entireio/cli/cmd/entire/cli/jsonutil" | ||
| "github.com/entireio/cli/cmd/entire/cli/paths" | ||
| "github.com/entireio/cli/cmd/entire/cli/settings" | ||
| ) | ||
|
|
||
| type projectReviewSettings struct { | ||
| path string | ||
| raw map[string]json.RawMessage | ||
| review json.RawMessage | ||
| fixAgent json.RawMessage | ||
| hasReview bool | ||
| hasFixAgent bool | ||
| } | ||
|
|
||
| func maybePromptReviewSettingsMigration( | ||
| ctx context.Context, | ||
| out io.Writer, | ||
| errOut io.Writer, | ||
| canPrompt bool, | ||
| promptYN func(context.Context, string, bool) (bool, error), | ||
| ) error { | ||
| project, ok, err := loadProjectReviewSettings(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| if !canPrompt { | ||
| fmt.Fprintln(errOut, "Review preferences are stored in project settings (.entire/settings.json). Run `entire review --edit` interactively to move them to local preferences.") | ||
| return nil | ||
| } | ||
|
|
||
| if promptYN == nil { | ||
| promptYN = realPromptYN | ||
| } | ||
| migrate, err := promptYN(ctx, "Review preferences are stored in project settings (.entire/settings.json). Move them to local preferences now?", false) | ||
| if err != nil { | ||
| return fmt.Errorf("review settings migration prompt: %w", err) | ||
| } | ||
| if !migrate { | ||
| return nil | ||
| } | ||
|
|
||
| if err := migrateProjectReviewSettings(ctx, project); err != nil { | ||
| return err | ||
| } | ||
| fmt.Fprintln(out, "Moved review preferences from project settings to local preferences.") | ||
| return nil | ||
| } | ||
|
|
||
| func loadProjectReviewSettings(ctx context.Context) (*projectReviewSettings, bool, error) { | ||
| path, err := paths.AbsPath(ctx, settings.EntireSettingsFile) | ||
| if err != nil { | ||
| path = settings.EntireSettingsFile | ||
| } | ||
|
|
||
| data, err := os.ReadFile(path) //nolint:gosec // path is resolved from repo settings path | ||
| if err != nil { | ||
| if os.IsNotExist(err) { | ||
| return nil, false, nil | ||
| } | ||
| return nil, false, fmt.Errorf("reading project settings for review migration: %w", err) | ||
| } | ||
|
|
||
| raw := map[string]json.RawMessage{} | ||
| if err := json.Unmarshal(data, &raw); err != nil { | ||
| return nil, false, fmt.Errorf("parsing project settings for review migration: %w", err) | ||
| } | ||
|
|
||
| reviewRaw, hasReview := raw["review"] | ||
| fixAgentRaw, hasFixAgent := raw["review_fix_agent"] | ||
| if !hasReview && !hasFixAgent { | ||
| return nil, false, nil | ||
| } | ||
| return &projectReviewSettings{ | ||
| path: path, | ||
| raw: raw, | ||
| review: reviewRaw, | ||
| fixAgent: fixAgentRaw, | ||
| hasReview: hasReview, | ||
| hasFixAgent: hasFixAgent, | ||
| }, true, nil | ||
| } | ||
|
|
||
| func migrateProjectReviewSettings(ctx context.Context, project *projectReviewSettings) error { | ||
| if project == nil { | ||
| return nil | ||
| } | ||
|
|
||
| prefs, err := settings.LoadClonePreferences(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("load review preferences for migration: %w", err) | ||
| } | ||
| if prefs == nil { | ||
| prefs = &settings.ClonePreferences{} | ||
| } | ||
|
|
||
| preferencesChanged := false | ||
| if project.hasReview && len(prefs.Review) == 0 && !isJSONNull(project.review) { | ||
| var review map[string]settings.ReviewConfig | ||
| if err := json.Unmarshal(project.review, &review); err != nil { | ||
| return fmt.Errorf("parsing project review settings: %w", err) | ||
| } | ||
| if len(review) > 0 { | ||
| prefs.Review = review | ||
| preferencesChanged = true | ||
| } | ||
| } | ||
| if project.hasFixAgent && prefs.ReviewFixAgent == "" && !isJSONNull(project.fixAgent) { | ||
| var fixAgent string | ||
| if err := json.Unmarshal(project.fixAgent, &fixAgent); err != nil { | ||
| return fmt.Errorf("parsing project review_fix_agent: %w", err) | ||
| } | ||
| if fixAgent != "" { | ||
| prefs.ReviewFixAgent = fixAgent | ||
| preferencesChanged = true | ||
| } | ||
| } | ||
|
|
||
| if preferencesChanged { | ||
| if err := settings.SaveClonePreferences(ctx, prefs); err != nil { | ||
| return fmt.Errorf("save review preferences for migration: %w", err) | ||
| } | ||
| } | ||
|
|
||
| delete(project.raw, "review") | ||
| delete(project.raw, "review_fix_agent") | ||
| data, err := jsonutil.MarshalIndentWithNewline(project.raw, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("marshal project settings after review migration: %w", err) | ||
| } | ||
| //nolint:gosec // G306: settings file is config, not secrets; 0o644 is appropriate | ||
| if err := os.WriteFile(project.path, data, 0o644); err != nil { | ||
| return fmt.Errorf("write project settings after review migration: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func isJSONNull(raw json.RawMessage) bool { | ||
| return bytes.Equal(bytes.TrimSpace(raw), []byte("null")) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.