{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module Distribution.Fedora.Release
( Release(..),
getReleases,
getFedoraReleases,
getEPELReleases
)
where
import Control.Monad (guard)
import Data.Aeson(Object)
import Data.Maybe (mapMaybe)
import Distribution.Fedora.BodhiReleases
import Fedora.Bodhi (lookupKey)
data Release = Release {
Release -> String
releaseName :: String,
Release -> String
releaseVersion :: String,
Release -> String
releaseIdPrefix :: String,
Release -> String
releaseBranch :: String
} deriving (Int -> Release -> ShowS
[Release] -> ShowS
Release -> String
(Int -> Release -> ShowS)
-> (Release -> String) -> ([Release] -> ShowS) -> Show Release
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Release -> ShowS
showsPrec :: Int -> Release -> ShowS
$cshow :: Release -> String
show :: Release -> String
$cshowList :: [Release] -> ShowS
showList :: [Release] -> ShowS
Show,Release -> Release -> Bool
(Release -> Release -> Bool)
-> (Release -> Release -> Bool) -> Eq Release
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Release -> Release -> Bool
== :: Release -> Release -> Bool
$c/= :: Release -> Release -> Bool
/= :: Release -> Release -> Bool
Eq)
instance Ord Release where
compare :: Release -> Release -> Ordering
compare Release
r1 Release
r2 =
String -> String -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Release -> String
releaseName Release
r1) (Release -> String
releaseName Release
r2)
readRelease :: Object -> Maybe Release
readRelease :: Object -> Maybe Release
readRelease Object
obj = do
String
name <- Text -> Object -> Maybe String
forall a. FromJSON a => Text -> Object -> Maybe a
lookupKey Text
"name" Object
obj
String
ver <- Text -> Object -> Maybe String
forall a. FromJSON a => Text -> Object -> Maybe a
lookupKey Text
"version" Object
obj
String
idPref <- Text -> Object -> Maybe String
forall a. FromJSON a => Text -> Object -> Maybe a
lookupKey Text
"id_prefix" Object
obj
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (String
idPref String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [String
"FEDORA-CONTAINER",String
"FEDORA-FLATPAK"])
String
br <- Text -> Object -> Maybe String
forall a. FromJSON a => Text -> Object -> Maybe a
lookupKey Text
"branch" Object
obj
Release -> Maybe Release
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Release -> Maybe Release) -> Release -> Maybe Release
forall a b. (a -> b) -> a -> b
$ String -> String -> String -> String -> Release
Release String
name String
ver String
idPref String
br
getReleases :: IO [Release]
getReleases :: IO [Release]
getReleases =
[Release] -> [Release]
forall a. [a] -> [a]
reverse ([Release] -> [Release])
-> ([Object] -> [Release]) -> [Object] -> [Release]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Object -> Maybe Release) -> [Object] -> [Release]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Object -> Maybe Release
readRelease ([Object] -> [Release]) -> IO [Object] -> IO [Release]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO [Object]
getBodhiReleases
getProductReleases :: String -> IO [Release]
getProductReleases :: String -> IO [Release]
getProductReleases String
name =
(Release -> Bool) -> [Release] -> [Release]
forall a. (a -> Bool) -> [a] -> [a]
filter (\Release
p -> Release -> String
releaseIdPrefix Release
p String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
name) ([Release] -> [Release]) -> IO [Release] -> IO [Release]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO [Release]
getReleases
getFedoraReleases :: IO [Release]
getFedoraReleases :: IO [Release]
getFedoraReleases =
String -> IO [Release]
getProductReleases String
"FEDORA"
getEPELReleases :: IO [Release]
getEPELReleases :: IO [Release]
getEPELReleases =
String -> IO [Release]
getProductReleases String
"FEDORA-EPEL"