summary refs log tree commit diff
path: root/maintainers/scripts/haskell/hydra-report.hs
diff options
context:
space:
mode:
author(cdep)illabout <cdep.illabout@gmail.com>2021-05-16 10:43:39 +0900
committer(cdep)illabout <cdep.illabout@gmail.com>2021-05-16 10:43:39 +0900
commit4ac4ced4705f474ae1424d6541d02bccf84016c6 (patch)
tree8328daa59022e34da20f5ca26bf02a673c7772a2 /maintainers/scripts/haskell/hydra-report.hs
parent39d04243e213a00ea1a644b486e4a330cc27ac64 (diff)
downloadnixpkgs-4ac4ced4705f474ae1424d6541d02bccf84016c6.tar
nixpkgs-4ac4ced4705f474ae1424d6541d02bccf84016c6.tar.gz
nixpkgs-4ac4ced4705f474ae1424d6541d02bccf84016c6.tar.bz2
nixpkgs-4ac4ced4705f474ae1424d6541d02bccf84016c6.tar.lz
nixpkgs-4ac4ced4705f474ae1424d6541d02bccf84016c6.tar.xz
nixpkgs-4ac4ced4705f474ae1424d6541d02bccf84016c6.tar.zst
nixpkgs-4ac4ced4705f474ae1424d6541d02bccf84016c6.zip
hydra-report.hs: Change Maintainers back to being Maybe Text
Diffstat (limited to 'maintainers/scripts/haskell/hydra-report.hs')
-rwxr-xr-xmaintainers/scripts/haskell/hydra-report.hs27
1 files changed, 20 insertions, 7 deletions
diff --git a/maintainers/scripts/haskell/hydra-report.hs b/maintainers/scripts/haskell/hydra-report.hs
index bb16b109818..e8ca5b888a2 100755
--- a/maintainers/scripts/haskell/hydra-report.hs
+++ b/maintainers/scripts/haskell/hydra-report.hs
@@ -143,8 +143,14 @@ handlesParams = ["--eval", "--strict", "--json", "-"]
 handlesExpression :: String
 handlesExpression = "with import ./. {}; with lib; zipAttrsWith (_: builtins.head) (mapAttrsToList (_: v: if v ? github then { \"${v.email}\" = v.github; } else {}) (import maintainers/maintainer-list.nix))"
 
-newtype Maintainers = Maintainers {maintainers :: Text}
-  deriving stock (Generic)
+-- | This newtype is used to parse a Hydra job output from @hydra-eval-jobs@.
+-- The only field we are interested in is @maintainers@, which is why this
+-- is just a newtype.
+--
+-- Note that there are occassionally jobs that don't have a maintainers
+-- field, which is why this has to be @Maybe Text@.
+newtype Maintainers = Maintainers { maintainers :: Maybe Text }
+  deriving stock (Generic, Show)
   deriving anyclass (FromJSON, ToJSON)
 
 -- | This is a 'Map' from Hydra job name to maintainer email addresses.
@@ -153,10 +159,10 @@ newtype Maintainers = Maintainers {maintainers :: Text}
 --
 -- @@
 --  fromList
---    [ ("arion.aarch64-linux", Maintainers "robert@example.com")
---    , ("bench.x86_64-linux", Maintainers "")
---    , ("conduit.x86_64-linux", Maintainers "snoy@man.com, web@ber.com")
---    , ("lens.x86_64-darwin", Maintainers "ek@category.com")
+--    [ ("arion.aarch64-linux", Maintainers (Just "robert@example.com"))
+--    , ("bench.x86_64-linux", Maintainers (Just ""))
+--    , ("conduit.x86_64-linux", Maintainers (Just "snoy@man.com, web@ber.com"))
+--    , ("lens.x86_64-darwin", Maintainers (Just "ek@category.com"))
 --    ]
 -- @@
 --
@@ -196,7 +202,14 @@ getMaintainerMap = do
       readJSONProcess hydraEvalCommand hydraEvalParams "" "Failed to decode hydra-eval-jobs output: "
    handlesMap :: EmailToGitHubHandles <-
       readJSONProcess handlesCommand handlesParams handlesExpression "Failed to decode nix output for lookup of github handles: "
-   pure $ Map.mapMaybe (nonEmpty . mapMaybe (`Map.lookup` handlesMap) . Text.splitOn ", " . maintainers) hydraJobs
+   pure $ Map.mapMaybe (splitMaintainersToGitHubHandles handlesMap) hydraJobs
+   where
+   -- Split a comma-spearated string of Maintainers into a NonEmpty list of
+   -- GitHub handles.
+   splitMaintainersToGitHubHandles
+      :: EmailToGitHubHandles -> Maintainers -> Maybe (NonEmpty Text)
+   splitMaintainersToGitHubHandles handlesMap (Maintainers maint) =
+      nonEmpty .  mapMaybe (`Map.lookup` handlesMap) .  Text.splitOn ", " $ fromMaybe "" maint
 
 -- | Run a process that produces JSON on stdout and and decode the JSON to a
 -- data type.