From dcef449ece55f9f44dc260f64989b3b7c59d71be Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Sun, 26 Mar 2023 09:46:21 -0400 Subject: [PATCH 1/8] fix broken test --- spec/use_packs_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/use_packs_spec.rb b/spec/use_packs_spec.rb index 268d871..6a5f4dd 100644 --- a/spec/use_packs_spec.rb +++ b/spec/use_packs_spec.rb @@ -672,6 +672,11 @@ def expect_files_to_not_exist(files) end it 'removes file annotations if the destination pack has file annotations' do + write_file('config/code_ownership.yml', <<~CONTENTS) + owned_globs: + - '{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx}' + CONTENTS + write_package_yml('packs/owned_by_artists', owner: 'Artists') write_file('app/services/foo.rb', '# @team Chefs') write_file('config/teams/artists.yml', 'name: Artists') From 5c00deaa41a552f829161446ace5333c89aec26c Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Sun, 26 Mar 2023 09:47:47 -0400 Subject: [PATCH 2/8] add failing test --- spec/use_packs/private/interactive_cli_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/use_packs/private/interactive_cli_spec.rb b/spec/use_packs/private/interactive_cli_spec.rb index f4a24c9..8f1024c 100644 --- a/spec/use_packs/private/interactive_cli_spec.rb +++ b/spec/use_packs/private/interactive_cli_spec.rb @@ -33,6 +33,14 @@ module INPUTS subject end + it 'allows creating a pack even if no teams are setup' do + expect(UsePacks).to receive(:create_pack!).with(pack_name: 'packs/my_new_pack', team: nil) + prompt.input << "Create\r" + prompt.input << "my_new_pack\r" + prompt.input.rewind + subject + end + it 'shows teams listed alphabetically and you can pick one with arrow keys' do write_file('config/teams/zebras.yml', 'name: Zebras') write_file('config/teams/artists.yml', 'name: Artists') From 3f235467a1d825d4ab84a72c313feefddae14c43 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Sun, 26 Mar 2023 10:26:53 -0400 Subject: [PATCH 3/8] upgrade sorbet --- Gemfile.lock | 23 ++++++++++++----------- sorbet/rbi/gems/activesupport@7.0.4.rbi | 4 +--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bf839a0..444eb4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -148,18 +148,19 @@ GEM rexml ruby-progressbar (1.11.0) smart_properties (1.17.0) - sorbet (0.5.9962) - sorbet-static (= 0.5.9962) + sorbet (0.5.10736) + sorbet-static (= 0.5.10736) sorbet-runtime (0.5.9976) - sorbet-static (0.5.9962-universal-darwin-14) - sorbet-static (0.5.9962-universal-darwin-15) - sorbet-static (0.5.9962-universal-darwin-16) - sorbet-static (0.5.9962-universal-darwin-17) - sorbet-static (0.5.9962-universal-darwin-18) - sorbet-static (0.5.9962-universal-darwin-19) - sorbet-static (0.5.9962-universal-darwin-20) - sorbet-static (0.5.9962-universal-darwin-21) - sorbet-static (0.5.9962-x86_64-linux) + sorbet-static (0.5.10736-universal-darwin-14) + sorbet-static (0.5.10736-universal-darwin-15) + sorbet-static (0.5.10736-universal-darwin-16) + sorbet-static (0.5.10736-universal-darwin-17) + sorbet-static (0.5.10736-universal-darwin-18) + sorbet-static (0.5.10736-universal-darwin-19) + sorbet-static (0.5.10736-universal-darwin-20) + sorbet-static (0.5.10736-universal-darwin-21) + sorbet-static (0.5.10736-universal-darwin-22) + sorbet-static (0.5.10736-x86_64-linux) spoom (1.1.11) sorbet (>= 0.5.9204) sorbet-runtime (>= 0.5.9204) diff --git a/sorbet/rbi/gems/activesupport@7.0.4.rbi b/sorbet/rbi/gems/activesupport@7.0.4.rbi index 93a4358..25e89de 100644 --- a/sorbet/rbi/gems/activesupport@7.0.4.rbi +++ b/sorbet/rbi/gems/activesupport@7.0.4.rbi @@ -3022,6 +3022,7 @@ class Date end Date::DATE_FORMATS = T.let(T.unsafe(nil), Hash) +Date::VERSION = T.let(T.unsafe(nil), String) module DateAndTime; end module DateAndTime::Calculations @@ -3590,11 +3591,8 @@ class Struct def as_json(options = T.unsafe(nil)); end end -Struct::CompletionJourneyData = Struct Struct::Group = Etc::Group Struct::HTMLElementDescription = Struct -Struct::Key = Struct -Struct::MenuInfo = Struct Struct::Passwd = Etc::Passwd Struct::Tms = Process::Tms From a348c61f11cb49167beb72504b4888b5d4903202 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Sun, 26 Mar 2023 10:27:16 -0400 Subject: [PATCH 4/8] Allow use_packs to work without code_ownership --- lib/use_packs/code_ownership_post_processor.rb | 13 ++++++------- .../private/interactive_cli/team_selector.rb | 3 ++- spec/use_packs_spec.rb | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/use_packs/code_ownership_post_processor.rb b/lib/use_packs/code_ownership_post_processor.rb index 65f8d4f..943773e 100644 --- a/lib/use_packs/code_ownership_post_processor.rb +++ b/lib/use_packs/code_ownership_post_processor.rb @@ -17,14 +17,13 @@ def before_move_file!(file_move_operation) relative_path_to_destination = file_move_operation.destination_pathname code_owners_allow_list_file = Pathname.new('config/code_ownership.yml') + return if !code_owners_allow_list_file.exist? - if code_owners_allow_list_file.exist? - UsePacks.replace_in_file( - file: code_owners_allow_list_file.to_s, - find: relative_path_to_origin, - replace_with: relative_path_to_destination - ) - end + UsePacks.replace_in_file( + file: code_owners_allow_list_file.to_s, + find: relative_path_to_origin, + replace_with: relative_path_to_destination + ) team = CodeOwnership.for_file(relative_path_to_origin.to_s) diff --git a/lib/use_packs/private/interactive_cli/team_selector.rb b/lib/use_packs/private/interactive_cli/team_selector.rb index f58f9c6..d078a50 100644 --- a/lib/use_packs/private/interactive_cli/team_selector.rb +++ b/lib/use_packs/private/interactive_cli/team_selector.rb @@ -6,9 +6,10 @@ module InteractiveCli class TeamSelector extend T::Sig - sig { params(prompt: TTY::Prompt, question_text: String).returns(CodeTeams::Team) } + sig { params(prompt: TTY::Prompt, question_text: String).returns(T.nilable(CodeTeams::Team)) } def self.single_select(prompt, question_text: 'Please use space to select a team owner') teams = CodeTeams.all.sort_by(&:name).to_h { |t| [t.name, t] } + return nil if teams.count == 0 team_selection = T.let(prompt.select( question_text, diff --git a/spec/use_packs_spec.rb b/spec/use_packs_spec.rb index 6a5f4dd..6edb4ce 100644 --- a/spec/use_packs_spec.rb +++ b/spec/use_packs_spec.rb @@ -618,7 +618,7 @@ def expect_files_to_not_exist(files) end describe 'CodeOwnershipPostProcessor' do - it 'modifies an application-specific file, config/code_ownership.yml, correctly' do + before do write_file('config/code_ownership.yml', <<~CONTENTS) owned_globs: - '{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx}' @@ -626,7 +626,9 @@ def expect_files_to_not_exist(files) - app/services/horse_like/donkey.rb - spec/services/horse_like/donkey_spec.rb CONTENTS + end + it 'modifies an application-specific file, config/code_ownership.yml, correctly' do write_file('app/services/horse_like/donkey.rb') write_file('spec/services/horse_like/donkey_spec.rb') write_package_yml('packs/animals') From 24ed84f41cf7eada1c2011bdd8dd8fc41b806890 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Thu, 30 Mar 2023 09:19:24 -0400 Subject: [PATCH 5/8] add failing test --- spec/use_packs_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/use_packs_spec.rb b/spec/use_packs_spec.rb index 6edb4ce..521429e 100644 --- a/spec/use_packs_spec.rb +++ b/spec/use_packs_spec.rb @@ -63,6 +63,30 @@ def expect_files_to_not_exist(files) expect(package.yml.read).to eq expected end + context 'code ownership is not yet configured' do + it 'creates a package.yml correctly' do + UsePacks.create_pack!(pack_name: 'packs/my_pack') + ParsePackwerk.bust_cache! + package = ParsePackwerk.find('packs/my_pack') + expect(package.name).to eq('packs/my_pack') + expect(package.enforce_privacy).to eq(true) + expect(package.enforce_dependencies).to eq(true) + expect(package.dependencies).to eq([]) + expect(package.metadata).to eq({}) + expect(package.directory.join(RuboCop::Packs::PACK_LEVEL_RUBOCOP_YML).read).to eq(<<~YML) + Department/SomeCop: + Enabled: true + YML + + expected = <<~EXPECTED + enforce_dependencies: true + enforce_privacy: true + EXPECTED + + expect(package.yml.read).to eq expected + end + end + context 'use packwerk is configured to not enforce dependencies by default' do it 'creates a package.yml correctly' do UsePacks.configure { |config| config.enforce_dependencies = false } From 5be915cd37264ab8062d455e67264329a8e2a011 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Thu, 30 Mar 2023 09:21:18 -0400 Subject: [PATCH 6/8] fix failing test --- lib/use_packs/private.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/use_packs/private.rb b/lib/use_packs/private.rb index a9a1d0b..dc624e6 100644 --- a/lib/use_packs/private.rb +++ b/lib/use_packs/private.rb @@ -366,13 +366,21 @@ def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_depend if existing_package.nil? should_enforce_dependenceies = enforce_dependencies.nil? ? UsePacks.config.enforce_dependencies : enforce_dependencies + # TODO: This should probably be `if defined?(CodeOwnership) && CodeOwnership.configured?` + # but we'll need to add an API to CodeOwnership to do this + if Pathname.new('config/code_ownership.yml').exist? + metadata = { + 'owner' => team.nil? ? 'MyTeam' : team.name + } + else + metadata = {} + end + package = ParsePackwerk::Package.new( enforce_dependencies: should_enforce_dependenceies, enforce_privacy: enforce_privacy, dependencies: [], - metadata: { - 'owner' => team.nil? ? 'MyTeam' : team.name - }, + metadata: metadata, name: pack_name, config: {} ) From f1eb7fec49b0baa1deebcd603153c99d60383a13 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Thu, 30 Mar 2023 09:23:34 -0400 Subject: [PATCH 7/8] fix tests --- lib/use_packs/private.rb | 2 +- spec/use_packs_spec.rb | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/use_packs/private.rb b/lib/use_packs/private.rb index dc624e6..5b4ff13 100644 --- a/lib/use_packs/private.rb +++ b/lib/use_packs/private.rb @@ -375,7 +375,7 @@ def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_depend else metadata = {} end - + package = ParsePackwerk::Package.new( enforce_dependencies: should_enforce_dependenceies, enforce_privacy: enforce_privacy, diff --git a/spec/use_packs_spec.rb b/spec/use_packs_spec.rb index 521429e..c91b356 100644 --- a/spec/use_packs_spec.rb +++ b/spec/use_packs_spec.rb @@ -13,6 +13,16 @@ def expect_files_to_not_exist(files) end end + def write_codeownership_config + write_file('config/code_ownership.yml', <<~CONTENTS) + owned_globs: + - '{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx}' + unowned_globs: + - app/services/horse_like/donkey.rb + - spec/services/horse_like/donkey_spec.rb + CONTENTS + end + before do UsePacks.bust_cache! CodeTeams.bust_caches! @@ -36,6 +46,8 @@ def expect_files_to_not_exist(files) end it 'creates a package.yml correctly' do + write_codeownership_config + RuboCop::Packs.configure do |config| config.required_pack_level_cops = ['Department/SomeCop'] end @@ -89,6 +101,7 @@ def expect_files_to_not_exist(files) context 'use packwerk is configured to not enforce dependencies by default' do it 'creates a package.yml correctly' do + write_codeownership_config UsePacks.configure { |config| config.enforce_dependencies = false } UsePacks.create_pack!(pack_name: 'packs/my_pack') expected_package = ParsePackwerk::Package.new( @@ -128,6 +141,7 @@ def expect_files_to_not_exist(files) end it 'automatically adds the owner metadata key' do + write_codeownership_config UsePacks.create_pack!(pack_name: 'packs/my_pack') ParsePackwerk.bust_cache! package = ParsePackwerk.find('packs/my_pack') @@ -138,6 +152,7 @@ def expect_files_to_not_exist(files) context 'team owner is provided' do it 'automatically adds the owner metadata key' do + write_codeownership_config write_file('config/teams/artists.yml', 'name: Artists') UsePacks.create_pack!(pack_name: 'packs/my_pack', team: CodeTeams.find('Artists')) ParsePackwerk.bust_cache! @@ -162,6 +177,8 @@ def expect_files_to_not_exist(files) let(:pack_name) { 'packs/fruits/apples' } it 'creates a package.yml correctly' do + write_codeownership_config + RuboCop::Packs.configure do |config| config.required_pack_level_cops = ['Department/SomeCop'] end @@ -643,13 +660,7 @@ def expect_files_to_not_exist(files) describe 'CodeOwnershipPostProcessor' do before do - write_file('config/code_ownership.yml', <<~CONTENTS) - owned_globs: - - '{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx}' - unowned_globs: - - app/services/horse_like/donkey.rb - - spec/services/horse_like/donkey_spec.rb - CONTENTS + write_codeownership_config end it 'modifies an application-specific file, config/code_ownership.yml, correctly' do @@ -698,10 +709,7 @@ def expect_files_to_not_exist(files) end it 'removes file annotations if the destination pack has file annotations' do - write_file('config/code_ownership.yml', <<~CONTENTS) - owned_globs: - - '{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx}' - CONTENTS + write_codeownership_config write_package_yml('packs/owned_by_artists', owner: 'Artists') write_file('app/services/foo.rb', '# @team Chefs') From 9f3a5abcbeab77129871801c92f91db40b247941 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Thu, 30 Mar 2023 09:25:28 -0400 Subject: [PATCH 8/8] bump version --- Gemfile.lock | 17 +++++++++-------- use_packs.gemspec | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 444eb4a..34dfbc8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GIT PATH remote: . specs: - use_packs (0.0.13) + use_packs (0.0.14) code_ownership colorize packs @@ -53,11 +53,11 @@ GEM smart_properties builder (3.2.4) byebug (11.1.3) - code_ownership (1.29.2) + code_ownership (1.32.2) code_teams (~> 1.0) packs sorbet-runtime - code_teams (1.0.0) + code_teams (1.0.1) sorbet-runtime coderay (1.1.3) colorize (0.8.1) @@ -78,10 +78,10 @@ GEM nokogiri (1.13.10) mini_portile2 (~> 2.8.0) racc (~> 1.4) - packs (0.0.5) + packs (0.0.6) sorbet-runtime parallel (1.22.1) - parse_packwerk (0.18.0) + parse_packwerk (0.18.2) sorbet-runtime parser (3.1.2.0) ast (~> 2.4.1) @@ -133,7 +133,7 @@ GEM unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.21.0) parser (>= 3.1.1.0) - rubocop-packs (0.0.33) + rubocop-packs (0.0.34) activesupport packs parse_packwerk @@ -142,7 +142,7 @@ GEM sorbet-runtime rubocop-rspec (2.13.2) rubocop (~> 1.33) - rubocop-sorbet (0.6.11) + rubocop-sorbet (0.7.0) rubocop (>= 0.90.0) ruby-graphviz (1.2.5) rexml @@ -191,8 +191,9 @@ GEM unparser (0.6.5) diff-lcs (~> 1.3) parser (>= 3.1.0) - visualize_packwerk (0.0.6) + visualize_packwerk (0.1.2) code_ownership + packs parse_packwerk rake ruby-graphviz diff --git a/use_packs.gemspec b/use_packs.gemspec index f4ee043..1ffedc9 100644 --- a/use_packs.gemspec +++ b/use_packs.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'use_packs' - spec.version = '0.0.13' + spec.version = '0.0.14' spec.authors = ['Gusto Engineers'] spec.email = ['dev@gusto.com']