Support user prompts in Fizzy do, move parsing logic to context

This commit is contained in:
Jorge Manrubia
2025-07-01 14:06:39 +02:00
parent 0f7b45ab38
commit 93be9e945f
10 changed files with 81 additions and 33 deletions
+27
View File
@@ -28,6 +28,29 @@ class Command::Parser::Context
viewing_cards_index? || viewing_search_results?
end
def find_user(string)
if string.starts_with?("gid://")
User.find_by_id(GlobalID::Locator.locate(string).id)
else
string_without_at = string.delete_prefix("@")
User.all.find { |user| user.mentionable_handles.include?(string_without_at.downcase) }
end
end
def find_workflow_stage(string)
candidate_stages.find do |stage|
stage.name.downcase.include?(combined_arguments.downcase)
end
end
def find_tag(string)
Tag.find_by_title(string)
end
def find_collection(string)
Collection.where("lower(name) like ?", "%#{name.downcase}%").first
end
private
attr_reader :controller, :action, :params
@@ -57,4 +80,8 @@ class Command::Parser::Context
@action = route[:action]
@params = ActionController::Parameters.new(Rack::Utils.parse_nested_query(uri.query).merge(route.except(:controller, :action)))
end
def candidate_stages
Workflow::Stage.where(workflow_id: cards.joins(:collection).select("collections.workflow_id").distinct)
end
end