diff --git a/lib/nix/extract-maintainers.nix b/lib/nix/extract-maintainers.nix index 360b89844..9e6286b46 100644 --- a/lib/nix/extract-maintainers.nix +++ b/lib/nix/extract-maintainers.nix @@ -1,73 +1,58 @@ { lib ? import ../../modules/lib/stdlib-extended.nix (import { }).lib, - changedFilesJson ? throw "provide either changedFiles or changedFilesJson", - changedFiles ? builtins.fromJSON changedFilesJson, + file ? throw "provide file argument", }: let config = { }; releaseInfo = lib.importJSON ../../release.json; - extractMaintainersFromFile = - file: - let - isNixFile = lib.hasSuffix ".nix" file; - filePath = ../../. + "/${file}"; - fileExists = builtins.pathExists filePath; + isNixFile = lib.hasSuffix ".nix" file; + filePath = ../../. + "/${file}"; + fileExists = builtins.pathExists filePath; - moduleResult = - if isNixFile && fileExists then - let - result = builtins.tryEval ( - let - fileContent = import filePath; + maintainers = + if isNixFile && fileExists then + let + fileContent = import filePath; + + module = + if lib.isFunction fileContent then + # TODO: Find a better way of handling this... + if lib.hasPrefix "docs/" file then + if lib.hasSuffix "home-manager-manual.nix" file then + fileContent { + stdenv = { + mkDerivation = x: x; + }; + inherit lib; + documentation-highlighter = { }; + revision = "unknown"; + home-manager-options = { + home-manager = { }; + nixos = { }; + nix-darwin = { }; + }; + nixos-render-docs = { }; + } + else + fileContent { + inherit lib; + pkgs = null; + inherit (releaseInfo) release isReleaseBranch; + } + else if lib.hasPrefix "lib/" file then + fileContent { inherit lib; } + else + fileContent { + inherit lib config; + pkgs = null; + } + else + fileContent; + in + module.meta.maintainers or [ ] + else + [ ]; - module = - if lib.isFunction fileContent then - # TODO: Find a better way of handling this... - if lib.hasPrefix "docs/" file then - if lib.hasSuffix "home-manager-manual.nix" file then - fileContent { - stdenv = { - mkDerivation = x: x; - }; - inherit lib; - documentation-highlighter = { }; - revision = "unknown"; - home-manager-options = { - home-manager = { }; - nixos = { }; - nix-darwin = { }; - }; - nixos-render-docs = { }; - } - else - fileContent { - inherit lib; - pkgs = null; - inherit (releaseInfo) release isReleaseBranch; - } - else if lib.hasPrefix "lib/" file then - fileContent { inherit lib; } - else - fileContent { - inherit lib config; - pkgs = null; - } - else - fileContent; - in - module.meta.maintainers or [ ] - ); - in - if result.success then result.value else [ ] - else - [ ]; - in - moduleResult; in -lib.pipe changedFiles [ - (map extractMaintainersFromFile) - lib.concatLists - lib.unique - (map (maintainer: maintainer.github)) -] +map (maintainer: maintainer.github) maintainers diff --git a/lib/python/extract-maintainers.py b/lib/python/extract-maintainers.py index 337b39c5d..94f387848 100755 --- a/lib/python/extract-maintainers.py +++ b/lib/python/extract-maintainers.py @@ -55,19 +55,25 @@ def extract_maintainers(changed_files: list[str], pr_author: str) -> list[str]: logging.info("Finding maintainers for changed files...") nix_file = Path(__file__).parent.parent / "nix" / "extract-maintainers.nix" - changed_files_json = json.dumps(changed_files) - try: - result_json = run_nix_eval(nix_file, "--argstr", "changedFilesJson", changed_files_json) - maintainers = set(json.loads(result_json)) - except NixEvalError: - # Error is already logged by run_nix_eval - return [] - except json.JSONDecodeError as e: - logging.error(f"Error parsing JSON output from Nix: {e}") - return [] + all_maintainers = set() - filtered_maintainers = sorted(list(maintainers - {pr_author})) + for file in changed_files: + try: + result_json = run_nix_eval(nix_file, "--argstr", "file", file) + file_maintainers = json.loads(result_json) + all_maintainers.update(file_maintainers) + if file_maintainers: + logging.debug(f"Found maintainers for {file}: {file_maintainers}") + except NixEvalError: + # Error is already logged by run_nix_eval, just skip this file + logging.debug(f"Skipping {file} due to evaluation error") + continue + except json.JSONDecodeError as e: + logging.error(f"Error parsing JSON output from Nix for {file}: {e}") + continue + + filtered_maintainers = sorted(list(all_maintainers - {pr_author})) if not filtered_maintainers: logging.info("No maintainers found (or only the PR author is a maintainer).")