- Notifications
You must be signed in to change notification settings - Fork8.8k
DEV: Refactor automation Update service per PR #36458 feedback#36771
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
Addresses code review feedback to improve the automation Update serviceby following Discourse service best practices and extracting complexlogic into a dedicated action class.Changes:- Extract logging logic to `DiscourseAutomation::Action::LogAutomationUpdate` action class, removing utility methods from the service (per service guidelines that discourage utility methods in services)- Use `model` step for `previous_state` instead of regular step- Simplify `capture_previous_state` using `slice` and `merge`- Pass `previous_state` as explicit parameter to `log_action`- Remove unused `params` from `apply_forced_triggerable`- Simplify attributes building with `symbolize_keys.slice().compact_blank`- Simplify save logic: `save!(validate: context[:clear_trigger].blank?)`- Use `index_with` for building change hashes in action class- Use `have_attributes` matcher in request specs- Simplify boolean checks with `value.in?([true, false])`References:- PR feedback:#36458- Service objects guide:https://meta.discourse.org/t/using-service-objects-in-discourse/333641
Flink left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Just small comments, otherwise 👍
Uh oh!
There was an error while loading.Please reload this page.
plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rbShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
plugins/automation/spec/services/discourse_automation/update_spec.rb OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
plugins/automation/app/services/discourse_automation/action/log_automation_update.rb OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
e701375 intomainUh oh!
There was an error while loading.Please reload this page.
Addresses code review feedback to improve the automation Update service by following Discourse service best practices and extracting complex logic into a dedicated action class.
Changes:
DiscourseAutomation::Action::LogAutomationUpdateaction class, removing utility methods from the service (per service guidelines that discourage utility methods in services)modelstep forprevious_stateinstead of regular stepcapture_previous_stateusingsliceandmergeprevious_stateas explicit parameter tolog_actionparamsfromapply_forced_triggerablesymbolize_keys.slice().compact_blanksave!(validate: context[:clear_trigger].blank?)index_withfor building change hashes in action classhave_attributesmatcher in request specsvalue.in?([true, false])References: