Skip to content

Commit 5e48f72

Browse files
brandonchinn178ysangkok
authored andcommitted
Refactor message generation
1 parent fb09c8b commit 5e48f72

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/Distribution/Server/Features/UserNotify.hs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -806,31 +806,40 @@ userNotifyFeature ServerEnv{serverBaseURI, serverCron}
806806
genDependencyUpdateList idx revIdx =
807807
dependencyReleaseEmails (queryUserGroup . maintainersGroup) idx revIdx queryGetUserNotifyPref
808808

809-
describeRevision users earlier now pkg =
810-
if pkgNumRevisions pkg <= 1
811-
then "Package upload, " ++ display (packageName pkg) ++ ", by " ++
812-
formatTimeUser users (pkgLatestUploadTime pkg) (pkgLatestUploadUser pkg)
813-
else "Package metadata revision(s), " ++ display (packageName pkg) ++ ":\n" ++
814-
unlines (map (uncurry (formatTimeUser users) . snd) recentRevs)
809+
describeRevision users earlier now pkg
810+
| pkgNumRevisions pkg <= 1 =
811+
"Package upload, " ++ display (packageName pkg) ++ ", by " ++
812+
formatTimeUser users (pkgLatestUploadTime pkg) (pkgLatestUploadUser pkg)
813+
| otherwise =
814+
"Package metadata revision(s), " ++ display (packageName pkg) ++ ":\n" ++
815+
unlines (map (uncurry (formatTimeUser users) . snd) recentRevs)
815816
where
816817
revs = reverse $ Vec.toList (pkgMetadataRevisions pkg)
817818
recentRevs = filter ((\x -> x > earlier && x <= now) . fst . snd) revs
818819

819-
describeGroupAction users (time, uid, act, descr) =
820-
case act of
821-
(Admin_GroupAddUser tn (MaintainerGroup pkg)) -> Just $
822-
"Group modified by " ++ formatTimeUser users time uid ++ ":\n" ++
823-
display (Users.userIdToName users tn) ++ " added to maintainers for " ++ BS.unpack pkg ++
824-
"\n" ++ "Reason: " ++ BS.unpack descr
825-
(Admin_GroupDelUser tn (MaintainerGroup pkg)) -> Just $
826-
"Group modified by " ++ formatTimeUser users time uid ++ ":\n" ++
827-
display (Users.userIdToName users tn) ++ " removed from maintainers for " ++ BS.unpack pkg ++
828-
"\n" ++ "Reason: " ++ BS.unpack descr
820+
describeGroupAction users (time, uid, act, reason) =
821+
fmap
822+
( \message ->
823+
"Group modified by " ++ formatTimeUser users time uid ++ ":\n"
824+
++ message ++ "\n"
825+
++ "Reason: " ++ BS.unpack reason
826+
)
827+
$ case act of
828+
(Admin_GroupAddUser tn (MaintainerGroup pkg)) ->
829+
Just $
830+
display (Users.userIdToName users tn)
831+
<> " added to maintainers for "
832+
<> BS.unpack pkg
833+
(Admin_GroupDelUser tn (MaintainerGroup pkg)) ->
834+
Just $
835+
display (Users.userIdToName users tn)
836+
<> " removed from maintainers for "
837+
<> BS.unpack pkg
829838
_ -> Nothing
830839

831-
describeDocReport (pkg, doc) =
840+
describeDocReport (pkg, success) =
832841
"Package doc build for " ++ display (packageName pkg) ++ ":\n" ++
833-
if doc
842+
if success
834843
then "Build successful."
835844
else "Build failed."
836845

@@ -885,9 +894,7 @@ userNotifyFeature ServerEnv{serverBaseURI, serverCron}
885894
mailParts = [[Part (T.pack "text/plain; charset=utf-8")
886895
None DefaultDisposition []
887896
(PartContent $ BS.pack $
888-
intercalate "\n\n" ebody
889-
<> "\n\n"
890-
<> adjustmentLinkParagraph
897+
intercalate "\n\n" (ebody <> [adjustmentLinkParagraph])
891898
)
892899
]]
893900
}

0 commit comments

Comments
 (0)