File tree 2 files changed +30
-7
lines changed
lib/code_ownership/private/ownership_mappers
spec/lib/code_ownership/private/ownership_mappers
2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -73,19 +73,20 @@ def update_cache(cache, files)
73
73
74
74
sig { params ( filename : String ) . returns ( T . nilable ( CodeTeams ::Team ) ) }
75
75
def file_annotation_based_owner ( filename )
76
- # If for a directory is named with an ownable extension, we need to skip
77
- # so File.foreach doesn't blow up below. This was needed because Cypress
78
- # screenshots are saved to a folder with the test suite filename.
79
- return if File . directory? ( filename )
80
- return unless File . file? ( filename )
81
-
82
76
# The annotation should be on line 1 but as of this comment
83
77
# there's no linter installed to enforce that. We therefore check the
84
78
# first line (the Ruby VM makes a single `read(1)` call for 8KB),
85
79
# and if the annotation isn't in the first two lines we assume it
86
80
# doesn't exist.
87
81
88
- line1 = File . foreach ( filename ) . first
82
+ begin
83
+ line1 = File . foreach ( filename ) . first
84
+ rescue Errno ::EISDIR , Errno ::ENOENT
85
+ # Ignore files that don't exist to avoid an intermittent (harmless?) bug.
86
+ # Ignoring directories is needed because Cypress
87
+ # screenshots are saved to a folder with the test suite filename.
88
+ return
89
+ end
89
90
90
91
return if !line1
91
92
Original file line number Diff line number Diff line change @@ -37,6 +37,28 @@ module CodeOwnership
37
37
end
38
38
39
39
describe '.for_file' do
40
+ context 'path is a directory' do
41
+ it 'returns nil' do
42
+ write_configuration
43
+ write_file ( 'config/teams/bar.yml' , <<~CONTENTS )
44
+ name: Bar
45
+ CONTENTS
46
+
47
+ expect ( CodeOwnership . for_file ( 'config/teams' ) ) . to be_nil
48
+ end
49
+ end
50
+
51
+ context 'path does not exist' do
52
+ it 'returns nil' do
53
+ write_configuration
54
+ write_file ( 'config/teams/bar.yml' , <<~CONTENTS )
55
+ name: Bar
56
+ CONTENTS
57
+
58
+ expect ( CodeOwnership . for_file ( 'config/teams/foo.yml' ) ) . to be_nil
59
+ end
60
+ end
61
+
40
62
context 'ruby owned file' do
41
63
before do
42
64
write_configuration
You can’t perform that action at this time.
0 commit comments