From c0455b836fb6d56a9a68c0ef4e3b636d2837f35f Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Tue, 20 Dec 2022 13:25:44 +0100 Subject: [PATCH] scripts: ci: compliance: Remove Codeowners check This check is no longer used and will be replaced by the maintainers file, remove it. Signed-off-by: Carles Cufi --- scripts/ci/check_compliance.py | 122 --------------------------------- 1 file changed, 122 deletions(-) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index b222638bd10..c0b0769a55f 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -677,128 +677,6 @@ class KconfigBasicCheck(KconfigCheck): super().run(full=False) -class Codeowners(ComplianceTest): - """ - Check if added files have an owner. - """ - name = "Codeowners" - doc = "See https://help.github.com/articles/about-code-owners/ for more details." - path_hint = "" - - def ls_owned_files(self, codeowners): - """Returns an OrderedDict mapping git patterns from the CODEOWNERS file - to the corresponding list of files found on the filesystem. It - unfortunately does not seem possible to invoke git and re-use - how 'git ignore' and/or 'git attributes' already implement this, - we must re-invent it. - """ - - # TODO: filter out files not in "git ls-files" (e.g., - # twister-out) _if_ the overhead isn't too high for a clean tree. - # - # pathlib.match() doesn't support **, so it looks like we can't - # recursively glob the output of ls-files directly, only real - # files :-( - - pattern2files = collections.OrderedDict() - top_path = Path(GIT_TOP) - - with open(codeowners, "r") as codeo: - for lineno, line in enumerate(codeo, start=1): - - if line.startswith("#") or not line.strip(): - continue - - match = re.match(r"^([^\s,]+)\s+[^\s]+", line) - if not match: - self.failure(f"Invalid CODEOWNERS line {lineno}\n\t{line}") - continue - - git_patrn = match.group(1) - glob = self.git_pattern_to_glob(git_patrn) - files = [] - for abs_path in top_path.glob(glob): - # comparing strings is much faster later - files.append(str(abs_path.relative_to(top_path))) - - if not files: - self.failure(f"Path '{git_patrn}' not found in the tree" - f"but is listed in CODEOWNERS") - - pattern2files[git_patrn] = files - - return pattern2files - - def git_pattern_to_glob(self, git_pattern): - """Appends and prepends '**[/*]' when needed. Result has neither a - leading nor a trailing slash. - """ - - if git_pattern.startswith("/"): - ret = git_pattern[1:] - else: - ret = "**/" + git_pattern - - if git_pattern.endswith("/"): - ret = ret + "**/*" - elif os.path.isdir(os.path.join(GIT_TOP, ret)): - self.failure("Expected '/' after directory '{}' " - "in CODEOWNERS".format(ret)) - - return ret - - def run(self): - codeowners = os.path.join(GIT_TOP, "CODEOWNERS") - if not os.path.exists(codeowners): - self.skip("CODEOWNERS not available in this repo") - - name_changes = get_files(filter="ARCD") - owners_changes = get_files(paths=(codeowners,)) - - if not name_changes and not owners_changes: - # TODO: 1. decouple basic and cheap CODEOWNERS syntax - # validation from the expensive ls_owned_files() scanning of - # the entire tree. 2. run the former always. - return - - logger.info("If this takes too long then cleanup and try again") - patrn2files = self.ls_owned_files(codeowners) - - # The way git finds Renames and Copies is not "exact science", - # however if one is missed then it will always be reported as an - # Addition instead. - new_files = get_files(filter="ARC").splitlines() - logger.debug(f"New files {new_files}") - - # Convert to pathlib.Path string representation (e.g., - # backslashes 'dir1\dir2\' on Windows) to be consistent - # with self.ls_owned_files() - new_files = [str(Path(f)) for f in new_files] - - new_not_owned = [] - for newf in new_files: - f_is_owned = False - - for git_pat, owned in patrn2files.items(): - logger.debug(f"Scanning {git_pat} for {newf}") - - if newf in owned: - logger.info(f"{git_pat} matches new file {newf}") - f_is_owned = True - # Unlike github, we don't care about finding any - # more specific owner. - break - - if not f_is_owned: - new_not_owned.append(newf) - - if new_not_owned: - self.failure("New files added that are not covered in " - "CODEOWNERS:\n\n" + "\n".join(new_not_owned) + - "\n\nPlease add one or more entries in the " - "CODEOWNERS file to cover those files") - - class Nits(ComplianceTest): """ Checks various nits in added/modified files. Doesn't check stuff that's