From c2785c8e47fec14d31f390964871266a099d0f7c Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 1 Apr 2018 00:59:13 +0000 Subject: [PATCH] Oops forgot to commit a source file --- src/Vervis/ChangeFeed.hs | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/Vervis/ChangeFeed.hs diff --git a/src/Vervis/ChangeFeed.hs b/src/Vervis/ChangeFeed.hs new file mode 100644 index 0000000..e181b60 --- /dev/null +++ b/src/Vervis/ChangeFeed.hs @@ -0,0 +1,76 @@ +{- This file is part of Vervis. + - + - Written in 2018 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +module Vervis.ChangeFeed + ( changeFeed + ) +where + +import Prelude + +import Data.Monoid ((<>)) +import Data.Text (Text) +import Yesod.Core (Route) +import Yesod.Feed + +import qualified Data.Text as T (concat) + +import Vervis.Changes +import Vervis.Foundation +import Vervis.Model.Ident +import Vervis.Model.Repo + +changeEntry :: LogEntry -> FeedEntry (Route App) +changeEntry le = FeedEntry + { feedEntryLink = HomeR + , feedEntryUpdated = fst $ leTime le + , feedEntryTitle = leMessage le + , feedEntryContent = mempty + , feedEntryEnclosure = Nothing + } + +changeFeed + :: ShrIdent -- ^ Sharer name + -> RpIdent -- ^ Repo name + -> Maybe Text -- ^ Optional branch name + -> VersionControlSystem -- ^ To pick VCS specific terms + -> [LogEntry] -- ^ Changes, recent first + -> Feed (Route App) +changeFeed shr repo mbranch vcs les = Feed + { feedTitle = T.concat + [ rp2text repo + , case mbranch of + Nothing -> "" + Just b -> ":" <> b + , " " + , case vcs of + VCSDarcs -> "Patches" + VCSGit -> "Commits" + ] + , feedLinkSelf = + case mbranch of + Nothing -> RepoHeadChangesR shr repo + Just b -> RepoChangesR shr repo b + , feedLinkHome = + case mbranch of + Nothing -> RepoHeadChangesR shr repo + Just b -> RepoChangesR shr repo b + , feedAuthor = shr2text shr + , feedDescription = mempty + , feedLanguage = "en" + , feedUpdated = fst $ leTime $ head les + , feedLogo = Nothing + , feedEntries = map changeEntry les + }