11# This component renders the request action description based on the type of the action
22
33class BsRequestActionDescriptionComponent < ApplicationComponent
4- attr_reader :action
4+ attr_reader :action , :text_only
55
66 delegate :project_or_package_link , to : :helpers
77 delegate :user_with_realname_and_icon , to : :helpers
88 delegate :requester_str , to : :helpers
99 delegate :creator_intentions , to : :helpers
1010
11- def initialize ( action :)
11+ def initialize ( action :, text_only : false )
1212 super
1313 @action = action
14+ @text_only = text_only
1415 end
1516
1617 # rubocop:disable Metrics/CyclomaticComplexity
1718 # rubocop:disable Rails/OutputSafety
1819 # rubocop:disable Style/FormatString
1920 def description
2021 creator = action . bs_request . creator
22+
2123 source_project_hash = { project : action . source_project , package : action . source_package , trim_to : nil }
2224 target_project_hash = { project : action . target_project , package : action . target_package , trim_to : nil }
2325
24- source_container = project_or_package_link ( source_project_hash )
25- target_container = project_or_package_link ( target_project_hash )
26+ source_and_target_component = BsRequestActionSourceAndTargetComponent . new ( action . bs_request )
27+
28+ if text_only
29+ source_container = source_and_target_component . source
30+ target_container = source_and_target_component . target
31+ else
32+ source_container = project_or_package_link ( source_project_hash )
33+ target_container = project_or_package_link ( target_project_hash )
34+ end
35+
36+ source_and_target_container = source_and_target_component . combine ( source_container , target_container )
2637
2738 description = case action . type
2839 when 'submit'
29- 'Submit %{source_container} to %{target_container}' %
30- { source_container : source_container , target_container : target_container }
40+ 'Submit %{source_and_target_container}' % { source_and_target_container : source_and_target_container }
3141 when 'delete'
32- target_repository = "repository #{ link_to ( action . target_repository , repositories_path ( target_project_hash ) ) } for " if action . target_repository
42+ repository_content = text_only ? action . target_repository : link_to ( action . target_repository , repositories_path ( target_project_hash ) )
43+ target_repository = "repository #{ repository_content } for " if action . target_repository
3344
3445 'Delete %{target_repository}%{target_container}' %
3546 { target_repository : target_repository , target_container : target_container }
@@ -44,14 +55,14 @@ def description
4455 'Set %{source_container} to be devel project/package of %{target_container}' %
4556 { source_container : source_container , target_container : target_container }
4657 when 'maintenance_incident'
47- 'Submit update from %{source_container} to %{target_container }' %
48- { source_container : source_container , target_container : target_container }
58+ 'Submit update from %{source_and_target_container }' %
59+ { source_and_target_container : source_and_target_container }
4960 when 'maintenance_release'
50- 'Maintenance release %{source_container} to %{target_container }' %
51- { source_container : source_container , target_container : target_container }
61+ 'Maintenance release %{source_and_target_container }' %
62+ { source_and_target_container : source_and_target_container }
5263 when 'release'
53- 'Release %{source_container} to %{target_container }' %
54- { source_container : source_container , target_container : target_container }
64+ 'Release %{source_and_target_container }' %
65+ { source_and_target_container : source_and_target_container }
5566 end
5667
5768 # HACK: this is just a porting of the already existing way of passing the string to the view
0 commit comments