From 749472d08a0bab461398cb51723320d43af8fef3 Mon Sep 17 00:00:00 2001 From: Steve Aziz <68991236+ScAziz@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:39:09 +0000 Subject: [PATCH 1/4] add before block to spec --- .../ownership_mappers/file_annotations_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb b/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb index 445648c..e4089a5 100644 --- a/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb +++ b/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb @@ -69,6 +69,19 @@ module CodeOwnership it 'can find the owner of a javascript file with file annotations' do expect(CodeOwnership.for_file('frontend/javascripts/packages/my_package/owned_file.jsx').name).to eq 'Bar' end + + context 'haml owned file' do + before do + write_configuration + write_file('config/teams/bar.yml', <<~CONTENTS) + name: Bar + CONTENTS + + write_file('packs/my_pacl/owned_file.html.haml', <<~CONTENTS) + -# @team Bar + CONTENTS + end + end end context 'javascript owned file with brackets' do @@ -89,6 +102,8 @@ module CodeOwnership end end + + describe '.remove_file_annotation!' do subject(:remove_file_annotation) do CodeOwnership.remove_file_annotation!(filename) From 3f256c8b870b45ed1644e69b63f5a1c85df39a4c Mon Sep 17 00:00:00 2001 From: Steve Aziz <68991236+ScAziz@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:48:50 +0000 Subject: [PATCH 2/4] add failing test for haml ownership --- .../file_annotations_spec.rb | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb b/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb index e4089a5..0d93f14 100644 --- a/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb +++ b/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb @@ -69,35 +69,39 @@ module CodeOwnership it 'can find the owner of a javascript file with file annotations' do expect(CodeOwnership.for_file('frontend/javascripts/packages/my_package/owned_file.jsx').name).to eq 'Bar' end + end - context 'haml owned file' do + context 'javascript owned file with brackets' do before do write_configuration write_file('config/teams/bar.yml', <<~CONTENTS) name: Bar CONTENTS - write_file('packs/my_pacl/owned_file.html.haml', <<~CONTENTS) - -# @team Bar + write_file('frontend/javascripts/packages/my_package/[formID]/owned_file.jsx', <<~CONTENTS) + // @team Bar CONTENTS end - end + + it 'can find the owner of a javascript file with file annotations' do + expect(CodeOwnership.for_file('frontend/javascripts/packages/my_package/[formID]/owned_file.jsx').name).to eq 'Bar' + end end - context 'javascript owned file with brackets' do + context 'haml owned file' do before do write_configuration write_file('config/teams/bar.yml', <<~CONTENTS) name: Bar CONTENTS - write_file('frontend/javascripts/packages/my_package/[formID]/owned_file.jsx', <<~CONTENTS) - // @team Bar + write_file('packs/my_pack/owned_file.html.haml', <<~CONTENTS) + -# @team Bar CONTENTS end - it 'can find the owner of a javascript file with file annotations' do - expect(CodeOwnership.for_file('frontend/javascripts/packages/my_package/[formID]/owned_file.jsx').name).to eq 'Bar' + it 'can find the owner of a haml file with file annotations' do + expect(CodeOwnership.for_file('packs/my_pack/owned_file.html.haml').name).to eq 'Bar' end end end From 4affcf99c115f25ce45d684eb3fa6626b06a9681 Mon Sep 17 00:00:00 2001 From: Steve Aziz <68991236+ScAziz@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:51:50 +0000 Subject: [PATCH 3/4] add haml comment pattern to TEAM_PATTERN regex --- .../private/ownership_mappers/file_annotations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/code_ownership/private/ownership_mappers/file_annotations.rb b/lib/code_ownership/private/ownership_mappers/file_annotations.rb index 9b0c908..4debcf3 100644 --- a/lib/code_ownership/private/ownership_mappers/file_annotations.rb +++ b/lib/code_ownership/private/ownership_mappers/file_annotations.rb @@ -18,7 +18,7 @@ class FileAnnotations extend T::Sig include Mapper - TEAM_PATTERN = T.let(%r{\A(?:#|//) @team (?.*)\Z}.freeze, Regexp) + TEAM_PATTERN = T.let(%r{\A(?:#|//|-#) @team (?.*)\Z}.freeze, Regexp) DESCRIPTION = 'Annotations at the top of file' sig do From 4ab000af553ebbb4644273be62fde6bea23cf00f Mon Sep 17 00:00:00 2001 From: Steve Aziz <68991236+ScAziz@users.noreply.github.com> Date: Thu, 6 Feb 2025 09:16:48 +0000 Subject: [PATCH 4/4] test removing file annotation --- .../file_annotations_spec.rb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb b/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb index 0d93f14..2188b87 100644 --- a/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb +++ b/spec/lib/code_ownership/private/ownership_mappers/file_annotations_spec.rb @@ -214,6 +214,43 @@ module CodeOwnership end end + context 'haml has annotation' do + let(:filename) { 'app.my_file.html.haml' } + + before do + write_file(filename, <<~CONTENTS) + -# @team Foo + + -# Some content + CONTENTS + + write_file('package.yml', <<~CONTENTS) + enforce_dependency: true + enforce_privacy: true + CONTENTS + end + + it 'removes the annotation' do + current_ownership = CodeOwnership.for_file(filename) + expect(current_ownership&.name).to eq 'Foo' + expect(File.read(filename)).to eq <<~HAML + -# @team Foo + + -# Some content + HAML + + remove_file_annotation + + new_ownership = CodeOwnership.for_file(filename) + expect(new_ownership).to eq nil + expected_output = <<~HAML + -# Some content + HAML + + expect(File.read(filename)).to eq expected_output + end + end + context 'file has new lines after the annotation' do let(:filename) { 'app/my_file.rb' }