adds release notes feature

This commit is contained in:
Keagan McClelland
2021-02-25 18:34:54 -07:00
parent 79d8aec8da
commit b643c34d6c
2 changed files with 15 additions and 8 deletions

View File

@@ -13,14 +13,18 @@ import Orphans.Emver ( )
data AppVersionRes = AppVersionRes data AppVersionRes = AppVersionRes
{ appVersionVersion :: Version { appVersionVersion :: Version
, appVersionMinCompanion :: Maybe Version , appVersionMinCompanion :: Maybe Version
, appVersionReleaseNotes :: Maybe Text
} }
deriving (Eq, Show) deriving (Eq, Show)
instance ToJSON AppVersionRes where instance ToJSON AppVersionRes where
toJSON AppVersionRes { appVersionVersion, appVersionMinCompanion } = toJSON AppVersionRes { appVersionVersion, appVersionMinCompanion, appVersionReleaseNotes } =
object $ ["version" .= appVersionVersion] <> case appVersionMinCompanion of let rn = case appVersionReleaseNotes of
Nothing -> [] Nothing -> []
Just x -> ["minCompanion" .= x] Just x -> ["release-notes" .= x]
mc = case appVersionMinCompanion of
Nothing -> []
Just x -> ["minCompanion" .= x]
in object $ ["version" .= appVersionVersion] <> mc <> rn
instance ToContent AppVersionRes where instance ToContent AppVersionRes where
toContent = toContent . toJSON toContent = toContent . toJSON
instance ToTypedContent AppVersionRes where instance ToTypedContent AppVersionRes where

View File

@@ -18,11 +18,12 @@ import Lib.Types.Emver
import Settings import Settings
import System.FilePath ( (</>) ) import System.FilePath ( (</>) )
import Util.Shared import Util.Shared
import System.Directory ( doesFileExist )
getVersionR :: Handler AppVersionRes getVersionR :: Handler AppVersionRes
getVersionR = do getVersionR = do
rv <- AppVersionRes . registryVersion . appSettings <$> getYesod rv <- AppVersionRes . registryVersion . appSettings <$> getYesod
pure . rv $ Nothing pure $ rv Nothing Nothing
getVersionAppR :: Text -> Handler (Maybe AppVersionRes) getVersionAppR :: Text -> Handler (Maybe AppVersionRes)
getVersionAppR appId = do getVersionAppR appId = do
@@ -34,10 +35,12 @@ getVersionSysR :: Text -> Handler (Maybe AppVersionRes)
getVersionSysR sysAppId = runMaybeT $ do getVersionSysR sysAppId = runMaybeT $ do
sysDir <- (</> "sys") . resourcesDir . appSettings <$> getYesod sysDir <- (</> "sys") . resourcesDir . appSettings <$> getYesod
avr <- MaybeT $ getVersionWSpec sysDir sysExt avr <- MaybeT $ getVersionWSpec sysDir sysExt
pure $ avr { appVersionMinCompanion = Just $ Version (1, 1, 0, 0) } let notesPath = sysDir </> "agent" </> show (appVersionVersion avr) </> "release-notes.md"
notes <- liftIO $ ifM (doesFileExist notesPath) (Just <$> readFile notesPath) (pure Nothing)
pure $ avr { appVersionMinCompanion = Just $ Version (1, 1, 0, 0), appVersionReleaseNotes = notes }
where sysExt = Extension (toS sysAppId) :: Extension "" where sysExt = Extension (toS sysAppId) :: Extension ""
getVersionWSpec :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe AppVersionRes) getVersionWSpec :: KnownSymbol a => FilePath -> Extension a -> Handler (Maybe AppVersionRes)
getVersionWSpec rootDir ext = do getVersionWSpec rootDir ext = do
av <- getVersionFromQuery rootDir ext av <- getVersionFromQuery rootDir ext
pure $ liftA2 AppVersionRes av (pure Nothing) pure $ liftA3 AppVersionRes av (pure Nothing) (pure Nothing)