Skip to content

Commit cab758e

Browse files
brandonchinn178ysangkok
authored andcommitted
Move describeDocReport into getNotificationEmails
1 parent b60a9c2 commit cab758e

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

src/Distribution/Server/Features/UserNotify.hs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,7 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
695695
groupActionNotifications <- concatMapM (genGroupUploadList notifyPrefs) groupActions
696696

697697
docReports <- collectDocReport trimLastTime now
698-
docReportNotifications <- foldM (genDocReportList notifyPrefs) Map.empty docReports
699-
let docReportEmails = foldMap describeDocReport <$> docReportNotifications
698+
docReportNotifications <- concatMapM (genDocReportList notifyPrefs) docReports
700699

701700
tagProposals <- collectTagProposals
702701
tagProposalNotifications <- concatMapM (genTagProposalList notifyPrefs) tagProposals
@@ -708,13 +707,14 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
708707
emails <-
709708
getNotificationEmails serverEnv userDetailsFeature queryGetUserNotifyPref users
710709
( foldr1 (Map.unionWith (<>))
711-
[ docReportEmails
710+
[
712711
]
713712
, mempty
714713
) $
715714
concat
716715
[ revisionUploadNotifications
717716
, groupActionNotifications
717+
, docReportNotifications
718718
, tagProposalNotifications
719719
, dependencyUpdateNotifications
720720
]
@@ -817,14 +817,18 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
817817
}
818818
_ -> pure []
819819

820-
genDocReportList notifyPrefs mp pkgDoc = do
821-
let addNotification uid m =
822-
if not (notifyOptOut npref) && notifyDocBuilderReport npref
823-
then Map.insertWith (++) uid [pkgDoc] m
824-
else m
825-
where npref = fromMaybe defaultNotifyPrefs (Map.lookup uid notifyPrefs)
826-
maintainers <- queryUserGroup $ maintainersGroup (packageName . pkgInfoId . fst $ pkgDoc)
827-
return $ foldr addNotification mp (toList maintainers)
820+
genDocReportList notifyPrefs (pkg, success) = do
821+
maintainers <- queryUserGroup $ maintainersGroup (packageName $ pkgInfoId pkg)
822+
pure . flip mapMaybe (toList maintainers) $ \uid ->
823+
fmap (uid,) $ do
824+
let NotifyPref{..} = fromMaybe defaultNotifyPrefs (Map.lookup uid notifyPrefs)
825+
guard $ not notifyOptOut
826+
guard notifyDocBuilderReport
827+
Just
828+
NotifyDocsBuild
829+
{ notifyPackageId = pkgInfoId pkg
830+
, notifyBuildSuccess = success
831+
}
828832

829833
genTagProposalList notifyPrefs (pkg, (addedTags, deletedTags)) = do
830834
maintainers <- queryUserGroup $ maintainersGroup pkg
@@ -849,13 +853,6 @@ userNotifyFeature serverEnv@ServerEnv{serverCron}
849853
Map.toList . fmap toNotif
850854
<$> getUserNotificationsOnRelease (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref pkg
851855

852-
describeDocReport (pkg, success) =
853-
EmailContentParagraph $
854-
"Package doc build for " <> emailContentDisplay (packageName pkg) <> ":" <> EmailContentSoftBreak <>
855-
if success
856-
then "Build successful."
857-
else "Build failed."
858-
859856
sendNotifyEmailAndDelay :: Mail -> IO ()
860857
sendNotifyEmailAndDelay email = do
861858
-- TODO: if we need any configuration of sendmail stuff, has to go here
@@ -880,6 +877,10 @@ data Notification
880877
, notifyReason :: Text
881878
, notifyUpdatedAt :: UTCTime
882879
}
880+
| NotifyDocsBuild
881+
{ notifyPackageId :: PackageId
882+
, notifyBuildSuccess :: Bool
883+
}
883884
| NotifyUpdateTags
884885
{ notifyPackageName :: PackageName
885886
, notifyAddedTags :: Set Tag
@@ -1012,6 +1013,11 @@ getNotificationEmails
10121013
notifyPackageName
10131014
notifyReason
10141015
notifyUpdatedAt
1016+
NotifyDocsBuild{..} ->
1017+
generalNotification $
1018+
renderNotifyDocsBuild
1019+
notifyPackageId
1020+
notifyBuildSuccess
10151021
NotifyUpdateTags{..} ->
10161022
generalNotification $
10171023
renderNotifyUpdateTags
@@ -1052,6 +1058,13 @@ getNotificationEmails
10521058
, "Reason: " <> EmailContentText reason
10531059
]
10541060

1061+
renderNotifyDocsBuild pkg success =
1062+
EmailContentParagraph $
1063+
"Package doc build for " <> renderPkgLink pkg <> ":" <> EmailContentSoftBreak
1064+
<> if success
1065+
then "Build successful."
1066+
else "Build failed."
1067+
10551068
renderNotifyUpdateTags pkg addedTags deletedTags =
10561069
EmailContentParagraph ("Pending tag proposal for " <> emailContentDisplay pkg <> ":")
10571070
<> EmailContentList

0 commit comments

Comments
 (0)