on bb7772e help sign in
86 lines 2.7 kB history raw
1module CompaREST.GitHub.API
2 ( postStatus,
3 postStatusProcessing,
4 )
5where
7import CompaREST.GitHub.Action.Config
8import Control.Monad.Freer
9import Control.Monad.Freer.GitHub
10import Control.Monad.Freer.Reader
11import Control.Monad.IO.Class
12import Data.Aeson
13import qualified Data.ByteString.Lazy.Char8 as BSLC
14import Data.OpenApi.Compare.Report
15import Data.Proxy
16import Data.Text (Text)
17import GitHub
18import GitHub.Data.Checks
19import GitHub.Endpoints.Checks
21postStatusProcessing ::
22 (Members '[GitHub, Reader Config] effs, MonadIO (Eff effs)) =>
23 Eff effs ()
24postStatusProcessing = do
25 Config {..} <- ask
26 printJSON $
27 sendGitHub $
28 checkR
29 repoOwner
30 repoName
31 Check
32 { checkName = mkName Proxy $ "compaREST – " <> projectName
33 , checkSha = sha
34 , checkDetailsURL = Nothing
35 , checkExternalId = Nothing
36 , checkStatus = Just CheckInProgress
37 , checkStartedAt = Nothing
38 , checkConclusion = Nothing
39 , checkCompletedAt = Nothing
40 , checkOutput = Nothing
41 , checkActions = Nothing
42 }
44postStatus ::
45 (Members '[GitHub, Reader Config] effs, MonadIO (Eff effs)) =>
46 -- | 'Nothing' means that there were no changes at all
47 Maybe (Text, ReportStatus) ->
48 Eff effs ()
49postStatus x = do
50 let (body, (title, conclusion)) = case x of
51 Just (b, s) -> (b,) $ case s of
52 BreakingChanges -> ("⚠️ Breaking changes found!", CheckNeutral)
53 NoBreakingChanges -> ("No breaking changes found ✨", CheckSuccess)
54 OnlyUnsupportedChanges -> ("🤷 Couldn't determine compatibility", CheckNeutral)
55 Nothing -> ("", ("✅ The API did not change", CheckSuccess))
56 Config {..} <- ask
57 printJSON $
58 sendGitHub $
59 checkR
60 repoOwner
61 repoName
62 Check
63 { checkName = mkName Proxy $ "compaREST – " <> projectName
64 , checkSha = sha
65 , checkDetailsURL = Nothing
66 , checkExternalId = Nothing
67 , checkStatus = Just CheckCompleted
68 , checkStartedAt = Nothing
69 , checkConclusion = Just conclusion
70 , checkCompletedAt = Nothing
71 , checkOutput =
72 Just $
73 CheckOutput
74 { checkTitle = title
75 , checkSummary = body
76 , checkText = Nothing
77 , checkAnnotations = Nothing
78 , checkImages = Nothing
79 }
80 , checkActions = Nothing
81 }
83printJSON :: MonadIO (Eff effs) => Eff effs Value -> Eff effs ()
84printJSON m = do
85 x <- m
86 liftIO . BSLC.putStrLn $ encode x