Skip to content

Commit

Permalink
Support ownership for HAML files (#115)
Browse files Browse the repository at this point in the history
* add before block to spec

* add failing test for haml ownership

* add haml comment pattern to TEAM_PATTERN regex

* test removing file annotation
  • Loading branch information
ScAziz authored Feb 7, 2025
1 parent 2b233e5 commit 259d602
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FileAnnotations
extend T::Sig
include Mapper

TEAM_PATTERN = T.let(%r{\A(?:#|//) @team (?<team>.*)\Z}.freeze, Regexp)
TEAM_PATTERN = T.let(%r{\A(?:#|//|-#) @team (?<team>.*)\Z}.freeze, Regexp)
DESCRIPTION = 'Annotations at the top of file'

sig do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,27 @@ module CodeOwnership
expect(CodeOwnership.for_file('frontend/javascripts/packages/my_package/[formID]/owned_file.jsx').name).to eq 'Bar'
end
end

context 'haml owned file' do
before do
write_configuration
write_file('config/teams/bar.yml', <<~CONTENTS)
name: Bar
CONTENTS

write_file('packs/my_pack/owned_file.html.haml', <<~CONTENTS)
-# @team Bar
CONTENTS
end

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



describe '.remove_file_annotation!' do
subject(:remove_file_annotation) do
CodeOwnership.remove_file_annotation!(filename)
Expand Down Expand Up @@ -195,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' }

Expand Down

0 comments on commit 259d602

Please sign in to comment.