at master 3.5 kB view raw
1{ 2 lib, 3}: 4{ 5 changedattrs, 6 changedpathsjson, 7 removedattrs, 8 byName ? false, 9}: 10let 11 pkgs = import ../../.. { 12 system = "x86_64-linux"; 13 config = { }; 14 overlays = [ ]; 15 }; 16 17 changedpaths = builtins.fromJSON (builtins.readFile changedpathsjson); 18 19 anyMatchingFile = 20 filename: builtins.any (changed: lib.strings.hasSuffix changed filename) changedpaths; 21 22 anyMatchingFiles = files: builtins.any anyMatchingFile files; 23 24 attrsWithMaintainers = lib.pipe (changedattrs ++ removedattrs) [ 25 (builtins.map ( 26 name: 27 let 28 # Some packages might be reported as changed on a different platform, but 29 # not even have an attribute on the platform the maintainers are requested on. 30 # Fallback to `null` for these to filter them out below. 31 package = lib.attrByPath (lib.splitString "." name) null pkgs; 32 in 33 { 34 inherit name package; 35 # TODO: Refactor this so we can ping entire teams instead of the individual members. 36 # Note that this will require keeping track of GH team IDs in "maintainers/teams.nix". 37 maintainers = package.meta.maintainers or [ ]; 38 } 39 )) 40 # No need to match up packages without maintainers with their files. 41 # This also filters out attributes where `packge = null`, which is the 42 # case for libintl, for example. 43 (builtins.filter (pkg: pkg.maintainers != [ ])) 44 ]; 45 46 relevantFilenames = 47 drv: 48 (lib.lists.unique ( 49 builtins.map (pos: lib.strings.removePrefix (toString ../..) pos.file) ( 50 builtins.filter (x: x != null) [ 51 ((drv.meta or { }).maintainersPosition or null) 52 ((drv.meta or { }).teamsPosition or null) 53 (builtins.unsafeGetAttrPos "src" drv) 54 # broken because name is always set by stdenv: 55 # # A hack to make `nix-env -qa` and `nix search` ignore broken packages. 56 # # TODO(@oxij): remove this assert when something like NixOS/nix#1771 gets merged into nix. 57 # name = assert validity.handled; name + lib.optionalString 58 #(builtins.unsafeGetAttrPos "name" drv) 59 (builtins.unsafeGetAttrPos "pname" drv) 60 (builtins.unsafeGetAttrPos "version" drv) 61 62 # Use ".meta.position" for cases when most of the package is 63 # defined in a "common" section and the only place where 64 # reference to the file with a derivation the "pos" 65 # attribute. 66 # 67 # ".meta.position" has the following form: 68 # "pkgs/tools/package-management/nix/default.nix:155" 69 # We transform it to the following: 70 # { file = "pkgs/tools/package-management/nix/default.nix"; } 71 { file = lib.head (lib.splitString ":" (drv.meta.position or "")); } 72 ] 73 ) 74 )); 75 76 attrsWithFilenames = builtins.map ( 77 pkg: pkg // { filenames = relevantFilenames pkg.package; } 78 ) attrsWithMaintainers; 79 80 attrsWithModifiedFiles = builtins.filter (pkg: anyMatchingFiles pkg.filenames) attrsWithFilenames; 81 82 listToPing = lib.concatMap ( 83 pkg: 84 builtins.map (maintainer: { 85 id = maintainer.githubId; 86 inherit (maintainer) github; 87 packageName = pkg.name; 88 dueToFiles = pkg.filenames; 89 }) pkg.maintainers 90 ) attrsWithModifiedFiles; 91 92 byMaintainer = lib.groupBy (ping: toString ping.${if byName then "github" else "id"}) listToPing; 93 94 packagesPerMaintainer = lib.attrsets.mapAttrs ( 95 maintainer: packages: builtins.map (pkg: pkg.packageName) packages 96 ) byMaintainer; 97in 98packagesPerMaintainer