mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
send back release notes for eos
This commit is contained in:
@@ -15,17 +15,20 @@ import qualified Data.Attoparsec.Text as Atto
|
|||||||
import Data.String.Interpolate.IsString
|
import Data.String.Interpolate.IsString
|
||||||
( i )
|
( i )
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.IO as T
|
||||||
import Foundation
|
import Foundation
|
||||||
import Handler.Types.Status
|
import Handler.Types.Status
|
||||||
import Lib.Error ( S9Error(NotFoundE) )
|
import Lib.Error ( S9Error(NotFoundE) )
|
||||||
import Lib.PkgRepository ( getBestVersion )
|
import Lib.PkgRepository ( getBestVersion )
|
||||||
import Lib.Types.AppIndex ( PkgId )
|
import Lib.Types.AppIndex ( PkgId )
|
||||||
import Lib.Types.Emver ( parseVersion
|
import Lib.Types.Emver ( Version(..)
|
||||||
|
, parseVersion
|
||||||
, satisfies
|
, satisfies
|
||||||
)
|
)
|
||||||
import Network.HTTP.Types.Status ( status404 )
|
import Network.HTTP.Types.Status ( status404 )
|
||||||
import Settings
|
import Settings
|
||||||
import System.FilePath ( (</>) )
|
import System.FilePath ( (</>) )
|
||||||
|
import System.IO.Error ( isDoesNotExistError )
|
||||||
import UnliftIO.Directory ( listDirectory )
|
import UnliftIO.Directory ( listDirectory )
|
||||||
import Util.Shared ( getVersionSpecFromQuery
|
import Util.Shared ( getVersionSpecFromQuery
|
||||||
, orThrow
|
, orThrow
|
||||||
@@ -41,7 +44,13 @@ getPkgVersionR pkg = do
|
|||||||
status404
|
status404
|
||||||
(NotFoundE [i|Version for #{pkg} satisfying #{spec}|])
|
(NotFoundE [i|Version for #{pkg} satisfying #{spec}|])
|
||||||
|
|
||||||
getEosVersionR :: Handler AppVersionRes
|
|
||||||
|
data EosVersionRes = EosVersionRes
|
||||||
|
{ eosVersionVersion :: Version
|
||||||
|
, eosVersionReleaseNotes :: Text
|
||||||
|
}
|
||||||
|
|
||||||
|
getEosVersionR :: Handler EosVersionRes
|
||||||
getEosVersionR = do
|
getEosVersionR = do
|
||||||
spec <- getVersionSpecFromQuery
|
spec <- getVersionSpecFromQuery
|
||||||
root <- getsYesod $ (</> "eos") . resourcesDir . appSettings
|
root <- getsYesod $ (</> "eos") . resourcesDir . appSettings
|
||||||
@@ -49,4 +58,10 @@ getEosVersionR = do
|
|||||||
let (failures, successes) = partitionEithers $ (Atto.parseOnly parseVersion . T.pack) <$> subdirs
|
let (failures, successes) = partitionEithers $ (Atto.parseOnly parseVersion . T.pack) <$> subdirs
|
||||||
for_ failures $ \f -> $logWarn [i|Emver Parse Failure for EOS: #{f}|]
|
for_ failures $ \f -> $logWarn [i|Emver Parse Failure for EOS: #{f}|]
|
||||||
let res = headMay . sortOn Down . filter (`satisfies` spec) $ successes
|
let res = headMay . sortOn Down . filter (`satisfies` spec) $ successes
|
||||||
maybe (sendResponseStatus status404 (NotFoundE [i|EOS version satisfying #{spec}|])) (pure . AppVersionRes) res
|
case res of
|
||||||
|
Nothing -> sendResponseStatus status404 (NotFoundE [i|EOS version satisfying #{spec}|])
|
||||||
|
Just r -> do
|
||||||
|
let notesPath = root </> show r </> "release-notes.md"
|
||||||
|
notes <- liftIO $ T.readFile notesPath `catch` \e ->
|
||||||
|
if isDoesNotExistError e then pure [i|# Release Notes Missing for #{r}|] else throwIO e
|
||||||
|
pure $ EosVersionRes r notes
|
||||||
|
|||||||
Reference in New Issue
Block a user