Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ownership for HAML files #115

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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