code_ownership 1.35.0 → 1.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e34134e28ee70e58344ea6d3f90be157bbdd6945888eee07d73abf3db3ed873b
|
|
4
|
+
data.tar.gz: 1875f6d3131505551c163aa03413edefa86c6f279d2c3189d9663a74a9603758
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de217fe525521395f2b6ad647257aecd69c9e8f8895fa0d466051cf4d365c3fce2dcf08ea9c9bfbeeef0c75116f3188d6f350c72becb965f7f3d49a992a0b6fa
|
|
7
|
+
data.tar.gz: abf92fcca79c8311cfa9d82fabcb0b129fdd076c9cb7a3db31c0db983dabf1e6cb5810b501e38cdab9fbf028dc3a43ed6105928469015b6bf30a33e774b5a6b6
|
|
@@ -10,6 +10,8 @@ module CodeOwnership
|
|
|
10
10
|
include Mapper
|
|
11
11
|
|
|
12
12
|
CODEOWNERS_DIRECTORY_FILE_NAME = '.codeowner'
|
|
13
|
+
RELATIVE_ROOT = Pathname('.').freeze
|
|
14
|
+
ABSOLUTE_ROOT = Pathname('/').freeze
|
|
13
15
|
|
|
14
16
|
@@directory_cache = T.let({}, T::Hash[String, T.nilable(CodeTeams::Team)]) # rubocop:disable Style/ClassVars
|
|
15
17
|
|
|
@@ -74,36 +76,46 @@ module CodeOwnership
|
|
|
74
76
|
)
|
|
75
77
|
end
|
|
76
78
|
|
|
77
|
-
#
|
|
79
|
+
# Takes a file and finds the relevant `.codeowner` file by walking up the directory
|
|
78
80
|
# structure. Example, given `a/b/c.rb`, this looks for `a/b/.codeowner`, `a/.codeowner`,
|
|
79
81
|
# and `.codeowner` in that order, stopping at the first file to actually exist.
|
|
80
|
-
#
|
|
82
|
+
# If the parovided file is a directory, it will look for `.codeowner` in that directory and then upwards.
|
|
83
|
+
# We do additional caching so that we don't have to check for file existence every time.
|
|
81
84
|
sig { params(file: String).returns(T.nilable(CodeTeams::Team)) }
|
|
82
85
|
def map_file_to_relevant_owner(file)
|
|
83
86
|
file_path = Pathname.new(file)
|
|
84
|
-
|
|
87
|
+
team = T.let(nil, T.nilable(CodeTeams::Team))
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
if File.directory?(file)
|
|
90
|
+
team = get_team_from_codeowners_file_within_directory(file_path)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
while team.nil? && file_path != RELATIVE_ROOT && file_path != ABSOLUTE_ROOT
|
|
94
|
+
file_path = file_path.parent
|
|
95
|
+
team = get_team_from_codeowners_file_within_directory(file_path)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
team
|
|
99
|
+
end
|
|
89
100
|
|
|
90
|
-
|
|
101
|
+
sig { params(directory: Pathname).returns(T.nilable(CodeTeams::Team)) }
|
|
102
|
+
def get_team_from_codeowners_file_within_directory(directory)
|
|
103
|
+
potential_codeowners_file = directory.join(CODEOWNERS_DIRECTORY_FILE_NAME)
|
|
91
104
|
|
|
92
|
-
|
|
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)
|
|
105
|
+
potential_codeowners_file_name = potential_codeowners_file.to_s
|
|
97
106
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
team = nil
|
|
108
|
+
if @@directory_cache.key?(potential_codeowners_file_name)
|
|
109
|
+
team = @@directory_cache[potential_codeowners_file_name]
|
|
110
|
+
elsif potential_codeowners_file.exist?
|
|
111
|
+
team = owner_for_codeowners_file(potential_codeowners_file)
|
|
102
112
|
|
|
103
|
-
|
|
113
|
+
@@directory_cache[potential_codeowners_file_name] = team
|
|
114
|
+
else
|
|
115
|
+
@@directory_cache[potential_codeowners_file_name] = nil
|
|
104
116
|
end
|
|
105
117
|
|
|
106
|
-
|
|
118
|
+
return team
|
|
107
119
|
end
|
|
108
120
|
end
|
|
109
121
|
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.
|
|
4
|
+
version: 1.36.0
|
|
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
|
+
date: 2023-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: code_teams
|