code_ownership 1.35.0 → 1.36.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 687d34f0d9ad8f7421b0a599904c697e10b34ec9f638a47f1e861b2e858bf091
4
- data.tar.gz: b8beee01bb8e5ff88d73117a05ad8c99c04e3ee3a7434f1a92da0e15cc7839dd
3
+ metadata.gz: 668edc0471999590cd95e9953151e6e30d02bf64b2bb14e544e5f7c56099c998
4
+ data.tar.gz: bbdff6a9af05c8026b33c206d63f083d1c9ed82831bd7b1f3cf3707aa0f54a67
5
5
  SHA512:
6
- metadata.gz: c30fb93a5e634f648f00ab7269d0744cbb9dc120b3c472769a116e59066190560845ae8ee660750efb81c10d8c483373ffda8058d523ac50f16fa05266cf9e29
7
- data.tar.gz: 1843017837ed962de655069fcb64d7d5121e72eb6375df14b8a7be8c35d6b9b55ba3e592bb9a240374964002ea65d1c7f87a0ddd6d565a1c74e4276c51bb56fb
6
+ metadata.gz: 54a6b78ddb108894b20ddee99d0a6637770485b27c154b6676021f512d2aae39159d052e8f2c7986b71c824eb9f3f7bc4a3b9d5bc0c9e1848e7bceecee3e7728
7
+ data.tar.gz: b4f39290cfc23f31b73642d3d6a5747ec79efc07210541c4b18c913f448c1df32efe6b4657e91f736055ab30ecf72b4910c22a0266503842aff84ad0e375be62
@@ -74,36 +74,54 @@ module CodeOwnership
74
74
  )
75
75
  end
76
76
 
77
- # takes a file and finds the relevant `.codeowner` file by walking up the directory
77
+ # Takes a file and finds the relevant `.codeowner` file by walking up the directory
78
78
  # structure. Example, given `a/b/c.rb`, this looks for `a/b/.codeowner`, `a/.codeowner`,
79
79
  # and `.codeowner` in that order, stopping at the first file to actually exist.
80
- # We do additional caching so that we don't have to check for file existence every time
80
+ # If the parovided file is a directory, it will look for `.codeowner` in that directory and then upwards.
81
+ # We do additional caching so that we don't have to check for file existence every time.
81
82
  sig { params(file: String).returns(T.nilable(CodeTeams::Team)) }
82
83
  def map_file_to_relevant_owner(file)
83
84
  file_path = Pathname.new(file)
84
- path_components = file_path.each_filename.to_a.map { |path| Pathname.new(path) }
85
+ team = T.let(nil, T.nilable(CodeTeams::Team))
86
+
87
+ if File.directory?(file)
88
+ team = get_team_from_codeowners_file_within_directory(file_path)
89
+ return team unless team.nil?
90
+ end
91
+
92
+ path_components = file_path.each_filename.to_a
93
+ if file_path.absolute?
94
+ path_components = ['/', *path_components]
95
+ end
85
96
 
86
97
  (path_components.length - 1).downto(0).each do |i|
87
- potential_relative_path_name = T.must(path_components[0...i]).reduce(Pathname.new('')) { |built_path, path| built_path.join(path) }
88
- potential_codeowners_file = potential_relative_path_name.join(CODEOWNERS_DIRECTORY_FILE_NAME)
98
+ team = get_team_from_codeowners_file_within_directory(
99
+ Pathname.new(File.join(*T.unsafe(path_components[0...i])))
100
+ )
101
+ return team unless team.nil?
102
+ end
89
103
 
90
- potential_codeowners_file_name = potential_codeowners_file.to_s
104
+ team
105
+ end
91
106
 
92
- team = nil
93
- if @@directory_cache.key?(potential_codeowners_file_name)
94
- team = @@directory_cache[potential_codeowners_file_name]
95
- elsif potential_codeowners_file.exist?
96
- team = owner_for_codeowners_file(potential_codeowners_file)
107
+ sig { params(directory: Pathname).returns(T.nilable(CodeTeams::Team)) }
108
+ def get_team_from_codeowners_file_within_directory(directory)
109
+ potential_codeowners_file = directory.join(CODEOWNERS_DIRECTORY_FILE_NAME)
97
110
 
98
- @@directory_cache[potential_codeowners_file_name] = team
99
- else
100
- @@directory_cache[potential_codeowners_file_name] = nil
101
- end
111
+ potential_codeowners_file_name = potential_codeowners_file.to_s
102
112
 
103
- return team unless team.nil?
113
+ team = nil
114
+ if @@directory_cache.key?(potential_codeowners_file_name)
115
+ team = @@directory_cache[potential_codeowners_file_name]
116
+ elsif potential_codeowners_file.exist?
117
+ team = owner_for_codeowners_file(potential_codeowners_file)
118
+
119
+ @@directory_cache[potential_codeowners_file_name] = team
120
+ else
121
+ @@directory_cache[potential_codeowners_file_name] = nil
104
122
  end
105
123
 
106
- nil
124
+ return team
107
125
  end
108
126
  end
109
127
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_ownership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.35.0
4
+ version: 1.36.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-29 00:00:00.000000000 Z
11
+ date: 2023-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_teams