Skip to content

Commit 81ac4d0

Browse files
authored
Testowner: fix path resolving (#14485)
1 parent b9ac376 commit 81ac4d0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

.github/scripts/analytics/upload_tests_results.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,27 @@ def parse_junit_xml(test_results_file, build_type, job_name, job_id, commit, bra
133133
return results
134134

135135

136+
def sort_codeowners_lines(codeowners_lines):
137+
def path_specificity(line):
138+
# removing comments
139+
trimmed_line = line.strip()
140+
if not trimmed_line or trimmed_line.startswith('#'):
141+
return -1, -1
142+
path = trimmed_line.split()[0]
143+
return len(path.split('/')), len(path)
144+
145+
sorted_lines = sorted(codeowners_lines, key=path_specificity)
146+
return sorted_lines
147+
136148
def get_codeowners_for_tests(codeowners_file_path, tests_data):
137149
with open(codeowners_file_path, 'r') as file:
138-
data = file.read()
139-
owners_odj = CodeOwners(data)
140-
150+
data = file.readlines()
151+
owners_odj = CodeOwners(''.join(sort_codeowners_lines(data)))
141152
tests_data_with_owners = []
142153
for test in tests_data:
143154
target_path = f'{test["suite_folder"]}'
144155
owners = owners_odj.of(target_path)
145-
test["owners"] = joined_owners = ";;".join(
156+
test["owners"] = ";;".join(
146157
[(":".join(x)) for x in owners])
147158
tests_data_with_owners.append(test)
148159
return tests_data_with_owners

0 commit comments

Comments
 (0)