Class: UsePackwerk::CodeOwnershipPostProcessor
- Inherits:
-
Object
- Object
- UsePackwerk::CodeOwnershipPostProcessor
- Extended by:
- T::Sig
- Includes:
- PerFileProcessorInterface
- Defined in:
- lib/use_packwerk/code_ownership_post_processor.rb
Instance Method Summary collapse
- #after_move_files!(file_move_operations) ⇒ Object
- #before_move_file!(file_move_operation) ⇒ Object
-
#initialize ⇒ CodeOwnershipPostProcessor
constructor
A new instance of CodeOwnershipPostProcessor.
Constructor Details
#initialize ⇒ CodeOwnershipPostProcessor
Returns a new instance of CodeOwnershipPostProcessor.
9 10 11 12 |
# File 'lib/use_packwerk/code_ownership_post_processor.rb', line 9 def initialize @teams = T.let([], T::Array[String]) @did_move_files = T.let(false, T::Boolean) end |
Instance Method Details
#after_move_files!(file_move_operations) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/use_packwerk/code_ownership_post_processor.rb', line 44 def after_move_files!(file_move_operations) if @teams.any? Logging.section('Code Ownership') do Logging.print('This section contains info about the current ownership distribution of the moved files.') @teams.group_by { |team| team }.sort_by { |_team, instances| -instances.count }.each do |team, instances| Logging.print " #{team} - #{instances.count} files" end if @did_move_files Logging.print 'Since the destination package has package-based ownership, file-annotations were removed from moved files.' end end end end |
#before_move_file!(file_move_operation) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/use_packwerk/code_ownership_post_processor.rb', line 15 def before_move_file!(file_move_operation) relative_path_to_origin = file_move_operation.origin_pathname relative_path_to_destination = file_move_operation.destination_pathname code_owners_allow_list_file = Pathname.new('config/code_ownership.yml') if code_owners_allow_list_file.exist? UsePackwerk.replace_in_file( file: code_owners_allow_list_file.to_s, find: relative_path_to_origin, replace_with: relative_path_to_destination ) end team = CodeOwnership.for_file(relative_path_to_origin.to_s) if team @teams << team.name else @teams << 'Unknown' end if !CodeOwnership.for_package(file_move_operation.destination_pack).nil? CodeOwnership.remove_file_annotation!(relative_path_to_origin.to_s) @did_move_files = true end end |